![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hello, I have a short array short[] RawData; filled with medical image data. Each pixel is represented by a short value, which must be windowed by special settings. As I cannot use PixelFormat.Format16bppGrayScale in GDI+, I tried to use the PixelFormat.Format16bppRgb555, because I really need to draw into this image and it would be an advantage to use the Graphics class functions to draw into it. The question now is that I want to keep the image data in my rawdata array and I don't want to copy the data into the bitmap. I really want to have let's say just a reference and all drawings I perform in the Graphics canvas should be reflected to the rawdata as well. Is there a way to do this? I tried following but I don't know if this will work at all: public Bitmap AsBitmap { get { MemoryStream m = new MemoryStream(); Bitmap BMP = new Bitmap(512, 512, PixelFormat.Format16bppRgb555); BitmapData Data = BMP.LockBits(new Rectangle(0, 0, 512, 512), ImageLockMode.ReadWrite, PixelFormat.Format16bppRgb555); unsafe { fixed (short* p = &RawData[0]) { short* ptr = p; try { ptr = (short*)Data.Scan0.ToPointer(); } catch (Exception E) { MessageBox.Show(E.Message); } } } BMP.UnlockBits(Data); Graphics g = Graphics.FromImage(BMP); g.DrawLine(new Pen(Color.White), 0, 0, 100, 100); return BMP; } } Thanks for your help Martin |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |