Issue in resizeing an image to thumbnail size
i have an image where i am resizing the image into thumbnail size it works fine if i am using an image size[700(width)* 600(height)] orignal size lets say i have 10 images of theis size
but if i use an image around size[1100*1200] orignal size it resize the image into thumbnail but doesnot match the size of the other thubnail image
when show in listview control all the images which are size in [700* 600] are shown in one size
image which is in size in [1100* 1200] are shown in one size[slighty smaller than other images]
so when i am displaying the image in listview control so this looks out all 10 images are shown in one size but one image is shown in a smaller size
and some times all the images are loaded fine
but some images are not shown only few images out 10 images 2 images sre not shown
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 Int开发者_高级运维Ptr());
}
this i the code what i am using i am setting the size height and width to 100
any help would be great thank you
I don't see what the problem is with your code, however, I would suggest using a Graphics object to draw the image instead of using Image object.
Here's an example:
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 control (and ImageList too) is designed to work with uniform sized images. This can be weird, but this is the situation. So I let ListView work as it wants. I created SquareThumbnail from all of my images from the normal thumbnails:
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();
}
I used ImageList.TransparentColor = Color.Purple
in the form to make it look good.
精彩评论