Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PNG transparency clipping

Status
Not open for further replies.

kettch

Programmer
Mar 5, 2001
110
US
I have an application that allows a user to position a graphic on a surface. Once the graphic is positioned, it is saved as a PNG that is set to a certain size. The image is always saved as the same size, so that the image will have different amounts of transparency, depending on how large the sub-image is. Later on the image will be reloaded and positioned at a known point, and the transparency will provide padding to make sure that the sub-image is in the right place. Make sense?

My problem is that when I load an image from a database, like this:

Code:
primaryImage = Drawing.Image.FromStream(New IO.MemoryStream(DirectCast(primaryImageData("ImageData"), Byte())))

I'm saving the image like this:

Code:
Dim ms As New IO.MemoryStream
img.Save(ms, Drawing.Imaging.ImageFormat.Png)
Dim b() As Byte = ms.GetBuffer
ms.Close()
primaryImageData("ImageData") = b

If I immediately do this:

Code:
Dim someImg As Bitmap = Drawing.Image.FromStream(New IO.MemoryStream(DirectCast(primaryImageData("ImageData"), Byte())), True)

someImg.Save("c:\temp\testimage.png")

Then the image comes out just fine, but for some reason it doesn't work when the datarow is fresh out of a dataset that was just populated from the database. My test case is the exact same code.


It somehow comes out with all of the transparency clipped off. I've verified that the image goes into the database correctly, and I've verified that I can load a PNG from a file correctly. Is there a better way to do this? Preferably one that preserves my image?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top