我有一个tiff图像,我转换为png图像我想作为图像或字节数组返回。例如,一个tiff图像有3个图像我想要一次返回3个图像路径。下面我已经给出了我的代码。
string[] pngPaths = null;
byte[] filedata3 = null;
// Get an FileStream for reading the TIFF image
using (FileStream tifFs = new FileStream(
dirs[0], FileMode.Open, FileAccess.Read))
{
// get a TiffBitmapDecoder
TiffBitmapDecoder tifDecoder = new TiffBitmapDecoder(tifFs
, BitmapCreateOptions.PreservePixelFormat
, BitmapCacheOption.Default);
// Initialize PNG image location array
pngPaths = new string[tifDecoder.Frames.Count];
// Save each page in the TIFF image
for (int i = 0; i < tifDecoder.Frames.Count; i++)
{
// Get a PngBitmapEncoder
PngBitmapEncoder pngEncoder = new PngBitmapEncoder();
pngEncoder.Frames.Add(tifDecoder.Frames[i]);
// Construct a PNG image location
pngPath = string.Format("{0}_{1}{2}",dirs[0].Substring(0, dirs[0].LastIndexOf(".")), i.ToString(), ".png");
ContentType = MimeMappingWrapper.GetMimeMapping(pngPath);
pngPaths[i] = pngPath;