From 0a3fe37bb0b194fd7c3aaa3543ca0af0bf0601de Mon Sep 17 00:00:00 2001 From: morkt Date: Mon, 20 Apr 2015 14:04:46 +0400 Subject: [PATCH] (ImageData.Create): new convenient static method. --- GameRes/Image.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/GameRes/Image.cs b/GameRes/Image.cs index a469706b..11a0980e 100644 --- a/GameRes/Image.cs +++ b/GameRes/Image.cs @@ -24,6 +24,7 @@ // using System.IO; +using System.Windows.Media; using System.Windows.Media.Imaging; namespace GameRes @@ -66,6 +67,16 @@ namespace GameRes OffsetX = x; OffsetY = y; } + + public static ImageData Create (ImageMetaData info, PixelFormat format, BitmapPalette palette, + byte[] pixel_data) + { + int stride = (int)info.Width*((format.BitsPerPixel+7)/8); + var bitmap = BitmapSource.Create ((int)info.Width, (int)info.Height, 96, 96, + format, palette, pixel_data, stride); + bitmap.Freeze(); + return new ImageData (bitmap, info); + } } public abstract class ImageFormat : IResource