gpt4 book ai didi

.net - 将多页 TIFF 转换为 PNG .Net

转载 作者:行者123 更新时间:2023-12-04 00:28:37 24 4
gpt4 key购买 nike

我可以在 .Net 中将单页 TIFF 转换为 PNG,但是,对于多页 TIFF,我将如何执行此操作?

最佳答案

谢谢@Tom Halladay

我将提供您代码的 c# 版本

private static Bitmap ConvertTiffToBitmapStream(byte[] tiffImage){
System.Drawing.Image ImageBitmap = Bitmap.FromStream(new MemoryStream(tiffImage));
int FrameCount = ImageBitmap.GetFrameCount(FrameDimension.Page);
int RunningHeight = 0;
int MaxWidth = 0;

for (int MeasurementFrameIndex = 0; MeasurementFrameIndex <= FrameCount - 1; MeasurementFrameIndex++){
ImageBitmap.SelectActiveFrame(FrameDimension.Page, MeasurementFrameIndex);
RunningHeight += ImageBitmap.Height;
MaxWidth = Math.Max(MaxWidth, ImageBitmap.Width);
}

Bitmap CombinedBitmap = new Bitmap(MaxWidth, RunningHeight);
int RunningVerticalPosition = 0;

for (int CombinationFrameIndex = 0; CombinationFrameIndex <= FrameCount - 1; CombinationFrameIndex++){
ImageBitmap.SelectActiveFrame(FrameDimension.Page, CombinationFrameIndex);
EmbedBitmap(new Bitmap(ImageBitmap), ref CombinedBitmap, RunningVerticalPosition);
RunningVerticalPosition += ImageBitmap.Height + 1;
}
return CombinedBitmap;
}

private static void EmbedBitmap(Bitmap SourceBitmap, ref Bitmap DestinationBitmap, int VerticalPosition){
Rectangle SourceRectangle = new Rectangle(new Point(0, 0), new Size(SourceBitmap.Width, SourceBitmap.Height));
Rectangle DestinationRectangle = new Rectangle(new Point(0, VerticalPosition), new Size(SourceBitmap.Width, SourceBitmap.Height));

using (Graphics Canvas = Graphics.FromImage(DestinationBitmap)){
Canvas.DrawImage(SourceBitmap, DestinationRectangle, SourceRectangle, GraphicsUnit.Pixel);
}
}

关于.net - 将多页 TIFF 转换为 PNG .Net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3566650/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com