Hello
Need a little help, I'm not advenced programmer.
What i need to do is write and read bmp data to text files without getting inside into bmp file format structrue.
First function of program is reading bmp file through openfile dialog and writing pixel data as greyscale values into tex files.
As You can see its writing greyscale "k" value to text file for each pixel separated by " ".
Now i need to read pixel data and create bmp file in memory and write it with changed extension.
Tried to do it with binary/text reading but no efefcts. Now i have concept to read whole file data as string and create int array from it.
CODE
for (i = 0; i < openFileDialog1.FileNames.Length; i++)
{
progressBar1.Value++;
this.Refresh();
string newFile;
//newFile = openFileDialog1.FileNames[i].ToString();
System.Drawing.Bitmap image = new System.Drawing.Bitmap(512, 512);
newFile = Path.GetDirectoryName(openFileDialog1.FileNames[i]) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(openFileDialog1.FileNames[i]) + ".bmp";
FileStream br;
br = new FileStream(openFileDialog1.FileNames[i], FileMode.Open);
string PixelData = ReadToEnd();
/* Something to Parse string PixelData into arary
List<int> numbers = new List<int>();
Numbers.Add( new List<int>( Array.ConvertAll<string, int>( PixelData.Split( ' ' ), new Converter<string, int>( int.Parse ) ) ) );
this dont work
*/
for (int x = 0; x < image.Width; ++x)
{
for (int y = 0; y < image.Height; ++y)
{
// set k value from arary[]
image.SetPixel(x, y, Color.FromArgb(255,k,k,k));
}
}
image.Save(newFile);
br.Close();
}
Dunno how to change string into array of integers.
All bmp files that im working with are same size 512x512 so always there will be 262144 Integers separated with " ".
Thanks for Your time in Advance.
All the best krs.
This post has been edited by krszc6: 4 Jul, 2009 - 01:59 PM