I'm writing a little tool for my mother, and it uses "picto's", which really are icons. I scanned in a page with all those picto's, and cut out all the icons.
This is what I am trying to do:
- Load an icon
- Create a new bitmap for the result icon with the size of (50,50)
- Copy the icon to the center of the new image (new.w/2-icon.w/2, new.h/2-icon.h/2)
- Draw a border around the new image.
I want to do this because not all icons are the same size, while the results needs them to be like that.
To display the resulting icons - with names - I added a ListView to my form, and an ImageList to store the images. It works, but the end result is not what I expected it to be:
The icons are centered to the top-left of the image. Besides, there are weird blue lines. This is a sample of the stored icons:
Here is the code that loads an icon:
Bitmap raw = new Bitmap(file.FullName);
Bitmap picto = new Bitmap(imgSize, imgSize);
Graphics pictog = Graphics.FromImage(picto);
pictog.DrawImage(raw, (picto.Width/2)-(raw.Width/2), (picto.Height/2)-(raw.Height/2));
pictog.DrawRectangle(borderPen, 0, 0, imgSize, imgSize);
raw.Dispose();
pictog.Dispose();
ret.Add(new Picto(picto, file.Name));
This is the code that inserts one into the ListView:
images.Images.Add(picto.Image);
ListViewItem item = new ListViewItem(picto.Name, images.Images.Count-1);
item.Tag = picto;
pictoView.Items.Add(item);
What am I doing wrong here?
Thanks!