Reputation: 7646
I'm trying to resize an RGB 8-Bit Tif and maintain it's transparency in c#. I've tried the following code.
using (Image thumbnail = new Bitmap(1500, 1500))
{
using (Bitmap source = new Bitmap(@"c:\trans.tif"))
{
using (Graphics g = Graphics.FromImage(thumbnail))
{
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.Clear(Color.Transparent);
g.DrawImage(source, 0, 0, 1500, 1500);
}
}
thumbnail.Save(@"c:\testoutput.tif", ImageFormat.Tiff);
//using (MemoryStream ms = new MemoryStream())
//{
// //thumbnail.Save(ms, ImageFormat.Tiff);
// //
// //result = ms.ToArray();
//}
}
The image was created using photoshop and I can't figure out why it's not holding the transparency on the resized tiffs.
Any ideas?
Upvotes: 3
Views: 1822
Reputation: 7646
I actually found out that due to the way the transparency is stored in the tiff format with photoshop it was better to create png's by automating photoshop and then crunching off the resulting png.
Upvotes: 1
Reputation: 37436
you need to set the pixelformat when you new up Image thumbnail
to at least 32bpp argb:
new Bitmap(1500, 1500, PixelFormat.Format32bppPArgb)
Edit:
Even better, grab it from source
so youve got exactly the same one, just means reversing your using
s
Upvotes: 4