H
halise
Hi,
i am in trouble with an exception in .net platform with c#.
The exception thrown is exactly as follows:
System.ArgumentException: Invalid parameter used.
at System.Drawing.Bitmap.SetPixel(Int32 x, Int32 y, Color color)
at binaryData2Image.Form1.button_Click(Object sender, EventArgs e)
in c:\documents and settings\..\my documents\visual studio
projects\binarydata2image\form1.cs:line 237
my code is something like that
// Create a bitmap to set the binary data as pixel data
// Bit depth is 16bits per pixel
Bitmap bmp = new Bitmap (256, 256,
System.Drawing.Imaging.PixelFormat.Format16bppRgb565 );
// Created for reading binary data and extracting color values
BinaryReader br_img = new BinaryReader(File.OpenRead("C:/Documents and
Settings/../SE1/IM1bdata2im"));
try
{
for(int y=1; y<256; ++y)
{
for(int x=1; x<256; ++x)
{
ushort pix = br_img.ReadUInt16();
//* For PixelFormat.Format16bppRgb565
int red = (int)( pix & 0xF800 ) >> 11 ; //takes the
first 5 most significant bits
int green = (int) ( pix & 0x07E0 ) >> 5
;//takes the bits from 6th to 12th
int blue = (int)( pix & 0x001F ) ;//takes the last 5 least
significant bits
bmp.SetPixel(x, y, Color.FromArgb(red, green, blue ) ) ;
}
}
}
catch( Exception exc )
{
textbox0.Text = exc.ToString();
}
br_img.Close();
picturebox.BackgroundImage = bmp;
I cant find why this exception is thrown, because everyhing seems very
reasonable to me.
Besides, when i used PixelFormat.FormatGrayScale, I got the same
problem with SetPixel method too.
please, can anyone help me?
thanks, in advance!
halise
i am in trouble with an exception in .net platform with c#.
The exception thrown is exactly as follows:
System.ArgumentException: Invalid parameter used.
at System.Drawing.Bitmap.SetPixel(Int32 x, Int32 y, Color color)
at binaryData2Image.Form1.button_Click(Object sender, EventArgs e)
in c:\documents and settings\..\my documents\visual studio
projects\binarydata2image\form1.cs:line 237
my code is something like that
// Create a bitmap to set the binary data as pixel data
// Bit depth is 16bits per pixel
Bitmap bmp = new Bitmap (256, 256,
System.Drawing.Imaging.PixelFormat.Format16bppRgb565 );
// Created for reading binary data and extracting color values
BinaryReader br_img = new BinaryReader(File.OpenRead("C:/Documents and
Settings/../SE1/IM1bdata2im"));
try
{
for(int y=1; y<256; ++y)
{
for(int x=1; x<256; ++x)
{
ushort pix = br_img.ReadUInt16();
//* For PixelFormat.Format16bppRgb565
int red = (int)( pix & 0xF800 ) >> 11 ; //takes the
first 5 most significant bits
int green = (int) ( pix & 0x07E0 ) >> 5
;//takes the bits from 6th to 12th
int blue = (int)( pix & 0x001F ) ;//takes the last 5 least
significant bits
bmp.SetPixel(x, y, Color.FromArgb(red, green, blue ) ) ;
}
}
}
catch( Exception exc )
{
textbox0.Text = exc.ToString();
}
br_img.Close();
picturebox.BackgroundImage = bmp;
I cant find why this exception is thrown, because everyhing seems very
reasonable to me.
Besides, when i used PixelFormat.FormatGrayScale, I got the same
problem with SetPixel method too.
please, can anyone help me?
thanks, in advance!
halise