I made a small program that uses GetPixel and SetPixel to
scan through a bitmap and change colors. So far so good.
The problem is trying to save the images.
Well, the images save, but only the original, not the new,
touched up versions.
What fine point of bitmap manipulation am I missing?
I declared a variable as picture, used a common dialog to get
a filename and then set the picture.
The picture is then loaded (LoadPicture) into a picturebox (scalemode = 3 ,
autoredraw = false). I change autoredraw to true right before
saving. (SetPixel won't work with autoredraw set to true and
I can't save without autoredraw = true. Life is full of irony).
I sample the area I want to change using GetPixel, then use ShowColor to get the (Long of the) color I want to change to, then use a loop to make the changes (SetPixel).
The picture is saved using the SavePicture function.
I tried declaring and setting (As Picture) the current Picture1.Image before saving, but that didn't work either.
I'm sure you need AutoRedraw set to true when you edit the pixels for it to have effect, cos as soon as it refreshes it'll undo the changes you've made. Mind if you want to use it I'v added a class I made which handles bitmaps using offscreen DCs, which is a lot faster than using SetPixel and GetPixel. Try using the GetByteArray and SetByteArray, they use a 2D byte array. Example is with it in the download.
Hope it helps.
When your thread has been resolved please edit the original post in the thread ()
and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.
Thanks Electroman and I'll check out the module you
posted when I get home.
I finally got it got work. Since speed isn't an issue, I ended
up not using SetPixelV to do the work. I experimented with
line and pset (both work fine, but a bit pokey) and settled
on pset.
No matter what I tried, I couldn't create a persistent image
using SetPixel.
Last edited by Rocketdawg; Feb 13th, 2003 at 09:19 PM.
you have to set AutoRedraw = True....
when the changes to the picture is done with SetPixel(V) do Picture1.Refresh
then save with SavePicture and use the picture1.image property!
SetPixelV is a bit faster than SetPixel...SetPixel returns the previous color value of the changed pixel so thats like calling both get and setpixel...