Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将tiff像素纵横比更改为正方形_C#_Tiff_Barcode_Aspect Ratio - Fatal编程技术网

C# 将tiff像素纵横比更改为正方形

C# 将tiff像素纵横比更改为正方形,c#,tiff,barcode,aspect-ratio,C#,Tiff,Barcode,Aspect Ratio,我正在尝试对多页tiff文件执行条形码识别。但tiff文件来自传真服务器(我无法控制),该服务器以非方形像素纵横比保存tiff。这会导致图像由于纵横比而严重挤压。我需要将tiff转换为方形像素纵横比,但不知道如何在C#中实现。我还需要拉伸图像,这样更改纵横比仍然可以使图像清晰可见 有人在C#做过这件事吗?或者有人使用过图像库来执行这样的过程吗?哦,我忘了提一下位图。设置分辨率可能有助于解决纵横比问题。下面的内容只是关于调整大小 退房。它讨论了两种调整大小的机制。我怀疑在你的例子中,双线性滤波实际

我正在尝试对多页tiff文件执行条形码识别。但tiff文件来自传真服务器(我无法控制),该服务器以非方形像素纵横比保存tiff。这会导致图像由于纵横比而严重挤压。我需要将tiff转换为方形像素纵横比,但不知道如何在C#中实现。我还需要拉伸图像,这样更改纵横比仍然可以使图像清晰可见


有人在C#做过这件事吗?或者有人使用过图像库来执行这样的过程吗?

哦,我忘了提一下<代码>位图。设置分辨率可能有助于解决纵横比问题。下面的内容只是关于调整大小

退房。它讨论了两种调整大小的机制。我怀疑在你的例子中,双线性滤波实际上是一个坏主意,因为你可能想要好的和单色的东西

下面是naive resize算法的副本(由Christian Graus编写,来自上面链接的页面),这应该是您想要的

public static Bitmap Resize(Bitmap b, int nWidth, int nHeight)
{
    Bitmap bTemp = (Bitmap)b.Clone();
    b = new Bitmap(nWidth, nHeight, bTemp.PixelFormat);

    double nXFactor = (double)bTemp.Width/(double)nWidth;
    double nYFactor = (double)bTemp.Height/(double)nHeight;

    for (int x = 0; x < b.Width; ++x)
        for (int y = 0; y < b.Height; ++y)
            b.SetPixel(x, y, bTemp.GetPixel((int)(Math.Floor(x * nXFactor)),
                      (int)(Math.Floor(y * nYFactor))));

    return b;
}
公共静态位图调整大小(位图b,int nWidth,int nHeight)
{
位图bTemp=(位图)b.Clone();
b=新位图(nWidth、nHeight、bTemp.PixelFormat);
双nXFactor=(双)bTemp.Width/(双)nWidth;
双nYFactor=(双)bTemp.Height/(双)nHeight;
对于(int x=0;x

另一种机制是像这样滥用
GetThumbNailImage
函数。这段代码保持了纵横比,但是删除这样做的代码应该很简单。

我使用了两个图像库,FreeImage(开源)和Snowbound。(相当昂贵)FreeImage有一个c#包装,Snowbound在.Net程序集中提供。两者都很有效


在代码中调整它们的大小应该不是不可能的,但使用GDI+时,双色TIFF有时会很尴尬。

免责声明:我在Atalasoft工作


我们可以做到这一点。我们已经写信向您展示如何使用我们的产品,但您可以适应其他SDK。基本上,你需要对图像进行重采样并调整DPI。

如果其他人遇到同样的问题,下面是我解决这个恼人问题的超级简单的方法

using System.Drawing;
using System.Drawing.Imaging;

// The memoryStream contains multi-page TIFF with different
// variable pixel aspect ratios.
using (Image img = Image.FromStream(memoryStream)) {
    Guid id = img.FrameDimensionsList[0];
    FrameDimension dimension = new FrameDimension(id);
    int totalFrame = img.GetFrameCount(dimension);
    for (int i = 0; i < totalFrame; i++) {
        img.SelectActiveFrame(dimension, i);

        // Faxed documents will have an non-square pixel aspect ratio.
        // If this is the case,adjust the height so that the
        // resulting pixels are square.
        int width = img.Width;
        int height = img.Height;
        if (img.VerticalResolution < img.HorizontalResolution) {
            height = (int)(height * img.HorizontalResolution / img.VerticalResolution);
        }

        bitmaps.Add(new Bitmap(img, new Size(width, height)));
    }
}
使用系统图;
使用系统、绘图、成像;
//memoryStream包含具有不同格式的多页TIFF
//可变像素纵横比。
使用(Image img=Image.FromStream(memoryStream)){
Guid id=img.FrameDimensionsList[0];
FrameDimension维度=新的FrameDimension(id);
int totalFrame=img.GetFrameCount(维度);
对于(int i=0;i