예제 #1
0
        public static byte[] LoadImage(string fileName, bool premultiplied, out int width, out int height)
        {
            WIC.ImagingFactory factory = new WIC.ImagingFactory();

            SharpDX.IO.NativeFileStream stream  = new SharpDX.IO.NativeFileStream(fileName, SharpDX.IO.NativeFileMode.Open, SharpDX.IO.NativeFileAccess.Read);
            WIC.BitmapDecoder           decoder = new WIC.BitmapDecoder(factory, stream, WIC.DecodeOptions.CacheOnDemand);
            WIC.BitmapFrameDecode       frame   = decoder.GetFrame(0);
            width  = frame.Size.Width;
            height = frame.Size.Height;
            byte[] data = new byte[width * height * 4];
            frame.CopyPixels(data, width * 4);
            return(data);
        }
예제 #2
0
        //-------------------------------------------------------------------------------------
        // Decodes a single frame
        //-------------------------------------------------------------------------------------
        private static Image DecodeSingleFrame(WICFlags flags, ImageDescription metadata, Guid convertGUID, WIC.BitmapFrameDecode frame)
        {
            var image = Image.New(metadata);

            var pixelBuffer = image.PixelBuffer[0];

            if (convertGUID == Guid.Empty)
            {
                frame.CopyPixels(pixelBuffer.RowStride, pixelBuffer.DataPointer, pixelBuffer.BufferStride);
            }
            else
            {
                using (var converter = new WIC.FormatConverter(Factory))
                {
                    converter.Initialize(frame, convertGUID, GetWICDither(flags), null, 0, WIC.BitmapPaletteType.Custom);
                    converter.CopyPixels(pixelBuffer.RowStride, pixelBuffer.DataPointer, pixelBuffer.BufferStride);
                }
            }

            return(image);
        }
예제 #3
0
파일: WICHelper.cs 프로젝트: numo16/SharpDX
        //-------------------------------------------------------------------------------------
        // Decodes a single frame
        //-------------------------------------------------------------------------------------
        private static Image DecodeSingleFrame(WICFlags flags, ImageDescription metadata, Guid convertGUID, BitmapFrameDecode frame)
        {
            var image = Image.New(metadata);

            var pixelBuffer = image.PixelBuffer[0];

            if (convertGUID == Guid.Empty)
            {
                frame.CopyPixels(pixelBuffer.RowStride, pixelBuffer.DataPointer, pixelBuffer.BufferStride);
            }
            else
            {
                using (var converter = new FormatConverter(Factory))
                {
                    converter.Initialize(frame, convertGUID, GetWICDither(flags), null, 0, BitmapPaletteType.Custom);
                    converter.CopyPixels(pixelBuffer.RowStride, pixelBuffer.DataPointer, pixelBuffer.BufferStride);
                }
            }

            return image;
        }
예제 #4
0
        private static Texture DecodeSingleframe(ImagingFactory imagingFactory, WicFlags flags, TextureDescription description, Guid convertGuid, BitmapFrameDecode frame)
        {
            var texture = new Texture(description);
              var image = texture.Images[0];

              if (convertGuid == Guid.Empty)
              {
            frame.CopyPixels(image.Data, image.RowPitch);
              }
              else
              {
            using (var converter = new FormatConverter(imagingFactory))
            {
              converter.Initialize(frame, convertGuid, GetWicDither(flags), null, 0, BitmapPaletteType.Custom);
              converter.CopyPixels(image.Data, image.RowPitch);
            }
              }

              return texture;
        }