C# TIFF图像开发
NuGet安装控件:
Install-Package BitMiracle.LibTiff.NET -Version 2.4.560
实现代码:
private BitmapSource TiffToBitmap(string fileName) { Tiff tif = Tiff.Open(fileName, "r"); if (tif == null) { return null; } // Find the width and height of the image FieldValue[] value = tif.GetField(TiffTag.IMAGEWIDTH); int width = value[0].ToInt(); value = tif.GetField(TiffTag.IMAGELENGTH); int height = value[0].ToInt(); // Read the image into the memory buffer int[] raster = new int[height * width]; if (!tif.ReadRGBAImage(width, height, raster)) { tif.Close(); tif.Dispose(); return null; } tif.Close(); tif.Dispose(); WriteableBitmap _wb = new WriteableBitmap(width, height, 96, 96, PixelFormats.Pbgra32, null); Int32Rect _rect = new Int32Rect(0, 0, _wb.PixelWidth, _wb.PixelHeight); int _bytesPerPixel = (_wb.Format.BitsPerPixel + 7) / 8; int _stride = _wb.PixelWidth * _bytesPerPixel; int _arraySize = _stride * _wb.PixelHeight; byte[] bits = new byte[_arraySize]; for (int y = 0; y < _wb.PixelHeight; y++) { int rasterOffset = y * _wb.PixelWidth; int bitsOffset = (_wb.PixelHeight - y - 1) * _stride; for (int x = 0; x < _wb.PixelWidth; x++) { int rgba = raster[rasterOffset++]; bits[bitsOffset++] = (byte)((rgba >> 16) & 0xff); bits[bitsOffset++] = (byte)((rgba >> 8) & 0xff); bits[bitsOffset++] = (byte)(rgba & 0xff); bits[bitsOffset++] = (byte)((rgba >> 24) & 0xff); } } _wb.WritePixels(_rect, bits, _stride, 0); return _wb; }
调用:
MyImage.Source = TiffToBitmap("test.tif");
Bit Miracle - Software for the PDF, TIFF, and JPEG formats.
https://bitmiracle.com/
Tiff转换Bitmap处理方法 - CSDN博客
https://blog.csdn.net/kongwei521/article/details/8259461
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