2

我正在使用 CCIT4 压缩创建 tif 图像。此图像没有 EOFB。有人可以帮我如何将此 EOFB 添加到 tif 图像中。或者如何使用 EOFB 信息创建图像。

这是我在没有 EOFB 的情况下生成图像的代码

 var tifImg = new Bitmap(500, 500);
        tifImg.SetResolution(200, 200);
        Graphics graphic = Graphics.FromImage(tifImg);
        graphic.FillRectangle(new SolidBrush(Color.White), new Rectangle(0, 0, 500, 500));
        try
        {

                string data = "My data"; 
                Font vrFont = new Font("Verdana", 32, GraphicsUnit.Pixel);
                Size micrSize = TextRenderer.MeasureText(data, vrFont); 
                graphic.DrawString(data, vrFont, new SolidBrush(Color.Black), new Point(10, 100)); 
                Rectangle rectangle = new Rectangle(10, 20, 200, 60);
                graphic.DrawRectangle(new Pen(new SolidBrush(Color.Black)), rectangle);
                SaveImage(tifImg, fileName, appLogger);


        var imageEncoders = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders().ToList();
        var imageCodecInfo = imageEncoders.FirstOrDefault(o => o.MimeType == "image/tiff");

        var encoderParameter = new System.Drawing.Imaging.EncoderParameters(2);
        encoderParameter.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)System.Drawing.Imaging.EncoderValue.CompressionCCITT4);
        encoderParameter.Param[1] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.SaveFlag, (long)18);

            tifImg.Save(fileName, imageCodecInfo, encoderParameter); 
        }
        catch { throw; }
        finally
        {
            graphic.Dispose();
            tifImg.Dispose();
        }

谢谢,

埃森

4

2 回答 2

1

我知道你想要 c#,但是用 java 语言查看这个类并搜索所有“addEOFB”

于 2012-08-02T14:35:08.270 回答
1

这是我在项目中所做的代码。检查这是否对您有帮助。

 private void AddEOFB(string imgFileName)
    {
        var fs = new FileStream(imgFileName, FileMode.Append, FileAccess.Write);
        try
        {
            fs.Seek(0, SeekOrigin.End);
            var buf = BitConverter.GetBytes(0x00100100);
            fs.Write(buf, 0, buf.Length);
        }
        catch { throw; }
        finally
        {
            fs.Close();
            fs.Dispose();
        }
    }
于 2012-08-02T20:58:00.553 回答