Example #1
0
 public static void CopyPixels(this IWICBitmapSource bitmapSource, int cbStride, byte[] pbBuffer, WICRect?prc = null)
 {
     using (var prcPtr = CoTaskMemPtr.From(prc))
     {
         bitmapSource.CopyPixels(prcPtr, cbStride, pbBuffer.Length, pbBuffer);
     }
 }
Example #2
0
 public static IWICMetadataQueryWriter CreateQueryWriter(this IWICImagingFactory imagingFactory, Guid guidMetadataFormat, Guid?pguidVendor = null)
 {
     using (var pguidVendorPtr = CoTaskMemPtr.From(pguidVendor))
     {
         return(imagingFactory.CreateQueryWriter(guidMetadataFormat, pguidVendorPtr));
     }
 }
Example #3
0
 public static IWICMetadataQueryWriter CreateQueryWriterFromReader(this IWICImagingFactory imagingFactory, IWICMetadataQueryReader pIQueryReader, Guid?pguidVendor = null)
 {
     using (var pguidVendorPtr = CoTaskMemPtr.From(pguidVendor))
     {
         return(imagingFactory.CreateQueryWriterFromReader(pIQueryReader, pguidVendorPtr));
     }
 }
Example #4
0
 public static IWICBitmapDecoder CreateDecoderFromStream(this IWICImagingFactory imagingFactory, IStream stream, WICDecodeOptions metadataOptions, Guid?pguidVendor = null)
 {
     using (var pguidVendorPtr = CoTaskMemPtr.From(pguidVendor))
     {
         return(imagingFactory.CreateDecoderFromStream(stream, pguidVendorPtr, metadataOptions));
     }
 }
Example #5
0
 public static IWICBitmapEncoder CreateEncoder(this IWICImagingFactory factory, Guid guidContainerFormat, Guid?pguidVendor = null)
 {
     using (var pguidVendorPtr = CoTaskMemPtr.From(pguidVendor))
     {
         return(factory.CreateEncoder(guidContainerFormat, pguidVendorPtr));
     }
 }
Example #6
0
 public static IWICBitmapDecoder CreateDecoderFromFilename(this IWICImagingFactory imagingFactory, string wzFilename, Guid?pguidVendor = null, WICDecodeOptions metadataOptions = WICDecodeOptions.WICDecodeMetadataCacheOnDemand)
 {
     using (var pguidVendorPtr = CoTaskMemPtr.From(pguidVendor))
     {
         return(imagingFactory.CreateDecoderFromFilename(wzFilename, pguidVendorPtr, StreamAccessMode.GENERIC_READ, metadataOptions));
     }
 }
Example #7
0
 public static IWICBitmapDecoder CreateDecoderFromFileHandle(this IWICImagingFactory imagingFactory, IntPtr hFile, WICDecodeOptions metadataOptions, Guid?pguidVendor = null)
 {
     using (var pguidVendorPtr = CoTaskMemPtr.From(pguidVendor))
     {
         return(imagingFactory.CreateDecoderFromFileHandle(hFile, pguidVendorPtr, metadataOptions));
     }
 }
Example #8
0
 public static IWICBitmapLock Lock(this IWICBitmap bitmap, WICBitmapLockFlags flags, WICRect?prcLock = null)
 {
     using (var prcLockPtr = CoTaskMemPtr.From(prcLock))
     {
         return(bitmap.Lock(prcLockPtr, flags));
     }
 }
Example #9
0
 public static void WriteSource(this IWICBitmapFrameEncode bitmapFrameEncode, IWICBitmapSource pIBitmapSource, WICRect?prc = null)
 {
     using (var prcPtr = CoTaskMemPtr.From(prc))
     {
         bitmapFrameEncode.WriteSource(pIBitmapSource, prcPtr);
     }
 }
Example #10
0
        public static WICBitmapPattern[] GetPatterns(this IWICBitmapDecoderInfo bitmapDecoderInfo)
        {
            int count;
            int size;

            bitmapDecoderInfo.GetPatterns(0, IntPtr.Zero, out count, out size);
            if (count == 0)
            {
                return(new WICBitmapPattern[0]);
            }
            using (var buffer = new CoTaskMemPtr(Marshal.AllocCoTaskMem(size)))
            {
                bitmapDecoderInfo.GetPatterns(size, buffer, out count, out size);
                IntPtr at       = buffer;
                var    patterns = new WICBitmapPattern[count];
                for (int i = 0, stride = Marshal.SizeOf(typeof(WICBitmapPatternRaw)); i < count; ++i, at += stride)
                {
                    var raw    = (WICBitmapPatternRaw)Marshal.PtrToStructure(at, typeof(WICBitmapPatternRaw)) !;
                    int length = raw.Length;
                    patterns[i] = new WICBitmapPattern()
                    {
                        Length      = length,
                        Position    = raw.Position,
                        Pattern     = new byte[length],
                        Mask        = new byte[length],
                        EndOfStream = raw.EndOfStream
                    };
                    Marshal.Copy(raw.Pattern, patterns[i].Pattern !, 0, length);
                    Marshal.Copy(raw.Mask, patterns[i].Mask !, 0, length);
                }
                return(patterns);
            }
        }