On a treeview after the select event, I populate a listview with images.
I want to custom format these images and place a black color border around each image.
I would add a border using a Graphics
object immediately after loading the images from file:
EDIT: modified the code, this works for me...
private void TreeView1_Select(object sender, EventArgs e) {
if (folder != null && System.IO.Directory.Exists(folder)) {
DirectoryInfo dir = new DirectoryInfo(@folder);
foreach (FileInfo file in dir.GetFiles()) {
Image img = new Bitmap(Image.FromFile(file.FullName));
using (Graphics g = Graphics.FromImage(img)){
g.DrawRectangle(Pens.Black, 0, 0, img.Width - 2, img.Height - 2);
}
imageList.Images.Add(img);
NOTE: the image copying is intended; if I modify the code to
Image img = (Bitmap)Bitmap.FromFile("test.bmp");
as suggested in the comments, I get an exception saying "A Graphics object cannot be created from an image that has an indexed pixel format."