EDN Admin
Well-known member
Ive had a problem with a program that copies parts of one image and pastes them onto another onto another. The image had RGB values altered when the image is saved out, and I couldnt understand why.
So I stripped the problem down to its bare essentials, and found that if I make a .png image which is a flat field of one colour only - say, R=132 G=132 B=255 - and load it into a bitmap in vb.net, then save it out again, its still the same colour.
OK so far.
If I use Drawstring to cut & paste a small piece of this image onto itself (doesnt matter where), when I save it out, the resulting image is a flat field of value R=130, G=128, B=253. Why the colour change?
Heres the business part of the code:
Dim BaseImage As Bitmap<br/>
BaseImage = New Bitmap("FlatImage.png", True)<br/>
Dim Rect As New Rectangle(100, 100, 200, 200)<br/>
gr.DrawImage(BaseImage, Rect, Rect, GraphicsUnit.Pixel)<br/>
BaseImage.Save("FlatImage_out.png")
The original values are preserved if the image is loaded and saved as .bmp format, but I have transparent areas in my images, so I have to use .png. Also, I need to preserve the exact colours in the original image. The differences are too big for a
simple rounding error, unless perhaps theres a conversion to HSL or some other colour space in the .png save.
VS 2010 v 10.0.30319 .Net v 4.0.30319 Win 7 Pro 64 bit
View the full article
So I stripped the problem down to its bare essentials, and found that if I make a .png image which is a flat field of one colour only - say, R=132 G=132 B=255 - and load it into a bitmap in vb.net, then save it out again, its still the same colour.
OK so far.
If I use Drawstring to cut & paste a small piece of this image onto itself (doesnt matter where), when I save it out, the resulting image is a flat field of value R=130, G=128, B=253. Why the colour change?
Heres the business part of the code:
Dim BaseImage As Bitmap<br/>
BaseImage = New Bitmap("FlatImage.png", True)<br/>
Dim Rect As New Rectangle(100, 100, 200, 200)<br/>
gr.DrawImage(BaseImage, Rect, Rect, GraphicsUnit.Pixel)<br/>
BaseImage.Save("FlatImage_out.png")
The original values are preserved if the image is loaded and saved as .bmp format, but I have transparent areas in my images, so I have to use .png. Also, I need to preserve the exact colours in the original image. The differences are too big for a
simple rounding error, unless perhaps theres a conversion to HSL or some other colour space in the .png save.
VS 2010 v 10.0.30319 .Net v 4.0.30319 Win 7 Pro 64 bit
View the full article