Resize tiff and keep transparency and C #

I am trying to resize an 8-bit TIF RGB and maintain its transparency in C #. I 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 understand why it does not hold the transparency on the resized.

Any ideas?

+3
source share
2 answers

I really found out that due to how transparency is stored in tiff format using Photoshop, it was better to create png by automating photoshop and then crunching the resulting png.

+1
source

you need to install pixelformat when you upgrade Image thumbnailto at least 32bpp argb:

new Bitmap(1500, 1500, PixelFormat.Format32bppPArgb)

Edit:

, source, , , using s

+4

Source: https://habr.com/ru/post/1757358/


All Articles