471,049 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,049 software developers and data experts.

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:


The new files should looks like d:\\........radar0000001.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:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Drawing;
  8. namespace Format_Files
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Bitmap[] mybitmaps;
  15.             Image myimage;
  16.             string c;
  17.             string s;
  18.             StreamWriter sw;
  19.             string sf;
  20.             string[] images;
  21.             int x;
  22.             int a;
  23.             int b;
  24.             sw = new StreamWriter(@"d:\stream.txt");
  25.             sf = @"d:\RadarImagesDownloaded";
  26.             images = Directory.GetFiles(sf, "*.jpg");
  28.             Console.WriteLine("--- Files: ---");
  29.             myimage = new Bitmap(512, 512);
  31.             for (x = 0; x < images.Length; x++)
  32.             {
  34.                 s = images[x];
  35.                 int i = s.IndexOf("radar");
  36.                 int t = s.IndexOf(".jpg");
  37.                 string d = s.Substring(i+5,s.Length-t - 1);
  38.                 int numbers = Convert.ToInt32(d);
  39.                 c = sf + @"\radar" + numbers.ToString("D6") + ".jpg";
  40.                 myimage.Save(c);
  41.                 Console.WriteLine("index: "+x+"  filename:"+images[x]);
  43.                 sw.WriteLine("index: "+x+" Substring:"+ d + " Converted numbers: " + numbers + " New fileNames: " + c);
  44.                 if ((x % 500) == 0) // just to help us see the printing on the screen.. cause it is too fast..so 
  45.                 // "pausing" every 500 .. (wait for user press )
  46.                 {
  47.                     Console.WriteLine(" just pausing so user can see.. : press any key to continue ...");
  48.                     Console.ReadKey(false);
  49.                 }
  50.             }
  51.             sw.Close();
  54.         }
  55.     }
  56. }
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.getpixel(a,b);

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

Apr 25 '11 #1
2 2957
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:\......radar001.jpg so now it will be d:\......radar000001.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.ToString("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!
Apr 25 '11 #2
1,501 Expert 1GB
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?
Apr 27 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Markus Bulmer | last post: by
20 posts views Thread by Crirus | last post: by
3 posts views Thread by Kentor | last post: by
3 posts views Thread by Jason B | last post: by
2 posts views Thread by lawpoop | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.