-2

I'm making a program to automatically perform certain edits on images.

One of the functions is converting "white" pixels to "white" and transparent. Initially, all is well.

I have managed to convert a 24bppRGB image to a 32bppRGB image with the required pixels all transparent.

The image loads in picturebox and can be opened once saved.

The problem arose when I tried to re-edit the file. When I tried to extract the raw pixel data again, I got nothing. As far as I can tell the entire pixel data array is 0's.

Why is this the case?

^This is my main question. Outside of that problem, I also noticed a few quirks with the program, these are just out of curiosity:

What's the difference between:

for(int i = 0; i < (x + 1); i += y)

and

for(int i = 0; i <= (x); i += y)

And also:

byte = 4;
for(int i = 0; i < x - byte; i += byte)

and

for(int i = 0; i < x - byte; i += 4)

The 2nd one caused a AccessViolationException when I unlocked the bitmap.

If possible, keep the explanation as simple as possible. I'm a fairly new at this. Thanks for your time.

  • Could it be a mismatch of `PixelFormat` in the call to LockBits, when opening the 32bppARGB image? – Anlo Apr 18 '12 at 11:46
  • I added code formatting to your question, but the second set of `for` loops don't make sense as a question, you may need to clarify. – Chris O Apr 18 '12 at 12:33
  • Hmm, I try to use bmp.PixelFormat as well as PixelFormat.Format32bppArgb. Neither produced an image. – user1341109 Apr 19 '12 at 04:25
  • That's strange, bmp.PixelFormat should definately work. Could you upload a 32bpp image somewhere so I can take a look? – Anlo Apr 19 '12 at 07:55

1 Answers1

1

here is a little tip with example, how to work with bitmaps easily.

p.s. difference between:

for(int i = 0; i < (x + 1); i += y)

and

for(int i = 0; i <= (x); i += y)

depends on y value.

Vano Maisuradze
  • 5,829
  • 6
  • 45
  • 73