.net 将图像大小调整为缩略图大小时出现的问题

.net 将图像大小调整为缩略图大小时出现的问题,.net,system.drawing,.net,System.drawing,我有一个图像,我正在将图像大小调整为缩略图大小 如果我使用的是图像大小[700(宽)*600(高)]原始大小,则效果良好 假设我有10张这个尺寸的图片 但如果我使用的图像大小约为[1100*1200]原始大小 它将图像调整为缩略图,但与其他thubnail图像的大小不匹配 在listview控件中显示时 所有尺寸为[700*600]的图像都以一种尺寸显示 尺寸为[1100*1200]的图像显示为一种尺寸[略小于其他图像] 所以当我在 listview控件,这样看起来 所有10幅图像都以一种尺寸显

我有一个图像,我正在将图像大小调整为缩略图大小 如果我使用的是图像大小[700(宽)*600(高)]原始大小,则效果良好 假设我有10张这个尺寸的图片

但如果我使用的图像大小约为[1100*1200]原始大小 它将图像调整为缩略图,但与其他thubnail图像的大小不匹配

在listview控件中显示时 所有尺寸为[700*600]的图像都以一种尺寸显示

尺寸为[1100*1200]的图像显示为一种尺寸[略小于其他图像]

所以当我在 listview控件,这样看起来 所有10幅图像都以一种尺寸显示 但有一张图片是用较小的字体显示的 大小

有时,所有图像都可以很好地加载

但有些图像未显示,10幅图像中只有少数图像未显示,2幅图像未显示

System.Drawing.Image objImage = System.Drawing.Bitmap.FromFile(System.Web.HttpContext.Current.Server.MapPath(@"Images\" + sImageFileName));
if (sImageFileName != null)
{
    if (iThumbSize == 1)
    {

        dHeight = objImage.Height;
        dWidth = objImage.Width;
        dNewHeight = 100;
        dNewWidth = 100;
        objImage = objImage.GetThumbnailImage((int)dNewWidth, (int)dNewHeight, new System.Drawing.Image.GetThumbnailImageAbort(callback), new IntPtr());
}
这是我正在使用的代码 我正在将尺寸高度和宽度设置为100

任何帮助都会很好
谢谢

我看不出你的代码有什么问题,但是,我建议使用图形对象来绘制图像,而不是使用图像对象
下面是一个例子:

Bitmap newImage = new Bitmap(newWidth, newHeight); using (Graphics gr = Graphics.FromImage(newImage)) {
    gr.SmoothingMode = SmoothingMode.AntiAlias;
    gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
    gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
    gr.DrawImage(srcImage, new Rectangle(0, 0, newWidth, newHeight)); }

我不知道你的代码有什么问题,但是,我建议使用图形对象来绘制图像,而不是使用图像对象
下面是一个例子:

Bitmap newImage = new Bitmap(newWidth, newHeight); using (Graphics gr = Graphics.FromImage(newImage)) {
    gr.SmoothingMode = SmoothingMode.AntiAlias;
    gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
    gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
    gr.DrawImage(srcImage, new Rectangle(0, 0, newWidth, newHeight)); }
ListView控件(以及ImageList)设计用于处理统一大小的图像。这可能很奇怪,但情况就是这样。所以我让ListView按照它想要的方式工作。我从普通缩略图中创建了所有图像的SquareThumbnail:

private void Thumbnail_Square()
{
    Size size = new Size(Settings.Thumbnail.Size, Settings.Thumbnail.Size);
    this._squareThumbnail = new Bitmap(size.Width, size.Height, this._thumbnail.PixelFormat);
    Graphics g = Graphics.FromImage(this._squareThumbnail);
    g.FillRectangle(Brushes.Purple, 0, 0, size.Width, size.Height);
    size = this._thumbnail.Size;
    Point location = new Point(
        (Settings.Thumbnail.Size - size.Width) / 2,
        (Settings.Thumbnail.Size - size.Height) / 2);
    g.DrawImage(this._thumbnail,
    new Rectangle(location.X, location.Y, size.Width, size.Height),
    new Rectangle(0, 0, this._thumbnail.Width, this._thumbnail.Height), GraphicsUnit.Pixel);
    g.Dispose();
}
我在表单中使用了
ImageList.TransparentColor=Color.Purple
,以使其看起来更美观。

ListView控件(以及ImageList)设计用于处理大小一致的图像。这可能很奇怪,但情况就是这样。所以我让ListView按照它想要的方式工作。我从普通缩略图中创建了所有图像的SquareThumbnail:

private void Thumbnail_Square()
{
    Size size = new Size(Settings.Thumbnail.Size, Settings.Thumbnail.Size);
    this._squareThumbnail = new Bitmap(size.Width, size.Height, this._thumbnail.PixelFormat);
    Graphics g = Graphics.FromImage(this._squareThumbnail);
    g.FillRectangle(Brushes.Purple, 0, 0, size.Width, size.Height);
    size = this._thumbnail.Size;
    Point location = new Point(
        (Settings.Thumbnail.Size - size.Width) / 2,
        (Settings.Thumbnail.Size - size.Height) / 2);
    g.DrawImage(this._thumbnail,
    new Rectangle(location.X, location.Y, size.Width, size.Height),
    new Rectangle(0, 0, this._thumbnail.Width, this._thumbnail.Height), GraphicsUnit.Pixel);
    g.Dispose();
}

我在表单中使用了
ImageList.TransparentColor=Color.Purple
,以使其看起来更美观。

因此您有两个问题,一个是纵横比的一致性,另一个是一些大小调整后的图像没有显示,是吗?是的,这就是您所说的问题。因此您有两个问题,一个是纵横比的一致性,另一个是一些调整大小的图像没有显示,是吗?是的,这就是你所说的问题