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?
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.