{Resolved} - Bitmap pixel colour detection
right i need to import a bitmap that could contain x amount of colours into a picture box
then divide the bitmap into a grid (made from multiples of 15 x 15 grids)
analyse the colours in each square n deduce what the average colour content is
assign a windows colour for that area of the grid
and the build another graphic from the extracted bitmap data
any ideas peops ?
this ones puddlin me
Re: Bitmap pixel colour detection
Re: Bitmap pixel colour detection
Sounds like you are resampling an image to make it smaller or pixellate it, is that right?
Fastest way is to lock the bitmap into memory using Bitmap.LockBits(). Then you copy the data into an array and scan it with a loop.
This way is much harder to implement (if you are not used to this kind of thing) so you might find using Bitmap.GetPixel() easier until you get into the swing of things.
Good luck getting a detailed answer in the next 72 hours :D
Re: Bitmap pixel colour detection
im writing a mosaic design program ... need to split the bitmap into its various colours ... have been looking a GetPixel() too ... will check the above out ... many thanks illskills
if any one else knows of any useful imaging scripts/classes/functions etc would be most helpful
thanks once again ! ;)
1 Attachment(s)
Re: Bitmap pixel colour detection
I did a pixelate example on pscode.com
http://www.pscode.com/vb/scripts/Sho...4029&lngWId=10
The way I did it was to lock the bitmap with lockbits, then get at the data with marshal.readbyte, and set it again with marshal.writebyte. Since then, I've found that it is faster to define an array to hold the colors and use marshal.copy to move all the data into the array.
Attached is the pixelate example modified that way (vb2005, I've not got 2003 to hand). If you have 2003 then open the form1.vb and then copy and paste the code into a new project (you'll need to set up the form controls manually, and clean up any 2005 specific stuff).
To get it faster (vb is limited, so code tweaks will only get it a bit faster) you would need to move to c# or c++. See Christian Graus' articles which are linked to here for a bit on processing in c#
http://www.bobpowell.net/imageprocessing.htm
Re: Bitmap pixel colour detection
You may be interested to know that DoomSharp will eventually (when I finally get around to it) use this DMA (direct memory access) to do all of its graphical rendering at runtime. In tests I've managed to get performance in excess of the GDI+ libraries! MS aren't perfect after all :D
Re: Bitmap pixel colour detection
that pixelate code looks wicked ill check it tonight many thanks .....
.... still have a few forms to finish before i look at this image import
thanks again
ill skillls