调整tiff并保持透明度和c#

我正在尝试调整RGB 8位Tif的大小并保持它在c#中的透明度。 我试过以下代码。

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(); //} } 

图像是使用photoshop创建的,我无法弄清楚为什么它没有在resize的tiff上保持透明度。

有任何想法吗?

你需要在新手时设置pixelformat Image thumbnail至少为32bpp argb:

 new Bitmap(1500, 1500, PixelFormat.Format32bppPArgb) 

编辑:

更好的是,从source抓取它,所以你有完全相同的,只是意味着扭转using s

我实际上发现,由于使用photoshop以tiff格式存储透明度的方式,最好通过自动化photoshop然后处理生成的png来创建png。