caseyd Posted January 13, 2009 Share Posted January 13, 2009 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 Quote Link to comment Share on other sites More sharing options...
pyrochild Posted January 13, 2009 Share Posted January 13, 2009 protected unsafe override Document OnLoad(Stream input) { //create our surface Surface surface = new Surface(width, height); //grab a pointer to the image's memory ColorBgra* ptr = surface.GetRowAddress(0); int b; //loop through the stream. (+perf by making a buffer and reading a few bytes at a time?) for (int i = 0; i { //read b = input.ReadByte(); //set the pixel's a to opaque, and r,g,and b to the read value ptr->Bgra = (uint)((255 ; //move to the next pixel in memory. ptr++; } //return return Document.FromImage(surface.CreateAliasedBitmap()); } A lot of room for improvement, performance-wise, but it does the trick. I think. Worked with the images I tested, anyway. Quote ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
caseyd Posted January 13, 2009 Author Share Posted January 13, 2009 Thanks, that worked great. Is there any documentation for the Paint.net libraries? I've been searching this forum, and the web, but can't seem to find anything, only references to a Paint.net sdk. Quote Link to comment Share on other sites More sharing options...
pyrochild Posted January 13, 2009 Share Posted January 13, 2009 Not really, but there are several plugins with the source code available that you can use as examples or templates. There are also templates that don't really work Quote ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
harold Posted January 13, 2009 Share Posted January 13, 2009 The error was that ScanWidth was not the same as Width, so pixels were copied to placeholder bytes. Right? You should probably be able to block-copy it row by row.. Quote I would write plugins, if I knew what kind of plugins were needed.. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.