Load image from stream

  • Thread starter Thread starter Guest
  • Start date Start date
New Bitmap(myStream)
This assumes the stream contains everything, including file header, not just
raw data
 
my code :

byte[] AImagem = ((byte[])dtr.GetValue(2));
MemoryStream AStream = new MemoryStream(AImagem);
pictureBox1.Image = new Bitmap(AStream);

The code generate a except (ArgumentException).

Rogerio
 
My code is generate a exception(ARGUMENTEXCEPTION).

Code:
byte[] AImagem = ((byte[])dtr.GetValue(2));
MemoryStream AStream = new MemoryStream(AImagem);
pictureBox1.Image = new Bitmap(AStream); <- this line generate a exception.

Rogerio
 
Most likely it's because your stream is not a bitmap. Change your code to
this to track it down further:

byte[] AImagem = ((byte[])dtr.GetValue(2));
MemoryStream AStream = new MemoryStream(AImagem);
Bitmap b = new Bitmap(AStream);
pictureBox1.Image = b;

--
Mark Arteaga
..NET Compact Framework MVP
http://www.neotericsdc.com | http://blog.markarteaga.com



Rogerio Jun said:
My code is generate a exception(ARGUMENTEXCEPTION).

Code:
byte[] AImagem = ((byte[])dtr.GetValue(2));
MemoryStream AStream = new MemoryStream(AImagem);
pictureBox1.Image = new Bitmap(AStream); <- this line generate a
exception.

Rogerio




Alex Feinman said:
New Bitmap(myStream)
This assumes the stream contains everything, including file header, not
just
raw data
 
The error persist.

Rogerio

Mark Arteaga said:
Most likely it's because your stream is not a bitmap. Change your code to
this to track it down further:

byte[] AImagem = ((byte[])dtr.GetValue(2));
MemoryStream AStream = new MemoryStream(AImagem);
Bitmap b = new Bitmap(AStream);
pictureBox1.Image = b;

--
Mark Arteaga
..NET Compact Framework MVP
http://www.neotericsdc.com | http://blog.markarteaga.com



Rogerio Jun said:
My code is generate a exception(ARGUMENTEXCEPTION).

Code:
byte[] AImagem = ((byte[])dtr.GetValue(2));
MemoryStream AStream = new MemoryStream(AImagem);
pictureBox1.Image = new Bitmap(AStream); <- this line generate a
exception.

Rogerio




Alex Feinman said:
New Bitmap(myStream)
This assumes the stream contains everything, including file header, not
just
raw data

--
Alex Feinman
---
Visit http://www.opennetcf.org
How can I load a image from MemoryStream ?

Rogerio
 
It was suggested just that you would know what causes the exception. Ok,
tell us what values have the first two bytes of the AImagem array:

byte[] AImagem = ((byte[])dtr.GetValue(2));

It should be:

0 - 0x42
1 - 0x4D

is it?

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Rogerio said:
The error persist.

Rogerio

Most likely it's because your stream is not a bitmap. Change your code to
this to track it down further:

byte[] AImagem = ((byte[])dtr.GetValue(2));
MemoryStream AStream = new MemoryStream(AImagem);
Bitmap b = new Bitmap(AStream);
pictureBox1.Image = b;

--
Mark Arteaga
..NET Compact Framework MVP
http://www.neotericsdc.com | http://blog.markarteaga.com



My code is generate a exception(ARGUMENTEXCEPTION).

Code:
byte[] AImagem = ((byte[])dtr.GetValue(2));
MemoryStream AStream = new MemoryStream(AImagem);
pictureBox1.Image = new Bitmap(AStream); <- this line generate a
exception.

Rogerio




:


New Bitmap(myStream)
This assumes the stream contains everything, including file header, not
just
raw data

--
Alex Feinman
---
Visit http://www.opennetcf.org

How can I load a image from MemoryStream ?

Rogerio
 
Values are 0x42 and 0x4D.

Rogerio

Sergey Bogdanov said:
It was suggested just that you would know what causes the exception. Ok,
tell us what values have the first two bytes of the AImagem array:

byte[] AImagem = ((byte[])dtr.GetValue(2));

It should be:

0 - 0x42
1 - 0x4D

is it?

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Rogerio said:
The error persist.

Rogerio

Most likely it's because your stream is not a bitmap. Change your code to
this to track it down further:

byte[] AImagem = ((byte[])dtr.GetValue(2));
MemoryStream AStream = new MemoryStream(AImagem);
Bitmap b = new Bitmap(AStream);
pictureBox1.Image = b;

--
Mark Arteaga
..NET Compact Framework MVP
http://www.neotericsdc.com | http://blog.markarteaga.com




My code is generate a exception(ARGUMENTEXCEPTION).

Code:
byte[] AImagem = ((byte[])dtr.GetValue(2));
MemoryStream AStream = new MemoryStream(AImagem);
pictureBox1.Image = new Bitmap(AStream); <- this line generate a
exception.

