重新采样Tiff图像

时间:2017-09-11 09:47:56

标签: c# image tiff resampling

我需要根据导航线(地震测量数据)重新采样Tiff图像。例如:宽度= 9857和高度= 1187的Tiff图像,我需要调整(缩小尺寸)宽度= 2160和高度= 1187。我尝试过使用默认的C#编码器和压缩算法,我知道这比原始图像尺寸缩小了70%。它在缩小尺寸期间失去了图像的分辨率。有什么方法可以避免吗??

    private static Bitmap LZWCompression(Image source, int width, int height)
    {
        Bitmap Destbitmap = new Bitmap(source, width, height);

        Destbitmap.SetResolution(300, 300);

        ImageCodecInfo myImageCodecInfo;
        myImageCodecInfo = GetEncoderInfo("image/tiff");

        System.Drawing.Imaging.Encoder myEncoder;
        myEncoder = System.Drawing.Imaging.Encoder.Quality;
        EncoderParameters myEncoderParameters;
        myEncoderParameters = new EncoderParameters(1);
        EncoderParameter myEncoderParameter;
        myEncoderParameter = new EncoderParameter(myEncoder, 100000L);
        myEncoderParameters.Param[0] = myEncoderParameter;
        Destbitmap.Save(@"E:\Resized_LZW.tiff", myImageCodecInfo, myEncoderParameters);
        return Destbitmap;
    }


    private static ImageCodecInfo GetEncoderInfo(String mimeType)
    {
        int j;
        ImageCodecInfo[] encoders;
        encoders = ImageCodecInfo.GetImageEncoders();
        for (j = 0; j < encoders.Length; ++j)
        {
            if (encoders[j].MimeType == mimeType)
                return encoders[j];
        }
        return null;
    }

0 个答案:

没有答案