1

我有一个图像,我正在将图像调整为缩略图大小

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

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

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

所以当我在列表视图控件中显示图像时,这看起来所有 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

任何帮助都会非常感谢

4

2 回答 2

1

我看不出您的代码有什么问题,但是,我建议使用 Graphics 对象而不是使用 Image 对象来绘制图像。
这是一个例子:

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)); }
于 2009-12-02T07:36:17.920 回答
0

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在表格中使用以使其看起来不错。

于 2011-01-09T14:31:14.973 回答