I have been searching ALL weekend for a solution. I have some GDI+ code for a video game that I need to get working in WPF. After searching through countless articles I've basically decided that it's not possible. I've posted on several other forums including MSDN forum and no one seems to know how to do it.
I know that WPF is said to be so powerfull and everything so it MUST be able to work with a simple bitmap image.
Is there a way to convert my function below to WPF, and get the exact same results? I've tried everything, including DrawingVisual but I can't get anything to even compile:
The only solution I can find it to convert back and forth between GDI+ bitmaps and WPF bitmaps, which is very messy, and way too slow for a video game.
Graphics gfx = new Graphics();
int sx = (selectedPaletteTile % PALETTE_COLUMNS) * 33;
int sy = (selectedPaletteTile / PALETTE_COLUMNS) * 33;
Rectangle src = new Rectangle(sx, sy, 32, 32); // Source
Rectangle dst = new Rectangle(0, 0, 32, 32); // Destination
gfx.DrawImage(imgPalette.Source, dst, src, draw.GraphicsUnit.Pixel);
private ImageSource ToBitmapSource(draw.Bitmap p_bitmap)
IntPtr hBitmap = p_bitmap.GetHbitmap();
wpfBitmap = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
Does anyone know a better solution?? How can I modify my original function to work under WPF and still get the exact same results?
fixed (byte* pBits = bits)
IntPtr ptr = new IntPtr(pBits);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(width,height,stride, System.Drawing.Imaging.PixelFormat.Format32bppPArgb,ptr);
The problem is the Graphics.DrawImage or Graphics.FromImage ... I can't get those to port over to WPF at all!
I work with Bitmap in GDI+ and have to convert that to BitmapImage to get it to work in WPF, only to find out that WPF can't work with Bitmaps (according to most of the articles I've read this weekend).