Last post Mar 09, 2006 01:09 PM by toptomato
Mar 06, 2006 09:24 AM|toptomato|LINK
Thanks in advance to all of you geniouses.
Here is what I am doing:
This is an ASP.net 2.0 with C# problem.
I am reading an image file (either: gif, jpg or png of any dimension) as such:
Image rImg = Image.FromFile(RawFilePath)
Next I create a Bitmap and extract graphic as such:
Bitmap wImage = new Bitmap(200, 200, PixelFormat.Format24bppRgb)
Graphics g = Graphics.FromImage(wImage)
Next I draw the Image in the graphic using only 50x50 square from the topleft corner of the rImg as such:
g.DrawImage(rImg, new Rectangle(0, 0, 200, 200), new Rectangle(0,0,50,50), GraphicsUnit.Pixel);
Finally I save the bitmap to disk as such:
Now here is the problem:
By design I can accept any of the three types of images (gif, png, jpg) and of any dimension. I must also by design only select the 50x50 square from the topleft corner and save as 200x200. Now here is the issue: My objective is to preserve transperencey,
especially in case of png files. Right now when I try to read a PNG that has transperency it save the transparent part of the image as black. How can I have it save the transaparent part as transparent? Thanks guys
Mar 06, 2006 04:52 PM|Garry English|LINK
Create the wImage Bitamp with PixelFormat.Format32bppArgb
Format24bppRgb doesn't contain a bit for Alpha.
Mar 09, 2006 09:25 AM|toptomato|LINK
Sorry for the delayed response. but you'r right. when saving in 32 bit it does saves the transperency. However you images saved as 32 bits (wheather they are png or jpg) don't show up in the browsers. Any fix for that or another
way of saving as 24 bits with transperency.
Mar 09, 2006 12:01 PM|Garry English|LINK
Png's and Gifs support transparent pixels, but Jpg's don't.
IE doesn't support the transparent pixels in Png files natively, but there are some work arounds. The transparent pixels of a Png file will appear grey in IE. Here is a link for some work arounds:
I believe that you can save a 24 bit Gif and the transparent pixels will show, but for Png's you will have to use a pixel format that has an alpha bit.
Mar 09, 2006 01:09 PM|toptomato|LINK
hi Garry appriciate your help, i tried the pingfix.js and it works, however, Internet Explorer (although not true in case of firefox) doesn't displays images that are saved as 32bits (wheather they are png or jpg). I tried the pngfix.js with two png files
(one saved as 24bits and one saved as 32 bits), the 24bit showed up with transparency perfectly, however the 32 bit didn't show up at all. However, on firefox the 32bit showed up with transparency perfactly.
Now is there a way to have a 32bit image show up on ie or is there a way to save 24bit png with transparency?