【问题标题】:Resize tiff and maintain transparency and c#调整 tiff 大小并保持透明度和 c#
【发布时间】:2010-07-30 14:16:56
【问题描述】:

我正在尝试调整 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 创建的,我无法弄清楚为什么它在调整大小的 tiff 上没有保持透明度。

有什么想法吗?

【问题讨论】:

  • 你为什么专门打电话给g.Clear(Color.Transparent);
  • 您已经在这里待了足够长的时间,通过格式化代码示例以提高可读性来表达对人们的尊重。

标签: c# .net image


【解决方案1】:

您需要在新 Image thumbnail 时将像素格式设置为至少 32bpp argb:

new Bitmap(1500, 1500, PixelFormat.Format32bppPArgb)

编辑:

更好的是,从source 获取它,所以你得到了完全相同的一个,只是意味着反转你的usings

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2016-07-08
      • 2011-06-21
      • 2014-04-14
      • 2011-01-22
      • 1970-01-01
      • 2018-06-06
      • 2019-03-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多