Listview icons show up blurry (C#) - c#

I'm attempting to display a "LargeIcon" view in a listview control, however the images I specify are blurry. This is what I have so far:
alt text http://img220.imageshack.us/img220/1005/blurryiconsql3.jpg
The .png files are 48x48 and that's what I have it set to display at in the ImageList properties. There's one thing that I've noticed (which is probably the cause) but I don't know how to change it. Inside the "Images Collection Editor" where you choose what images you want for the ImageList control, it looks like it's setting the wrong size for each image.
alt text http://img83.imageshack.us/img83/5218/imagepropertiesmf9.jpg
As you can see the "PhysicalDimension" and the "Size" is set to 16x16 and not abled to be manipulated. Does anyone have any ideas? Many thanks!

Be sure to set ImageList.ImageSize to 48 x 48 too.

When adding a .PNG Icon format size the editor tends to pick the first entry size in that file, so it picks up the 16x16 entry and it's stretching that out. That's why you see the 16x16 in the properties there. As suggested, the support for PNG is poor, I'm often found myself rolling over to another format as well to avoid this.
You can open the file in Paint.Net if you need a free editor or something more fully featured like Photoshop or Fireworks and extract the exact size you want.

I'm not sure if its the problem in this specific case, but Microsoft support for the PNG format is generally poor. Try adding the images in .bmp format and they should display fine.

Check also the ColorDepth setting on your ImageList. I had a similar issue with a TreeView control, but after reading the previous posting regarding the size I found this setting, played around with it a bit and found that it greatly affects the way images from an ImageList are rendered. The higher the depth the better the quality.

Be sure to set the ImageList size to 48x48 px BEFORE you add the images.
If the ImageList is set to 32x32 and you add a 48x48 image, the icon is resized to 32x32. When you change the ImageList to 48x48 afterwards, the image is just resized again, thus losing quality and going blurry.
Also, Paint.NET (or Photoshop) can't open .ico files.
Visual Studio/.NET can handle 32-bit PNG images fine, the built-in image editor in VS is a bit lack-lustre though.

Related

What does MSPaint process to eliminate objects in background when PNG image is converted to 4-bit BMP image?

I opened a PNG image, clicked Save As, changed to 16 color Bitmap, and saved it.
Then, MSPaint warned about loss of information about transparent and image qualities and, I clicked OK.
As a result, letters behind the black glass object disappeared clearly like this image (Before->After).
By changing PixelFormat or removing transparent area on C# (.Net 4.6.2), I tried to implement this feature just like MSPaint, however, it wasn't removed clearly. In some way, Nothing changed.
Is that not about PixelFormat or ColorDepth?
Or, Is there a way to get rid of objects behind another on PNG?
What should I do to implement that?
EDIT 1
Thank you so much, #TaW. By following your method ApplyGamma, I could solve the issue.

RibbonToggleButton displays image badly

I'm using Ribbon from RibbonControlsLibrary.dll 4.0.0.11019, .NET 4.0, C#, WPF.
It can be downloaded with a free samples here: http://www.microsoft.com/en-us/download/details.aspx?id=11877
The problem comes when a RibbonToggleButton is displayed. Then it's image seems to be a little bit broken, like a part of image is shifted for a few pixels.
EDIT: Thanks to kind people I can post and image now:
Here are some details:
Image is displayed in it's large variant
Image size is 32x32
I set image scaling to none for all the images of Ribbon
Image is broken only when the text in RibbonToggleButton has 1 line
Same image displays correctly in any other kind of button (RibbonButton, RibbonSplitButton etc.)
The image is displayed correctly when I set the font size in Windows to Medium (125%)
My OS is Windows 8
When I set the VerticalContentAlignment for the toggle button to "Bottom", the Image starts to display correctly, but the whole Ribbon starts to look ugly.
I experience this problem for all the toggle buttons, including those which are in a Microsoft's free samples.
I guess that probably the Image doesn't have enough space, so it's compressed from 32x32 to some smaller size.
I use the theme that is made of Microsoft's Generic theme, that is included in the RibbonControlsLibrary.dll. I guess I could fix the RibbonToggleButton template somehow, but I have no idea what to fix there.
Any ideas?
In the xaml declaration of your UserControl / Window put that line:
RenderOptions.BitmapScalingMode="HighQuality"

Image taken from ImageList looks different than taken straight from resource

I have a form with two buttons.
To one of them I assigned an image (a 16 x 16, 32 bit depth png) by setting the Image property from VS's properties editor (using the Import... button).
I also have an ImageList (16 x 16 ImageSize and Depth32Bit ColorDepth) to which I assigned the same image as to the first button also from the properties editor -> Images and then Add. Then I assigned this image to my second button this way:
button2.Image = imageList.Images[0];
And this is how the images look (2x the actual size):
Is it possible to have my second button look like my first one by using an ImageList? The reason why I use an ImageList is because when checking performance, the line of code that loaded the image from the resource was a hot spot according to VS's Performance Wizard.
My application will have a list of controls, each of which have a bunch of buttons with images, so I want them to load as fast as possible. So what I have is a static ImageList from which each of these controls get their images.
This is because the images you have added in your Imagelist have higher ColorDepth that the ColorDepth you have set in your ImageList Properties. for example, if the images you have added are in PNG format, you should set the ColorDepth of you ImageList (In the properties window) to Depth32Bit as the PNG format uses 32Bit color depth.

Problem with Images on TreeView

I have a TreeView with ItemHeight=16 and CheckBoxes=true. I want to show images that are 8x16 pixels in size on the nodes. But when I do this, the "Plus/Minus" and "CheckBoxes" change their size (get smaller).
How can I fix this? I don't want to use a 16x16 image because I don't want to loose those 8 pixels with white space.
Any suggestions?
That sounds like a bug. Checkbox size and plus/minus size shouldn't be affected by the image size. Check with MS and see if they have a solution.
Have you tried TreeViewAdv for .Net it comes with huge amounts of awesome, and should solve your problem...

C#: Using .ico file with multiple images

I'm trying to set the images in a TreeView in C#, from a .ico file containing two icons: a 32x32 version and a 16x16 version. The images are setting, but .Net is choosing the 32x32 version, and scaling it down (which looks terrible) instead of choosing the readily available 16x16 image.
The relevant code:
ilTree.Images.Add(Properties.Resources.group);
ilTree.Images.Add(Properties.Resources.single);
ilTree.Images.Add(Properties.Resources.db);
treeStored.ImageList = ilTree;
Where am I going wrong?
Answer:
There are two things you must do to get this to work. The first, as mentioned below, is to manually specify the correct size to the image list. The second is that you will also probably have to specify the color depth. MSDN states that:
In the .NET Framework version 1.1 or later, the default is Depth8Bit.
...however, that did not prevent ImageList from removing colors from my 8-bit icon. Upon close inspection, my icons (there were three) were: 4bit, 4bit, 8bit. The two 4 bit icons shared palettes, however the 8bit had a different one. In total, there were 257 colors between the icons. Despite the only slight overflow, .Net knocked it down to a mere 20 colors.
You need to create a new Icon object. There is an overload for the constructor that accepts the original Icon object and a size. I don't know if the new Icon object will share the same HIcon, but it will draw properly. To be safe, I would recommend ensuring that both are disposed.
Set the ImageSize property of the ImageList to new Size(16, 16)

Categories

Resources