tags:

views:

38

answers:

2

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?

+2  A: 

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 usings

Andrew Bullock
A: 

This one may be of some help:

Why does resizing a png image lose transparency?

Leniel Macaferi