Note that there are some explanatory texts on larger screens.

plurals
  1. POList view control displaying distorted images
    primarykey
    data
    text
    <p>I have a problem with the ListView control in a windows forms application. Even if I create a thumbnail image or resize the real one I get distorted images in the list view. The image looks like when you zoom in an image very much. I first thought that the GetThumbnailImage is couseing this but I used a resize code I found here and I have the same result. </p> <p>I also did not found any bug related to list view control so I gues I'm doing something wrong but I just can't figure out what. Here is the code I use:</p> <pre><code>lsvPictures.LargeImageList = m_imagesList; lsvPictures.LargeImageList.ImageSize = new Size(100, 100); lsvPictures.View = View.LargeIcon; lsvPictures.CheckBoxes = true; for (int i = 0; i &lt; ofd.FileNames.Length; i++) { filename = ofd.FileNames[i].ToString(); ListViewItem lvi = new ListViewItem(filename); m_imagesList.Images.Add(ResizeImage(Image.FromFile(filename), 100, 100)); lvi.ImageIndex = i; lsvPictures.Items.Add(lvi); } </code></pre> <p>And this is the function that resizes images:</p> <pre><code>public static System.Drawing.Bitmap ResizeImage(System.Drawing.Image image, int width, int height) { //a holder for the result Bitmap result = new Bitmap(width, height); //use a graphics object to draw the resized image into the bitmap using (Graphics graphics = Graphics.FromImage(result)) { //set the resize quality modes to high quality graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //draw the image into the target bitmap graphics.DrawImage(image, 0, 0, result.Width, result.Height); } //return the resulting bitmap return result; } </code></pre> <p>Thank you! Mosu'</p> <p>I just found the source of the problems:</p> <p><code>m_imagesList.ColorDepth = ColorDepth.Depth16Bit;</code></p> <p>It seams that, as default, the ColorDepth of the ImageList is 8 bit (or 4 bit, but my guess is 8). If I change this to at least 16 bit everything looks very nice. </p> <p>To those with similar problems: I changed my Thumbnail method a lot before I realised that the ListView control is not using the color depth the images were having. I put the result of my method on a PictureBox control and saw that the function was working corectly. Atfer this I googled a lot ... and found that silly ColorDepth property. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload