小编Dyl*_*est的帖子

将 Tiff 的帧组合成单个 png 会导致内存不足异常 C#

首先,我将 tiff 的帧保存到位图列表中:

public Bitmap SaveTiffAsTallPng(string filePathAndName)
{
    byte[] tiffFile = System.IO.File.ReadAllBytes(filePathAndName);
    string fileNameOnly = Path.GetFileNameWithoutExtension(filePathAndName);
    string filePathWithoutFile = Path.GetDirectoryName(filePathAndName);
    string filename = filePathWithoutFile + "\\" + fileNameOnly + ".png";

    if (System.IO.File.Exists(filename))
    {
        return new Bitmap(filename);
    }
    else
    {
        List<Bitmap> bitmaps = new List<Bitmap>();
        int pageCount;

        using (Stream msTemp = new MemoryStream(tiffFile))
        {
            TiffBitmapDecoder decoder = new TiffBitmapDecoder(msTemp, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
            pageCount = decoder.Frames.Count;

            for (int i = 0; i < pageCount; i++)
            {
                System.Drawing.Bitmap bmpSingleFrame = Worker.BitmapFromSource(decoder.Frames[i]);
                bitmaps.Add(bmpSingleFrame);
            }

            Bitmap …
Run Code Online (Sandbox Code Playgroud)

c# asp.net tiff image-processing out-of-memory

0
推荐指数
1
解决办法
359
查看次数

标签 统计

asp.net ×1

c# ×1

image-processing ×1

out-of-memory ×1

tiff ×1