0

So I created a program that load 100 pictures onto the screen, each picture basically represents an object, and let the user pick which one they want.

The problem is the app isnt able to load 100 images without leaving a ton of red x's in my pictureboxes.

How can I reduce the amount of memory each picture requires?

enter image description here

EDIT: The images are not actually plain black, I just have not played with the Image scale yet to show what I want. The image sizes are actually 4288 x 2848. I dont need that on this screen, a small scale image will work.

This is for an auction display. So essentially the image you see here is a thumbnail, and will take you to the page of the auction item.

CODE: Using infragistics/WPF

        foreach (var item in Vehicles)
        {
            BitmapImage b = new BitmapImage();
            b.BeginInit();
            b.UriSource = new Uri(item.OverviewImage);
            b.EndInit();

          var addTile = new XamTile
          {
              Content = new Image { Source = b}
          };

          tileManager.Items.Add(addTile);
        }

Other code I tried, not using infragistics/C#

   public List<Vehicle> Vehicles { get; set; }
    private int count = 0;

    public AuctionScreen()
    {
        InitializeComponent();

        Vehicles = new List<Vehicle>();
    }

    private void AuctionScreen_Load(object sender, EventArgs e)
    {
        timer1.Start();
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
            var m = new PictureBox();
            m.ImageLocation = Vehicles[count].OverviewImage;

            flowLayoutPanel1.Controls.Add(m);
            if (count > Vehicles.Count)
            {
                timer1.Stop();
            }
    }
DidIReallyWriteThat
  • 1,033
  • 1
  • 10
  • 39
  • What's the size of each image? Are they really black (or is this just a privacy issue)? – Thomas Ayoub Sep 25 '15 at 13:07
  • 2
    I'd nudge toward scaling: https://msdn.microsoft.com/en-us/library/7wt4bf7h%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396 – Nebula Sep 25 '15 at 13:09
  • post your code please –  Sep 25 '15 at 13:09
  • 4
    If your question genuinely is _"How can I display 100 images of 12 Megapixels each in one form"_, you may want to reconsider your approach. Load the pictures one by one, scale them down appropriately and then render them onto some canvas (you really don't want 100 pictureboxes on one form). This is not trivial, will perform badly and the question is too broad, try doing some research. – CodeCaster Sep 25 '15 at 13:18
  • @CodeCaster I have done research, and for you to say I have not is frustrating. Ive been working on this for 2 days and finally posted a question here hoping for help, not a comment saying do more research. I obviously don't know enough about how images are rendered, and can't put everything together into a cohesive solution. "This is not trivial".. if it was, I wouldn't be here. – DidIReallyWriteThat Sep 25 '15 at 13:24
  • I don't mean anything by that, your research simply does not show from your question. Giving you a complete answer would be way too long, you need to break up your question in smaller parts. – CodeCaster Sep 25 '15 at 13:25
  • @CodeCaster My question was never "How can I display 100 images of 12 Megapixels each in one form". My question has always been "How can I reduce the amount of memory each picture requires?" – DidIReallyWriteThat Sep 25 '15 at 13:28
  • Well if you search for _that_, you'll find http://stackoverflow.com/questions/7153864/c-how-to-reduce-memory-and-cpu-consumption-when-working-with-bitmaps ("dispose them"), http://stackoverflow.com/questions/16495638/show-a-lot-of-images-with-really-low-memory-using-in-c ("scale them"), and so on. :) – CodeCaster Sep 25 '15 at 13:30

1 Answers1

0

You are probably going to want to draw all of your images onto a single canvas in order to reduce the CPU and RAM overhead of displaying so many pictureboxes

I'd look at this question. How to render bitmap into canvas in WPF? Here they are talking about drawing an image onto a canvas, you should be able to draw multiple images onto one canvas, by specifying the rectangle when you create them.

If you need these clickable then simply listen for the onClick event of the canvas and get the image you need by the mouse position.

Community
  • 1
  • 1
Lex Webb
  • 2,772
  • 2
  • 21
  • 36