0

I've been working on a program made in windows form application. The background changes differently depending on what key you press.

Even though I made the backgrounds in Photoshop and saved it on high quality settings, the pictures still are a poor quality (not even HD quality).

The pictures get randomly picked out of a imagelist. I'm using the Stretch option to make the image automatically resize.

How to improve the picture quality?

this.BackgroundImage = imageList1.Images[Number2];
BackgroundImageLayout = ImageLayout.Stretch;
TaW
  • 53,122
  • 8
  • 69
  • 111
DutchJelly
  • 59
  • 6
  • A piece of code showing how you're displaying the picture(s) would help a lot towards us understanding your problem. – LightBulb Feb 25 '17 at 21:21
  • um where do I find those? – DutchJelly Feb 25 '17 at 21:28
  • My main problem is finding where I can adjust picture quality of images in the imagelist.. I don't know where I can find the code. – DutchJelly Feb 25 '17 at 21:36
  • If you don't have code that shows that effect why do you have the question? I'm not sure if SO can help debugging the issue unless you provide [MCVE]. – Alexei Levenkov Feb 25 '17 at 22:01
  • I made an edit with the code showing how I'm displaying the backgroundimage on my windows form application. – DutchJelly Feb 25 '17 at 22:03
  • is there a way to pm you the total code? I'm pretty sure you can reproduce the problem if you choose a high quality image in you imagelist and display it using the this.Backgroundimage1 method – DutchJelly Feb 25 '17 at 22:07

1 Answers1

4

ImageList can only hold images of 256x256 pixels or less and it tranforms all images you add to the one size you set it to.

It is meant to hold small stuff, like listview&treeview images, state images and other basically icon-size graphics. - Note that by default the size and also the color depth of a ImageList.Image are even much lower..:

ImageList is typically used by other controls, such as the ListView, TreeView, or ToolBar. You can add bitmaps or icons to the ImageList, and the other controls are able to use the images as they require.

ImageList.ImageSize : The Size that defines the height and width, in pixels, of the images in the list. The default size is 16 by 16. The maximum size is 256 by 256.

ImageList.ColorDepth The number of available colors for the image. In the .NET Framework version 1.0, the default is Depth4Bit. In the .NET Framework version 1.1 or later, the default is Depth8Bit.

Your images surely are lot larger; so you need to hold the images in a List<Bitmap>:

List<Bitmap> images = new List<Bitmap>()

Now load the list, maybe from bitmaps you have stored as a resource and then access as usual:

this.BackgroundImage = images[someNumber2];
...

Of course the alternative would be to load them from disk.

Community
  • 1
  • 1
TaW
  • 53,122
  • 8
  • 69
  • 111
  • So it's still a list where everything gets sorted from 0 to (in my case) 8? Thanks by the way, I'll try it out! – DutchJelly Feb 25 '17 at 23:25
  • Yes you can acces a `List` with an interger index like an array (although they are [not the same internally](http://stackoverflow.com/questions/6705583/indexers-in-list-vs-array).) - Lists have many other advantages over arrays. In fact the `Images` property of an `ImageList` is itself a collection that implements the `IList` interface.. – TaW Feb 25 '17 at 23:31
  • I'm not sure where I can add the pictures to. Is it some folder I have to add it to? – DutchJelly Feb 25 '17 at 23:38
  • If you mean how to add them to the application's resources, there are many posts about that. One way is to open the Form's ´.resx` file in the project solution tab and choose `Add Resource - Existing file`, similar like you added them to the imagelist, probably. If you did that in code however, you can do the same all without using the resources. The difference is that using the resources you embed the image, making the exe portable but also bulky.. – TaW Feb 25 '17 at 23:58
  • You could rely on the order you add them in but I would prefer to use a naming scheme for better flexibilty and readabililty. You can then retrieve them by names, say back1, back2.. – TaW Feb 26 '17 at 00:14
  • I'm sorry, but I can't figure out how to load the images from the resources into the list. Could you explain that a little more in depth? I'm pretty new to C#, sorry for the amount of questions. Also, I'll use the names as sortingmethode, good call on that one. – DutchJelly Feb 26 '17 at 00:22
  • Check out this [image](http://imgur.com/a/cis7O) and this button code : `Random rnd = new Random(); string n = (rnd.Next(4) + 1).ToString("#0"); System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetExecutingAssembly(); Stream myStream = myAssembly.GetManifestResourceStream( "scribble.Images.img" + n + ".png" ); this.BackgroundImage = new Bitmap(myStream);` I created the folder and dropped the images there. – TaW Feb 26 '17 at 07:58
  • If you are happy with an answer, please consider [accepting](http://stackoverflow.com/help/accepted-answer) it..! – TaW Feb 26 '17 at 19:46