Best way of displaying images
-
Thursday, August 28, 2008 2:33 PMHi all,
I have a custom image collection with images of different sizes and am trying to find the best way to display them to the user.
I have tried using a panel and just creating picture boxes for each one with the individual sizes, the trouble is it looks awful.
The second way was to use a list view but as you can only use one image list for the entire list view the images all come out the same size and some are stretched and others crushed.
My question is has anyone used any other controls that will allow different sized images to be displayed in a neat and organised way.
Thanks
All Replies
-
Wednesday, September 03, 2008 8:44 AM
molemenacer said:
I have a custom image collection with images of different sizes and am trying to find the best way to display them to the user.
My question is has anyone used any other controls that will allow different sized images to be displayed in a neat and organised way.
Hi molemenacer,
Here is one idea:
Place several PictureBox controls with same size on your form, and resize each image (with different size) based on original scale in order to accord with PictureBox size (Width is in priority), then display them on each PictureBox controls. That looks neat and organised. Please take it a try with the following code sample.Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load PictureBox1.Image = Image.FromFile("D:\VBproject\3.GIF") PictureBox2.Image = Image.FromFile("D:\VBproject\1.jpg") End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click resizeImage("D:\VBproject\3.GIF", PictureBox1) resizeImage("D:\VBproject\1.jpg", PictureBox2) End Sub Public Sub resizeImage(ByVal imgPath As String, ByVal picbox As PictureBox) ' Get the source bitmap Dim bm_source As Bitmap = New Bitmap(imgPath) ' Record the scale of source bitmap Dim scale As Double = bm_source.Height / bm_source.Width ' Make a new bitmap Dim bm_dest As New Bitmap(CInt(picbox.Width), CInt(picbox.Width * scale)) ' Make a Graphics object for the new Bitmap. Dim gr_dest As Graphics = Graphics.FromImage(bm_dest) ' Copy the source image into the destination bitmap gr_dest.DrawImage(bm_source, 0, 0, bm_dest.Width + 1, bm_dest.Height + 1) ' Display the new bitmap in PictureBox picbox.Image = bm_dest End Sub End Class
Best regards,
Martin Xie- Marked As Answer by Martin Xie - MSFT Wednesday, September 03, 2008 8:45 AM

