473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

ArgumentException: Invalid parameter used at Bitmap.SetPixel

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.Format16bppRgb5 65 );

// 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
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 16 '05 #1
3 9332
Hi Halise,

I see nothing wrong with this code. Could you post the actual code you
use?

Do you get the same problem using other PixelFormats?

Btw, it appears you are creating a bitmap from raw data which will benefit
hugely from using LockBits in unsafe mode (~90% time cut compared to
SetPixel)

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2
hi, i still cant decide whether i can use LockBits or not in my case,
that is creating a bitmap from my binary data rather than processing
the pixel data of the bitmap.

what dou you think about that? can you clearify more?

thanks,

halise.

Morten Wennevikwrote: Hi Halise,
I see nothing wrong with this code. Could you post the actual code you use?

Do you get the same problem using other PixelFormats?

Btw, it appears you are creating a bitmap from raw data which will benefit hugely from using LockBits in unsafe mode (~90% time cut compared to SetPixel)

--
Happy Coding!
Morten Wennevik [C# MVP][/quote:1b6849140c]

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 16 '05 #3
Add using System.Text;
then error
An unhandled exception of type 'System.IO.DirectoryNotFoundException'
occurred in mscorlib.dll

Additional information: DirectoryNotFoundException
"halise" <ha********@yahoo-dot-com.no-spam.invalid> wrote in message
news:42********@127.0.0.1...
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.Format16bppRgb5 65 );

// 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
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Wally | last post by:
I am trying to display images from an Access 2000 database and I get an error "Invalid Parameter Used" when I execute the code line "picBLOB.Image = Image.FromStream(stmBLOBData)" in my Visual...
1
by: halise irak via .NET 247 | last post by:
I get an "ArgumentException: Invalid parameter used at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement)" exception. it is too ridicilious to get such an...
5
by: Jeroen Ceuppens | last post by:
I have the colormap (ARGB, 8bit , so every color from 0 to 255) , put it in an array (1dim) I have the pixel date (array 640x480) What is the best way to make with these array's a bitmap file?...
1
by: James Dean | last post by:
I get the following message when i try to set a pixel in the bitmap.......whats wrong and how can i fix it....... "Additional information: SetPixel is not supported for images with indexed pixel...
8
by: iyuen | last post by:
I'm having problems with converting a byte array to an image object~ My byte array is an picture in VB6 StdPicture format. I've used propertybag to convert the picture into base64Array format in...
0
by: CroDude | last post by:
Hi all! I have problems when writting bitmap to a byte array and after reading it back form byte to Bitmap object. What I do is this: First I throw Bitmap to a memory-stream and then I write it...
18
by: Atara | last post by:
In my apllication I use the following code: '-- My Code: Public Shared Function strDate2Date(ByVal strDate As String) As System.DateTime Dim isOk As Boolean = False If (strDate Is Nothing)...
6
by: ProtossLee | last post by:
Hi, I am currently working on a project for image processing. a double matrix m1(1300X1000) need to be converted into bitmap and displayed on screen. so far I've made the following code: For i...
2
by: Steve Richter | last post by:
using SetPixel to set all the pixels of a bitmap to Color.Red. Problem is the bitmap displays as Color.Turqoise. if all the pixels of the bitmap are Red, why does it not display as Red? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.