// Copyright (c) 2010-2014 SharpDX - Alexandre Mutel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.IO;
using SharpDX.DXGI;
using SharpDX.Mathematics.Interop;
namespace SharpDX.Direct2D1
{
public partial class Bitmap
{
///
/// Creates a Direct2D bitmap from a pointer to in-memory source data.
///
/// an instance of
/// The dimension of the bitmap to create in pixels.
/// dd371800
/// HRESULT ID2D1RenderTarget::CreateBitmap([In] D2D_SIZE_U size,[In, Optional] const void* srcData,[In] unsigned int pitch,[In] const D2D1_BITMAP_PROPERTIES* bitmapProperties,[Out, Fast] ID2D1Bitmap** bitmap)
/// ID2D1RenderTarget::CreateBitmap
public Bitmap(RenderTarget renderTarget, Size2 size)
: this(renderTarget, size, DataPointer.Zero, 0, new BitmapProperties(new PixelFormat(Format.Unknown, AlphaMode.Unknown)))
{
}
///
/// Creates a Direct2D bitmap from a pointer to in-memory source data.
///
/// an instance of
/// The dimension of the bitmap to create in pixels.
/// The pixel format and dots per inch (DPI) of the bitmap to create.
/// dd371800
/// HRESULT ID2D1RenderTarget::CreateBitmap([In] D2D_SIZE_U size,[In, Optional] const void* srcData,[In] unsigned int pitch,[In] const D2D1_BITMAP_PROPERTIES* bitmapProperties,[Out, Fast] ID2D1Bitmap** bitmap)
/// ID2D1RenderTarget::CreateBitmap
public Bitmap(RenderTarget renderTarget, Size2 size, SharpDX.Direct2D1.BitmapProperties bitmapProperties)
: this(renderTarget, size, DataPointer.Zero, 0, bitmapProperties)
{
}
///
/// Creates a Direct2D bitmap from a pointer to in-memory source data.
///
/// an instance of
/// The dimension of the bitmap to create in pixels.
/// A pointer to the memory location of the image data, or NULL to create an uninitialized bitmap.
/// The byte count of each scanline, which is equal to (the image width in pixels * the number of bytes per pixel) + memory padding. If srcData is NULL, this value is ignored. (Note that pitch is also sometimes called stride.)
/// dd371800
/// HRESULT ID2D1RenderTarget::CreateBitmap([In] D2D_SIZE_U size,[In, Optional] const void* srcData,[In] unsigned int pitch,[In] const D2D1_BITMAP_PROPERTIES* bitmapProperties,[Out, Fast] ID2D1Bitmap** bitmap)
/// ID2D1RenderTarget::CreateBitmap
public Bitmap(RenderTarget renderTarget, Size2 size, DataPointer dataPointer, int pitch)
: this(renderTarget, size, dataPointer, pitch, new BitmapProperties(new PixelFormat(Format.Unknown, AlphaMode.Unknown)))
{
}
///
/// Creates a Direct2D bitmap from a pointer to in-memory source data.
///
/// an instance of
/// The dimension of the bitmap to create in pixels.
/// A pointer to the memory location of the image data, or NULL to create an uninitialized bitmap.
/// The byte count of each scanline, which is equal to (the image width in pixels * the number of bytes per pixel) + memory padding. If srcData is NULL, this value is ignored. (Note that pitch is also sometimes called stride.)
/// The pixel format and dots per inch (DPI) of the bitmap to create.
/// dd371800
/// HRESULT ID2D1RenderTarget::CreateBitmap([In] D2D_SIZE_U size,[In, Optional] const void* srcData,[In] unsigned int pitch,[In] const D2D1_BITMAP_PROPERTIES* bitmapProperties,[Out, Fast] ID2D1Bitmap** bitmap)
/// ID2D1RenderTarget::CreateBitmap
public Bitmap(RenderTarget renderTarget, Size2 size, DataPointer dataPointer, int pitch, SharpDX.Direct2D1.BitmapProperties bitmapProperties)
: base(IntPtr.Zero)
{
renderTarget.CreateBitmap(size, dataPointer == DataPointer.Zero ? IntPtr.Zero : dataPointer.Pointer, pitch, bitmapProperties, this);
}
///
/// Creates an whose data is shared with another resource.
///
/// an instance of
/// An that contains the data to share with the new ID2D1Bitmap. For more information, see the Remarks section.
/// dd371865
/// HRESULT ID2D1RenderTarget::CreateSharedBitmap([In] const GUID& riid,[In] void* data,[In, Optional] const D2D1_BITMAP_PROPERTIES* bitmapProperties,[Out, Fast] ID2D1Bitmap** bitmap)
/// ID2D1RenderTarget::CreateSharedBitmap
public Bitmap(RenderTarget renderTarget, Bitmap bitmap)
: this(renderTarget, bitmap, null)
{
}
///
/// Creates an whose data is shared with another resource.
///
/// an instance of
/// An that contains the data to share with the new ID2D1Bitmap. For more information, see the Remarks section.
/// The pixel format and DPI of the bitmap to create . The portion of the pixel format must match the of data or the method will fail, but the alpha modes don't have to match. To prevent a mismatch, you can pass NULL or the value obtained from the {{D2D1::PixelFormat}} helper function. The DPI settings do not have to match those of data. If both dpiX and dpiY are 0.0f, the default DPI, 96, is used.
/// dd371865
/// HRESULT ID2D1RenderTarget::CreateSharedBitmap([In] const GUID& riid,[In] void* data,[In, Optional] const D2D1_BITMAP_PROPERTIES* bitmapProperties,[Out, Fast] ID2D1Bitmap** bitmap)
/// ID2D1RenderTarget::CreateSharedBitmap
public Bitmap(RenderTarget renderTarget, Bitmap bitmap, SharpDX.Direct2D1.BitmapProperties? bitmapProperties)
: base(IntPtr.Zero)
{
renderTarget.CreateSharedBitmap(Utilities.GetGuidFromType(typeof(Bitmap)), bitmap.NativePointer, bitmapProperties, this);
}
///
/// Creates an whose data is shared with another resource.
///
/// an instance of
/// An that contains the data to share with the new ID2D1Bitmap. For more information, see the Remarks section.
/// dd371865
/// HRESULT ID2D1RenderTarget::CreateSharedBitmap([In] const GUID& riid,[In] void* data,[In, Optional] const D2D1_BITMAP_PROPERTIES* bitmapProperties,[Out, Fast] ID2D1Bitmap** bitmap)
/// ID2D1RenderTarget::CreateSharedBitmap
public Bitmap(RenderTarget renderTarget, Surface surface)
: this(renderTarget, surface, null)
{
}
///
/// Creates an whose data is shared with another resource.
///
/// an instance of
/// An that contains the data to share with the new ID2D1Bitmap. For more information, see the Remarks section.
/// The pixel format and DPI of the bitmap to create . The portion of the pixel format must match the of data or the method will fail, but the alpha modes don't have to match. To prevent a mismatch, you can pass NULL or the value obtained from the {{D2D1::PixelFormat}} helper function. The DPI settings do not have to match those of data. If both dpiX and dpiY are 0.0f, the default DPI, 96, is used.
/// dd371865
/// HRESULT ID2D1RenderTarget::CreateSharedBitmap([In] const GUID& riid,[In] void* data,[In, Optional] const D2D1_BITMAP_PROPERTIES* bitmapProperties,[Out, Fast] ID2D1Bitmap** bitmap)
/// ID2D1RenderTarget::CreateSharedBitmap
public Bitmap(RenderTarget renderTarget, Surface surface, SharpDX.Direct2D1.BitmapProperties? bitmapProperties)
: base(IntPtr.Zero)
{
renderTarget.CreateSharedBitmap(Utilities.GetGuidFromType(typeof(Surface)), surface.NativePointer, bitmapProperties, this);
}
///
/// Creates an that points to the bitmap data already stored in the .
///
/// An instance of .
/// An that contains the data to share with the new .
/// dd371865
/// HRESULT ID2D1RenderTarget::CreateSharedBitmap([In] const GUID& riid,[In] void* data,[In, Optional] const D2D1_BITMAP_PROPERTIES* bitmapProperties,[Out, Fast] ID2D1Bitmap** bitmap)
/// ID2D1RenderTarget::CreateSharedBitmap
public Bitmap(RenderTarget renderTarget, WIC.BitmapLock bitmapLock)
: this(renderTarget, bitmapLock, null)
{
}
///
/// Creates an that points to the bitmap data already stored in the .
///
/// An instance of .
/// An that contains the data to share with the new .
/// The pixel format and DPI of the bitmap to create . The portion of the pixel format must match the of data or the method will fail, but the alpha modes don't have to match. To prevent a mismatch, you can pass NULL or the value obtained from the {{D2D1::PixelFormat}} helper function. The DPI settings do not have to match those of data. If both dpiX and dpiY are 0.0f, the default DPI, 96, is used.
/// dd371865
/// HRESULT ID2D1RenderTarget::CreateSharedBitmap([In] const GUID& riid,[In] void* data,[In, Optional] const D2D1_BITMAP_PROPERTIES* bitmapProperties,[Out, Fast] ID2D1Bitmap** bitmap)
/// ID2D1RenderTarget::CreateSharedBitmap
public Bitmap(RenderTarget renderTarget, WIC.BitmapLock bitmapLock, BitmapProperties? bitmapProperties)
: base(IntPtr.Zero)
{
renderTarget.CreateSharedBitmap(Utilities.GetGuidFromType(typeof(WIC.BitmapLock)), bitmapLock.NativePointer, bitmapProperties, this);
}
///
/// Creates a Direct2D bitmap from a pointer to in-memory source data.
///
/// an instance of
/// The dimension of the bitmap to create in pixels.
/// A pointer to an array of pixel data. The size of the array must be equal to sizeof(pixel) * Size.Width * Height.
/// The pixel format and dots per inch (DPI) of the bitmap to create.
/// dd371800
/// HRESULT ID2D1RenderTarget::CreateBitmap([In] D2D_SIZE_U size,[In, Optional] const void* srcData,[In] unsigned int pitch,[In] const D2D1_BITMAP_PROPERTIES* bitmapProperties,[Out, Fast] ID2D1Bitmap** bitmap)
/// ID2D1RenderTarget::CreateBitmap
public unsafe static Bitmap New(RenderTarget renderTarget, Size2 size, T[] pixelDatas, SharpDX.Direct2D1.BitmapProperties bitmapProperties) where T : struct
{
var sizeOfBitmap = pixelDatas.Length*Utilities.SizeOf();
var expectedSize = size.Width*size.Height* FormatHelper.SizeOfInBytes(bitmapProperties.PixelFormat.Format);
if (sizeOfBitmap != expectedSize)
throw new ArgumentException("Invalid size of pixelDatas. Must be equal to sizeof(T) == sizeof(PixelFormat.Format) and Width * Height elements");
return new Bitmap(renderTarget, size, new DataPointer((IntPtr)Interop.Fixed(pixelDatas), sizeOfBitmap), size.Width * FormatHelper.SizeOfInBytes(bitmapProperties.PixelFormat.Format), bitmapProperties);
}
///
/// Creates a Bitmap from a WIC bitmap.
///
/// The render target.
/// A reference to a WIC bitmap.
///
/// dd371797
/// HRESULT ID2D1RenderTarget::CreateBitmapFromWicBitmap([In] IWICBitmapSource* wicBitmapSource,[In, Optional] const D2D1_BITMAP_PROPERTIES* bitmapProperties,[Out] ID2D1Bitmap** bitmap)
/// ID2D1RenderTarget::CreateBitmapFromWicBitmap
public static Bitmap FromWicBitmap(RenderTarget renderTarget, WIC.BitmapSource wicBitmapSource)
{
Bitmap bitmap;
renderTarget.CreateBitmapFromWicBitmap(wicBitmapSource, null, out bitmap);
return bitmap;
}
///
/// Creates a Bitmap from a WIC bitmap.
///
/// The render target.
/// The WIC bitmap.
/// The bitmap properties.
///
/// dd371797
/// HRESULT ID2D1RenderTarget::CreateBitmapFromWicBitmap([In] IWICBitmapSource* wicBitmapSource,[In, Optional] const D2D1_BITMAP_PROPERTIES* bitmapProperties,[Out] ID2D1Bitmap** bitmap)
/// ID2D1RenderTarget::CreateBitmapFromWicBitmap
public static Bitmap FromWicBitmap(RenderTarget renderTarget, WIC.BitmapSource wicBitmap, SharpDX.Direct2D1.BitmapProperties bitmapProperties)
{
Bitmap bitmap;
renderTarget.CreateBitmapFromWicBitmap(wicBitmap, bitmapProperties, out bitmap);
return bitmap;
}
///
/// Copies the specified region from the specified bitmap into the current bitmap.
///
///
/// This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion, and will fail if the bitmap formats do not match. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.
///
/// The bitmap to copy from.
/// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
/// dd371152
/// HRESULT ID2D1Bitmap::CopyFromBitmap([In, Optional] const D2D_POINT_2U* destPoint,[In] ID2D1Bitmap* bitmap,[In, Optional] const D2D_RECT_U* srcRect)
/// ID2D1Bitmap::CopyFromBitmap
public void CopyFromBitmap(Bitmap sourceBitmap)
{
CopyFromBitmap(null, sourceBitmap, null);
}
///
/// Copies the specified region from the specified bitmap into the current bitmap.
///
///
/// This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion, and will fail if the bitmap formats do not match. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.
///
/// The bitmap to copy from.
/// In the current bitmap, the upper-left corner of the area to which the region specified by srcRect is copied.
/// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
/// dd371152
/// HRESULT ID2D1Bitmap::CopyFromBitmap([In, Optional] const D2D_POINT_2U* destPoint,[In] ID2D1Bitmap* bitmap,[In, Optional] const D2D_RECT_U* srcRect)
/// ID2D1Bitmap::CopyFromBitmap
public void CopyFromBitmap(Bitmap sourceBitmap, RawPoint destinationPoint)
{
CopyFromBitmap(destinationPoint, sourceBitmap, null);
}
///
/// Copies the specified region from the specified bitmap into the current bitmap.
///
///
/// This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion, and will fail if the bitmap formats do not match. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.
///
/// The bitmap to copy from.
/// The area of bitmap to copy.
/// In the current bitmap, the upper-left corner of the area to which the region specified by srcRect is copied.
/// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
/// dd371152
/// HRESULT ID2D1Bitmap::CopyFromBitmap([In, Optional] const D2D_POINT_2U* destPoint,[In] ID2D1Bitmap* bitmap,[In, Optional] const D2D_RECT_U* srcRect)
/// ID2D1Bitmap::CopyFromBitmap
public void CopyFromBitmap(Bitmap sourceBitmap, RawPoint destinationPoint, RawRectangle sourceArea)
{
CopyFromBitmap(destinationPoint, sourceBitmap, sourceArea);
}
///
/// Copies the specified region from memory into the current bitmap.
///
///
/// This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion; the two bitmap formats should match. Passing this method invalid input, such as an invalid destination rectangle, can produce unpredictable results, such as a distorted image or device failure. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.
///
/// The data to copy.
/// The stride, or pitch, of the source bitmap stored in srcData. The stride is the byte count of a scanline (one row of pixels in memory). The stride can be computed from the following formula: pixel width * bytes per pixel + memory padding.
/// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
/// dd371155
/// HRESULT ID2D1Bitmap::CopyFromMemory([In, Optional] const D2D_RECT_U* dstRect,[In] const void* srcData,[In] unsigned int pitch)
/// ID2D1Bitmap::CopyFromMemory
public void CopyFromMemory(IntPtr pointer, int pitch)
{
CopyFromMemory(null, pointer, pitch);
}
///
/// Copies the specified region from memory into the current bitmap.
///
///
/// This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion; the two bitmap formats should match. Passing this method invalid input, such as an invalid destination rectangle, can produce unpredictable results, such as a distorted image or device failure. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.
///
/// The data to copy.
/// The stride, or pitch, of the source bitmap stored in srcData. The stride is the byte count of a scanline (one row of pixels in memory). The stride can be computed from the following formula: pixel width * bytes per pixel + memory padding.
/// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
/// dd371155
/// HRESULT ID2D1Bitmap::CopyFromMemory([In, Optional] const D2D_RECT_U* dstRect,[In] const void* srcData,[In] unsigned int pitch)
/// ID2D1Bitmap::CopyFromMemory
public void CopyFromMemory(byte[] memory, int pitch)
{
unsafe
{
fixed (void* pMemory = &memory[0]) CopyFromMemory(null, new IntPtr(pMemory), pitch);
}
}
///
/// Copies the specified region from memory into the current bitmap.
///
///
/// This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion; the two bitmap formats should match. Passing this method invalid input, such as an invalid destination rectangle, can produce unpredictable results, such as a distorted image or device failure. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.
///
/// The data to copy.
/// The stride, or pitch, of the source bitmap stored in srcData. The stride is the byte count of a scanline (one row of pixels in memory). The stride can be computed from the following formula: pixel width * bytes per pixel + memory padding.
/// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
/// dd371155
/// HRESULT ID2D1Bitmap::CopyFromMemory([In, Optional] const D2D_RECT_U* dstRect,[In] const void* srcData,[In] unsigned int pitch)
/// ID2D1Bitmap::CopyFromMemory
public void CopyFromMemory(T[] memory, int pitch = 0) where T : struct
{
unsafe
{
if (pitch == 0)
pitch = (int)(Size.Width * Utilities.SizeOf() / this.DotsPerInch.Width);
CopyFromMemory(null, (IntPtr)Interop.Fixed(memory), pitch);
}
}
///
/// Copies the specified region from memory into the current bitmap.
///
///
/// This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion; the two bitmap formats should match. Passing this method invalid input, such as an invalid destination rectangle, can produce unpredictable results, such as a distorted image or device failure. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.
///
/// The data to copy.
/// The stride, or pitch, of the source bitmap stored in srcData. The stride is the byte count of a scanline (one row of pixels in memory). The stride can be computed from the following formula: pixel width * bytes per pixel + memory padding.
/// In the current bitmap, the upper-left corner of the area to which the region specified by srcRect is copied.
/// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
/// dd371155
/// HRESULT ID2D1Bitmap::CopyFromMemory([In, Optional] const D2D_RECT_U* dstRect,[In] const void* srcData,[In] unsigned int pitch)
/// ID2D1Bitmap::CopyFromMemory
public void CopyFromMemory(IntPtr pointer, int pitch, RawRectangle destinationArea)
{
CopyFromMemory(destinationArea, pointer, pitch);
}
///
/// Copies the specified region from memory into the current bitmap.
///
///
/// This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion; the two bitmap formats should match. Passing this method invalid input, such as an invalid destination rectangle, can produce unpredictable results, such as a distorted image or device failure. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.
///
/// The data to copy.
/// The stride, or pitch, of the source bitmap stored in srcData. The stride is the byte count of a scanline (one row of pixels in memory). The stride can be computed from the following formula: pixel width * bytes per pixel + memory padding.
/// In the current bitmap, the upper-left corner of the area to which the region specified by srcRect is copied.
/// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
/// dd371155
/// HRESULT ID2D1Bitmap::CopyFromMemory([In, Optional] const D2D_RECT_U* dstRect,[In] const void* srcData,[In] unsigned int pitch)
/// ID2D1Bitmap::CopyFromMemory
public void CopyFromMemory(byte[] memory, int pitch, RawRectangle destinationArea)
{
unsafe
{
fixed (void* pMemory = &memory[0]) CopyFromMemory(destinationArea, new IntPtr(pMemory), pitch);
}
}
///
/// Copies the specified region from memory into the current bitmap.
///
///
/// This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion; the two bitmap formats should match. Passing this method invalid input, such as an invalid destination rectangle, can produce unpredictable results, such as a distorted image or device failure. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.
///
/// The data to copy.
/// The stride, or pitch, of the source bitmap stored in srcData. The stride is the byte count of a scanline (one row of pixels in memory). The stride can be computed from the following formula: pixel width * bytes per pixel + memory padding.
/// In the current bitmap, the upper-left corner of the area to which the region specified by srcRect is copied.
/// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
/// dd371155
/// HRESULT ID2D1Bitmap::CopyFromMemory([In, Optional] const D2D_RECT_U* dstRect,[In] const void* srcData,[In] unsigned int pitch)
/// ID2D1Bitmap::CopyFromMemory
public void CopyFromMemory(T[] memory, int pitch, RawRectangle destinationArea) where T : struct
{
unsafe
{
CopyFromMemory(destinationArea, (IntPtr)Interop.Fixed(memory), pitch);
}
}
///
/// Copies the specified region from the specified render target into the current bitmap.
///
///
/// This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion, and will fail if the bitmap formats do not match. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}. All clips and layers must be popped off of the render target before calling this method. The method returns {{D2DERR_RENDER_TARGET_HAS_LAYER_OR_CLIPRECT}} if any clips or layers are currently applied to the render target.
///
/// The render target that contains the region to copy.
/// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
/// dd371158
/// HRESULT ID2D1Bitmap::CopyFromRenderTarget([In, Optional] const D2D_POINT_2U* destPoint,[In] ID2D1RenderTarget* renderTarget,[In, Optional] const D2D_RECT_U* srcRect)
/// ID2D1Bitmap::CopyFromRenderTarget
public void CopyFromRenderTarget(RenderTarget renderTarget)
{
CopyFromRenderTarget(null, renderTarget, null);
}
///
/// Copies the specified region from the specified render target into the current bitmap.
///
///
/// This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion, and will fail if the bitmap formats do not match. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}. All clips and layers must be popped off of the render target before calling this method. The method returns {{D2DERR_RENDER_TARGET_HAS_LAYER_OR_CLIPRECT}} if any clips or layers are currently applied to the render target.
///
/// The render target that contains the region to copy.
/// In the current bitmap, the upper-left corner of the area to which the region specified by srcRect is copied.
/// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
/// dd371158
/// HRESULT ID2D1Bitmap::CopyFromRenderTarget([In, Optional] const D2D_POINT_2U* destPoint,[In] ID2D1RenderTarget* renderTarget,[In, Optional] const D2D_RECT_U* srcRect)
/// ID2D1Bitmap::CopyFromRenderTarget
public void CopyFromRenderTarget(RenderTarget renderTarget, RawPoint destinationPoint)
{
CopyFromRenderTarget(destinationPoint, renderTarget, null);
}
///
/// Copies the specified region from the specified render target into the current bitmap.
///
///
/// This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion, and will fail if the bitmap formats do not match. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}. All clips and layers must be popped off of the render target before calling this method. The method returns {{D2DERR_RENDER_TARGET_HAS_LAYER_OR_CLIPRECT}} if any clips or layers are currently applied to the render target.
///
/// The render target that contains the region to copy.
/// In the current bitmap, the upper-left corner of the area to which the region specified by srcRect is copied.
/// The area of renderTarget to copy.
/// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
/// dd371158
/// HRESULT ID2D1Bitmap::CopyFromRenderTarget([In, Optional] const D2D_POINT_2U* destPoint,[In] ID2D1RenderTarget* renderTarget,[In, Optional] const D2D_RECT_U* srcRect)
/// ID2D1Bitmap::CopyFromRenderTarget
public void CopyFromRenderTarget(RenderTarget renderTarget, RawPoint destinationPoint, RawRectangle sourceArea)
{
CopyFromRenderTarget(destinationPoint, renderTarget, sourceArea);
}
///
/// Copies the specified region from a stream into the current bitmap.
///
///
/// This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion; the two bitmap formats should match. Passing this method invalid input, such as an invalid destination rectangle, can produce unpredictable results, such as a distorted image or device failure. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.
///
/// The stream to copy the data from.
/// Length in bytes of the data to copy from the stream.
/// The stride, or pitch, of the source bitmap stored in srcData. The stride is the byte count of a scanline (one row of pixels in memory). The stride can be computed from the following formula: pixel width * bytes per pixel + memory padding.
/// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
/// dd371155
/// HRESULT ID2D1Bitmap::CopyFromMemory([In, Optional] const D2D_RECT_U* dstRect,[In] const void* srcData,[In] unsigned int pitch)
/// ID2D1Bitmap::CopyFromMemory
public void CopyFromStream(Stream stream, int pitch, int length)
{
CopyFromMemory(Utilities.ReadStream(stream, ref length), pitch);
}
///
/// Copies the specified region from a stream into the current bitmap.
///
///
/// This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion; the two bitmap formats should match. Passing this method invalid input, such as an invalid destination rectangle, can produce unpredictable results, such as a distorted image or device failure. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.
///
/// The stream to copy the data from.
/// Length in bytes of the data to copy from the stream.
/// The stride, or pitch, of the source bitmap stored in srcData. The stride is the byte count of a scanline (one row of pixels in memory). The stride can be computed from the following formula: pixel width * bytes per pixel + memory padding.
/// In the current bitmap, the upper-left corner of the area to which the region specified by srcRect is copied.
/// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
/// dd371155
/// HRESULT ID2D1Bitmap::CopyFromMemory([In, Optional] const D2D_RECT_U* dstRect,[In] const void* srcData,[In] unsigned int pitch)
/// ID2D1Bitmap::CopyFromMemory
public void CopyFromStream(Stream stream, int pitch, int length, RawRectangle destinationArea)
{
CopyFromMemory(Utilities.ReadStream(stream, ref length), pitch, destinationArea);
}
///
/// Return the dots per inch (DPI) of the bitmap.
///
/// The dots per inch (DPI) of the bitmap.
public Size2F DotsPerInch
{
get
{
float y;
float x;
GetDpi(out x, out y);
return new Size2F(x, y);
}
}
}
}