How to get pixel from array of jpeg files ? Cant figure out

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chocolade
    New Member
    • Aug 2010
    • 69

    How to get pixel from array of jpeg files ? Cant figure out

    I have a console application project wich inside im creating array of jpg files from a directory and then im formating the files and make new files and i want to reneame/move/copy the new files with the old ones.

    Since the old files are jpg i want first read all the files pixels get the colors of them and set it back to the new files i created wich have also diffrenet format.

    For example in my program original file looks like:

    d:\\.........ra dar001.jpg

    The new files should looks like d:\\........rad ar0000001.jpg

    I just formatted the new files to be with 6 zeros iside so file radar001 will be radar000001.jpg and file radar350.jpg will be radar000350.jpg

    Then i converted it to int32

    Now i also created in the loop new 3200+ bitmaps empty files black bitmaps files.

    Now i want to getpixel of the old files set in the new bitmaps i created the pixels and then delete the old files.


    This is the code:

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Drawing;
    
    namespace Format_Files
    {
        class Program
        {
            static void Main(string[] args)
            {
                Bitmap[] mybitmaps;
                Image myimage;
                string c;
                string s;
                StreamWriter sw;
                string sf;
                string[] images;
                int x;
                int a;
                int b;
                sw = new StreamWriter(@"d:\stream.txt");
                sf = @"d:\RadarImagesDownloaded";
                images = Directory.GetFiles(sf, "*.jpg");
     
                Console.WriteLine("--- Files: ---");
                myimage = new Bitmap(512, 512);
    
                for (x = 0; x < images.Length; x++)
                {
    
                    s = images[x];
                    int i = s.IndexOf("radar");
                    int t = s.IndexOf(".jpg");
                    string d = s.Substring(i+5,s.Length-t - 1);
                    int numbers = Convert.ToInt32(d);
                    c = sf + @"\radar" + numbers.ToString("D6") + ".jpg";
                    myimage.Save(c);
                    Console.WriteLine("index: "+x+"  filename:"+images[x]);
    
                    sw.WriteLine("index: "+x+" Substring:"+ d + " Converted numbers: " + numbers + " New fileNames: " + c);
                    if ((x % 500) == 0) // just to help us see the printing on the screen.. cause it is too fast..so 
                    // "pausing" every 500 .. (wait for user press )
                    {
                        Console.WriteLine(" just pausing so user can see.. : press any key to continue ...");
                        Console.ReadKey(false);
                    }
                }
                sw.Close();
    
               
            }
        }
    }
    Now c string c wontaining the new files names how they should be. So i created with myimage.Save(c) ; the new files.

    Now i want to make new two for's for inside for using a and b get all the pixels from the old jpg files and set the pixels into the new files wich are myimage

    I know how to do it with one image you make for in for like:

    for (a=0;a<newimage .width;a++)
    {
    for (b=0;b<newimage .height;b++)
    {
    Color mc = newimage.getpix el(a,b);
    mynewimage.setp ixel(a,b,mc);
    }
    }


    Something like that.
    Now how do i make it with array of jpg files ? According to my code.


    Thanks.
  • Chocolade
    New Member
    • Aug 2010
    • 69

    #2
    The original idea is to rename the original files to new names. Keep the files same content just rename them. So maybe i dont need to create new bitmap files and all the stuff.

    Since in string C i have the new file names how can i rename now the old files ? So if file number one was d:\......radar0 01.jpg so now it will be d:\......radar0 00001.jpg
    So all i need is somehow to rename the files names.

    I tried to use in my code after the c = sf + @"\radar" + numbers.ToStrin g("D6") + ".jpg";

    I added File.Move(c, s);
    But im getting error say he cant find the files on hard disk the files c containing but i dont the files i just want to change the original files names rename them!

    Comment

    • GaryTexmo
      Recognized Expert Top Contributor
      • Jul 2009
      • 1501

      #3
      Out of curiosity, why do you need to copy the pixels? Can't you just use the Save method on the Bitmap class to save a copy in a new format?

      As for how to go through each file in the list, I'm not sure what you mean. You're already processing each file (Line 31 and 34 above) but then you hard code the name into it. Just work on the file you get in your loop?

      Comment

      Working...