472,960 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,960 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:

d:\\.........radar001.jpg

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;
  7.  
  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");
  27.  
  28.             Console.WriteLine("--- Files: ---");
  29.             myimage = new Bitmap(512, 512);
  30.  
  31.             for (x = 0; x < images.Length; x++)
  32.             {
  33.  
  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]);
  42.  
  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();
  52.  
  53.  
  54.         }
  55.     }
  56. }
  57.  
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);
mynewimage.setpixel(a,b,mc);
}
}


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


Thanks.
Apr 25 '11 #1
2 3158
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
GaryTexmo
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

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

Similar topics

0
by: Markus Bulmer | last post by:
Hi, I'm trying to do a photo album with php. The admins should be able to write comments, descriptions etc. into the jpeg files via a web form. I tried to implement this with the (still...
20
by: Crirus | last post by:
I have a 20x16 array of objects. I need a way to iterate through the array and only consider few rows and few columns. To be clearer, sometimes I need only first 2 rows and last 3 columns to be...
3
by: Kentor | last post by:
hello, im trying to make a little loop, but i cant figure it out... i have a string with a bunch of 1s and 0s in it: 110101010101111010101 .... i need to count the number of 1s divide it by 2 and...
1
by: janaki112 | last post by:
my 1 dimensional pixel array is named => intensity (got by using pixel grabber) I have created an image using Code: Container n=new Container(); Image img=n.createImage(new...
3
by: Jason B | last post by:
Hi all, I'm somewhat new to Python and I'm trying to figure out the best way to accomplish the following: From an array of pixel data in an XML file (given the format, width and height of the...
2
by: lawpoop | last post by:
Hello folks - I'm working on a function to map a php project that's gotten a little unwieldly. I'd like to have a reference of all files like the output of the unix tree command, like this: .....
7
by: griffinheart | last post by:
hey there this script works fine in firefox. but in ie the this call document.getElementById(form).style.display='block'; gives me object required, well i don't know much about java and can't...
5
by: chevon1920 | last post by:
I am trying to do my assignment but I cant figure out how to get 8 data points per line to print to a file. Here is the assignment 1. Program asks the user to enter an odd number as a BASE,...
4
by: cagdasal | last post by:
Hello there, i am having the following problem, when i read an image the following way: public void readBitmapImage (String imagePath){ ImageDir = imagePath; //Read in the image file...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.