Rogerio




:


New Bitmap(myStream)
This assumes the stream contains everything, including file header, not
just
raw data

--
Alex Feinman
---
Visit http://www.opennetcf.org

How can I load a image from MemoryStream ?

Rogerio
 
Okey, try to save this image into disk and using some image viewer make
sure that this image is not corrupted.

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Rogerio said:
Values are 0x42 and 0x4D.

Rogerio

:

It was suggested just that you would know what causes the exception. Ok,
tell us what values have the first two bytes of the AImagem array:

byte[] AImagem = ((byte[])dtr.GetValue(2));

It should be:

0 - 0x42
1 - 0x4D

is it?

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Rogerio said:
The error persist.

Rogerio

:



Most likely it's because your stream is not a bitmap. Change your code to
this to track it down further:

byte[] AImagem = ((byte[])dtr.GetValue(2));
MemoryStream AStream = new MemoryStream(AImagem);
Bitmap b = new Bitmap(AStream);
pictureBox1.Image = b;

--
Mark Arteaga
..NET Compact Framework MVP
http://www.neotericsdc.com | http://blog.markarteaga.com





My code is generate a exception(ARGUMENTEXCEPTION).

Code:
byte[] AImagem = ((byte[])dtr.GetValue(2));
MemoryStream AStream = new MemoryStream(AImagem);
pictureBox1.Image = new Bitmap(AStream); <- this line generate a
exception.

Rogerio




:



New Bitmap(myStream)
This assumes the stream contains everything, including file header, not
just
raw data

--
Alex Feinman
---
Visit http://www.opennetcf.org


How can I load a image from MemoryStream ?

Rogerio
 
I do this. In "Full Framework" the code is ok, but in Compact Framework a
exception is generate.

Rogerio

Sergey Bogdanov said:
Okey, try to save this image into disk and using some image viewer make
sure that this image is not corrupted.

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Rogerio said:
Values are 0x42 and 0x4D.

Rogerio

:

It was suggested just that you would know what causes the exception. Ok,
tell us what values have the first two bytes of the AImagem array:

byte[] AImagem = ((byte[])dtr.GetValue(2));

It should be:

0 - 0x42
1 - 0x4D

is it?

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Rogerio Jun wrote:

The error persist.

Rogerio

:



Most likely it's because your stream is not a bitmap. Change your code to
this to track it down further:

byte[] AImagem = ((byte[])dtr.GetValue(2));
MemoryStream AStream = new MemoryStream(AImagem);
Bitmap b = new Bitmap(AStream);
pictureBox1.Image = b;

--
Mark Arteaga
..NET Compact Framework MVP
http://www.neotericsdc.com | http://blog.markarteaga.com





My code is generate a exception(ARGUMENTEXCEPTION).

Code:
byte[] AImagem = ((byte[])dtr.GetValue(2));
MemoryStream AStream = new MemoryStream(AImagem);
pictureBox1.Image = new Bitmap(AStream); <- this line generate a
exception.

Rogerio




:



New Bitmap(myStream)
This assumes the stream contains everything, including file header, not
just
raw data

--
Alex Feinman
---
Visit http://www.opennetcf.org


How can I load a image from MemoryStream ?

Rogerio
 
Save this image on the disk and deploy together with your small
application that loads this image. If you can reproduce this error again
you may write me email and attach to it your bmp and your code.

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Rogerio said:
I do this. In "Full Framework" the code is ok, but in Compact Framework a
exception is generate.

Rogerio

:

Okey, try to save this image into disk and using some image viewer make
sure that this image is not corrupted.

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Rogerio said:
Values are 0x42 and 0x4D.

Rogerio

:



It was suggested just that you would know what causes the exception. Ok,
tell us what values have the first two bytes of the AImagem array:

byte[] AImagem = ((byte[])dtr.GetValue(2));

It should be:

0 - 0x42
1 - 0x4D

is it?

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Rogerio Jun wrote:


The error persist.

Rogerio

:




Most likely it's because your stream is not a bitmap. Change your code to
this to track it down further:

byte[] AImagem = ((byte[])dtr.GetValue(2));
MemoryStream AStream = new MemoryStream(AImagem);
Bitmap b = new Bitmap(AStream);
pictureBox1.Image = b;

--
Mark Arteaga
..NET Compact Framework MVP
http://www.neotericsdc.com | http://blog.markarteaga.com






My code is generate a exception(ARGUMENTEXCEPTION).

Code:
byte[] AImagem = ((byte[])dtr.GetValue(2));
MemoryStream AStream = new MemoryStream(AImagem);
pictureBox1.Image = new Bitmap(AStream); <- this line generate a
exception.

Rogerio




:




New Bitmap(myStream)
This assumes the stream contains everything, including file header, not
just
raw data

--
Alex Feinman
---
Visit http://www.opennetcf.org



How can I load a image from MemoryStream ?

Rogerio
 
Back
Top