I want to create a bitmap from a byte array of pixel in metro Apps. Earlier below function was used for the same:
//Here create the Bitmap to the know height, width and format
Bitmap bmp = new Bitmap( 352, 288, PixelFormat.Format24bppRgb);
//Create a BitmapData and Lock all pixels to be written
BitmapData bmpData = bmp.LockBits(
new Rectangle(0, 0, bmp.Width, bmp.Height),
ImageLockMode.WriteOnly, bmp.PixelFormat);
//Copy the data from the byte array into BitmapData.Scan0
Marshal.Copy(data, 0, bmpData.Scan0, data.Length);
//Unlock the pixels
bmp.UnlockBits(bmpData);
//Return the bitmap
return bmp;
but BitmapData class is not present in windows 8 now. Please suggest any alternate way for the same.
thanks,
Pankaj
If I am not entirely mistaken, part of the code above is taken from the Evil DICOM library, from the
ImageHelper.GetBitmapmethod.I have myself made an attempt to port this code to Metro (or whatever Microsoft is going to call it eventually), and here is what the Metro analogue of
ImageHelper.GetBitmaplooks like in my port:(Actually, I am using
stream.WriteAsyncin my own code, requiring the method to be declared asasync. However, this is irrelevant for the above question as such.)This answer is similar to Diogo’s, but if you are not already “there” hopefully this answer can lead you more directly to your goal.
UPDATE
I have now published my Evil Dicom port to Metro on Github. You can find the repository here, and here is also a display from a very simple Metro application where I have used this Evil Dicom Metro port: