Patch: Transparent Images

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 年 前
I really wanted to upload transparent PNG files, and needed to maintain the transparency. So I made a few changes that I wanted to pass along:
                            var newBitMap = new Bitmap(newSize.Width, newSize.Height, PixelFormat.Format32bppArgb);
                            var g = Graphics.FromImage(newBitMap);
              g.FillRegion(new SolidBrush(Color.FromArgb(0, Color.White)), g.Clip);
                            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                            g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                            g.DrawImage(b, 0, 0, newSize.Width, newSize.Height);
                            var ep = new EncoderParameters();
                            ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, PictureManager.ImageQuality);
                            //newBitMap.Save(Path.Combine(PictureManager.LocalThumbImagePath, localFilename), getImageCodeInfo("image/jpeg"), ep);
              newBitMap.Save(Path.Combine(PictureManager.LocalThumbImagePath, localFilename), ImageFormat.Png);
                            newBitMap.Dispose();
                            b.Dispose();


Ideally it would look at the lastPart variable and use either the jpeg (commented out above) or png line depending on the source and desired output image.

For best results, the above code is also needed in these 3 methods:
PictureManager.GetPictureUrl(Picture picture, int TargetSize, bool showDefaultPicture)
PictureManager.GetDefaultPictureUrl(PictureTypeEnum DefaultPictureType, int TargetSize)
PictureManager.ValidatePicture(byte[] PictureBinary)
13 年 前
Im trying to do this, but have it detect the file type and select the approp encoding. This seems to work fine, except for the validateimage function which takes a byte array with no additional data on the file. Any ideas on how to detect what the file type is in this function?
13 年 前
Nope. I think it would have to modify the ValidateImage method to either accept a filename as a parameter, or else skip image generation entirely, which is safe because the above methods will pick up on it if the image hasn't been saved out yet. The ValidateImage method dosn't have to save it, but does so as a way of pre-caching.
13 年 前
thanks for the feedback. i may add this.. but im trying to keep code changes to a minumum to reduce my work when future versions release and need to be merged in. fun fun :)
13 年 前
Right. so I would just Skip saving the file entirely in the ValidateImage method. Leave the part where it initializes, or save the image to a MemoryStream instead of a file, so that image load/save can be tested, which is the purpose of the method.
13 年 前
excellent, thanks!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.