• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3686
  • Last Modified:

display multiple images on a windows form in C#

Hi,

If I have to load a few images (lets say from 5 to 10) on a windows form from database, whats the best way to do it? use dynamically generated pictureboxes? I should be able to drag images around, something like google picasa...  I can load them to an imageList but I'm trying to get more ideas about displaying them..

Has anyone done anything similar?

0
prajeebkumar
Asked:
prajeebkumar
  • 6
  • 6
1 Solution
 
Bob LearnedCommented:
Here is a class to convert between a byte array and images:

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

public class MemoryImage
{

  public Image ByteArrayToImage(byte[] buffer, string fileName)
  {
    MemoryStream ms = new MemoryStream(buffer);
    Image img = Image.FromStream(ms);
    return img;
  }

  public byte[] ImageToByteArray(Image img, ImageFormat format)
  {
    MemoryStream ms = new MemoryStream();
    img.Save(ms, format);
    return ms.ToArray();
  }
}

Bob
0
 
prajeebkumarAuthor Commented:
Hi,

thank you for the reply. But I'm actually looking for suggestions on how to display the images on the form, like google picasa may be.. assume I have an image array that contains images.. now what is the best way to load them on the windows form, using picture boxes or something else?  i'm not very familiar with windows programming, so if thats what you mentioned above, plz explain a little more.
0
 
Bob LearnedCommented:
I haven't used Picasa, so how does it display the images?  You can easily use PictureBox controls to display images.

Bob
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
prajeebkumarAuthor Commented:
I'm not sure how picasa display the images on the panel.. they have lot of images arranged side by side which you can move around on form..  i know I can use picture boxes to display images but i'm wondering if thats the best way. I wouldn't know how many images are there beforehand so I have to programatically create pictureboxes on the fly.. also, is that the only control that can be used to display images on windows forms?  

btw, if you have lot of photo albums on your pc, you should probably download picasa, its free and really nice to arrange albums, just fyi!
0
 
Bob LearnedCommented:
If you want to tile images across a page, then you could do something like this.

int x = 20;
int y = 20;
int maxHeight = -1

foreach (Image img in this.ImageCollection)
{
   PictureBox pic = new PictureBox();
   pic.Image = img;
   pic.Location = new Point(x, y);

   x += pic.Width + 10;
   maxHeight = Math.Max(pic.Height, maxHeight);

   if (x > this.ClientSize.Width - 100)
   {
      x = 20;
      y += maxHeight + 10;
   }
}

Bob
0
 
prajeebkumarAuthor Commented:
Hi,

thats a nice suggestion. Please go to the following question and post a reply so I can assign points to you for that.
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21817805.html

I would still like to keep this question open to see if anybody else has any other ideas. I'm surprised picture box is the only control you can display images on windows programming.
0
 
Bob LearnedCommented:
Points for questions are not allowed anymore.  You can display images in other controls, but it is a bit more difficult.  

Bob
0
 
prajeebkumarAuthor Commented:
you mean, i cannot create another question to assign points to you?
0
 
Bob LearnedCommented:
Nope.  It against the membership guidelines to create a condition where the points go above 500.  I don't need the points anyway.

Let's get this question answered.

Bob
0
 
prajeebkumarAuthor Commented:
ok, I created another question for you anyway. If you would like, I can assign you points if you reply to this question,
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21817805.html  .. you just need to post something so I can assign points, its upto you.

Thank you for your help, I'm just keeping it open just to see if someone has another idea. I will try your solution first and see if that achieves what I need to do.

0
 
Bob LearnedCommented:
1) You can add images to an ImageList control, and then display them in a ListView control.

2) If a control has a Paint event, such as a Panel, you can always use GDI+ to draw an image on the control.

Bob
0
 
prajeebkumarAuthor Commented:
do you have a sample code for the second idea you mentioned? drawing image on a panel? if not, dont worry about it, I'll look it up..

thanks for your suggestions. I guess I'm going to assign the points to you for all your help. I could be back if I need more help.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now