Hi,
I am trying to work with some heightmaps in Paint.net, and am looking to write a plugin that will do the following:
Load and save an 8bpp greyscale image. No header information, just the pixel data in a RGB format. I tried using the RawLoader plugin, and mucked around with its settings but no dice. I am currently using Gimp for this, but would like to be able to use PDN for it all. I am new to C# as well, but here was my first stab at doing this:
int width = 257;
int height = 257;
byte[] data = new byte[width * height];
for (int index = 0; index < width * height; index++)
data [index] = (byte)input.ReadByte ();
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
//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
System.Runtime.InteropServices.Marshal.Copy(data, 0, bmpData.Scan0, data.Length);
//Unlock the pixels
bmp.UnlockBits(bmpData);
return Document.FromImage(bmp);
It loads the image, but it is all messed up. I am pretty sure it has to do with the PixelFormat. Is there an easier way to do this?
Thanks,
Casey