Click here to Skip to main content
15,561,685 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello everyone!

First if of all, I would like to say thank you to everyone who for being so cooperative. I've asked for help twice and I have received helped twice so thank you.

Second all, my question. I'm working on an image processing program. In this program, I can select multiple images. Also, I added some image processing tools like brightness and contrast. Now, here's the problem. For example, when I open say 4 images at once and then change the brightness of the first picture, it works fine. But, then when I go to the second picture and then change it's brightness, the picture changes completely to the first picture and then the brightness of the first picture is adjusted again but in the second picture's position and then the same thing happens to the rest of the pictures. it's like if I choose 6 multiple images, all 6 images are named as the first selected image. So maybe that's why when I adjust other images they changed to the first image.

Here's the code I'm using for opening multiple images:
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
.......
.......

namespace Filters
{
    public partial class Form1 : Form
         
    {
        private static int imageCount;
        private static int totalImageCount;
...........
...........
..........


    private void openToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            try
            {
                open.Multiselect = true;
                open.Filter = "Image Files (*.tif; *.dcm; *.jpg; *.jpeg)|*.tif; *.dcm; *.jpg; *.jpeg";

                if (open.ShowDialog() == DialogResult.OK)
                {
                    int i = 0;
                    totalImageCount = open.FileNames.Length;
                    images = new Image[totalImageCount];
                    foreach (String file in open.FileNames)
                    {
                        images[i] = Image.FromFile(file);
                        i++;
                    }
                    picShowPicture.Image = images[imageCount];
                    if (totalImageCount > 0)
                    {
                        nextBtn.Enabled = true;
                        open.CheckFileExists = true;
                        open.CheckPathExists = true;
                    }

                    imageOfTxt.Text = "Image 1 of " + totalImageCount;
                }
            }
            catch (Exception)
            {
                throw new ApplicationException("Failed loading image");
            }
            myImage = (Bitmap)picShowPicture.Image;
            newBitmap = new Bitmap(open.FileName);
        }


So is it possible that we can select multiple images and have each image to be treated as a picture of its own without taking another image's name or like the example I gave you?

Thank you everyone :D
Posted
Comments
Sergey Alexandrovich Kryukov 4-Sep-11 21:58pm    
Essential part of code is not shown. For example, where imageCount is assigned? picShowPicture.Image = images[imageCount] looks like a bug, otherwise imageCount is not a count -- indexing is zero-based. Generally, code looks pretty bad, not wonder you messed up. Why to fields are static? -- makes no sense.
Anyway, it's not shown how one image becomes another one, as adjustment code is not shown.
--SA

1 solution

Hi,

Well I expect you have messed up a little in your coding. The code you have does successfully load all you Image into an array. I expect your error is coming from not saving the changed image back into this array. I've added three button two your code so I could effectively check your code. Two I know you already have which cycle through your images[n] array.

C#
private void nextBtn_Click(object sender, EventArgs e)
{
    if (images.Length - 1 > imageCount)
    {
        imageCount++;
        pictureBox1.Image = images[imageCount];
    }
    this.Refresh();
}


private void PrevBtn_Click(object sender, EventArgs e)
{
    if (imageCount > 0)
    {
        imageCount--;
        pictureBox1.Image = images[imageCount];
    }
    this.Refresh();
}


Now I added a third in this case all I did was change the image effect into a grayscale one. Here you would have your code to adjust brightness etc.

C#
private void Grey_BTN_Click(object sender, EventArgs e)
{
   Bitmap myImage = (Bitmap)pictureBox1.Image;

   for (int y = 0; y < myImage.Height; y++)
   {
       for (int x = 0; x < myImage.Width; x++)
       {
            Color c = myImage.GetPixel(x, y);
            int luma = (int)(c.R * 0.3 + c.G * 0.59 + c.B * 0.11);
            myImage.SetPixel(x, y, Color.FromArgb(luma, luma, luma));
       }
   }
    
   //Here is the important bit of storing your changes
   images[imageCount] = myImage; 
   pictureBox1.Image = images[imageCount];
   this.refresh();
}


I hope this helps
Let me know if you need more assistant, and if you need mor advanced image processing features then I suggest EMGU a C# wrapper for the OpenCV image processing library.

Take Care
Chris
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900