No it wasn't. I knew that article, but I didn't get that code working. Also the ImageConverter which is mentioned in the articles message board didn't work for me. My code, as nasty as it is by now looks like this:using System.Runtime.InteropServices; using System.Drawing; ... public void saveImage(String filename) { List byteList = new List(); lock (this) { foreach (int color in m_data) { byteList.AddRange(System.BitConverter.GetBytes(color)); } } byte[] byteData = byteList.ToArray(); GCHandle handle = GCHandle.Alloc(byteData); ; try { IntPtr imgDataPtr = Marshal.UnsafeAddrOfPinnedArrayElement(byteData, 0); if(imgDataPtr != IntPtr.Zero) { Bitmap img = new Bitmap(this.Height, this.Width, byteData.Length, PixelFormat.Format32bppArgb, imgDataPtr); Random rnd = new Random(); img.Save(filename, System.Drawing.Imaging.ImageFormat.Tiff); } else { System.Diagnostics.Debugger.Break(); } } catch(Exception e) { System.Diagnostics.Debugger.Break(); } finally { handle.Free(); } }
The creation of the Bitmap always threw ArgumentExceptions, when the PixelFormat is anything else than Format32bppArgb. It took me quite a time to figure out, that PixelFormat was the parameter which caused the problem, since I don't see any obvious differences between Format32bppArgb and Canonical which are both 32 Bits / pixel and should at maximum cause some mixed up channels when stated wrong. So maybe I'd get the Bitmap creation running with one of the linked examples above, if I check again for the correct PixelFormat, but by now I think I better use that maybe unnecessarily complicated version you helped me to figure out. If I get a shorter and less complicated version running, I'll post it here. Norbert