When will Image.fromstream be in the compact framework ??

  • Thread starter Thread starter Brent Yax
  • Start date Start date
B

Brent Yax

Does anyone know if there are any plans to include the
system.io MemoryStream or the System.Drawing
Image.fromstream functionality to .Net compact framework ?

Or does anyone know of a way in the .net cvompact
framework to display an image in a compact application
from a string or byte array ?

Thank you !!
 
Basically I have a string that contains entire JPEG images
in ASCII or BINARY. I am looking for a way to take that
string and convert it to an image without having to write
it to a file. I would like to have my compact application
display the image from the variable I already have (or a
converted one, I just don't want to waste resources to
write all there JPEG's to files before viewing them).

Any help would be greatly appreciated!
 
Geoff,

This will work if the data in the stream is a bitmap
image, but what if we're trying to construct a jpeg?

-----Original Message-----
Hi Brent,

You should be able to create a stream from the byte array and use the
overloaded constructor of the Bitmap class...

byte[] bytes = new byte[2048];
System.IO.MemoryStream ms = new System.IO.MemoryStream (bytes);
Image im = new Bitmap(ms);


--
Geoff Schwab
Program Manager
Excell Data Corporation
http://msdn.com/mobility
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/n etcf/FAQ/default.aspx

This posting is provided "AS IS" with no warranties, and confers no rights.
Brent Yax said:
Does anyone know if there are any plans to include the
system.io MemoryStream or the System.Drawing
Image.fromstream functionality to .Net compact framework ?

Or does anyone know of a way in the .net cvompact
framework to display an image in a compact application
from a string or byte array ?

Thank you !!


.
 
Hi Chris,

It will still work, the Bitmap object can handle jpegs. The following code
loads a jpeg into a byte array and displays it...


Image im = null;

private void Form1_Load(object sender, System.EventArgs e)
{
String fullAppName = Assembly.GetExecutingAssembly().GetName().CodeBase;
String fullAppPath = Path.GetDirectoryName(fullAppName);
String testImageName = Path.Combine(fullAppPath, "test.jpg");

FileStream fs = null;
MemoryStream ms = null;

try
{
if (File.Exists(testImageName))
{
fs = new FileStream(testImageName, FileMode.Open);

byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, (int)fs.Length);
ms = new MemoryStream(bytes);
im = new Bitmap(ms);
}
}
finally
{
if (fs != null)
fs.Close();
if (ms != null)
ms.Close();
}
}

protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawImage(im, 0, 0);
base.OnPaint (e);
}

Geoff,

This will work if the data in the stream is a bitmap
image, but what if we're trying to construct a jpeg?

-----Original Message-----
Hi Brent,

You should be able to create a stream from the byte array and use the
overloaded constructor of the Bitmap class...

byte[] bytes = new byte[2048];
System.IO.MemoryStream ms = new System.IO.MemoryStream (bytes);
Image im = new Bitmap(ms);


--
Geoff Schwab
Program Manager
Excell Data Corporation
http://msdn.com/mobility
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/n etcf/FAQ/default.aspx

This posting is provided "AS IS" with no warranties, and confers no rights.
Brent Yax said:
Does anyone know if there are any plans to include the
system.io MemoryStream or the System.Drawing
Image.fromstream functionality to .Net compact framework ?

Or does anyone know of a way in the .net cvompact
framework to display an image in a compact application
from a string or byte array ?

Thank you !!


.
 
Geoff Schwab [MSFT] said:
Hi Brent,

You should be able to create a stream from the byte array and use the
overloaded constructor of the Bitmap class...

byte[] bytes = new byte[2048];
System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes);
Image im = new Bitmap(ms);

I get an OutOfMemory exception when i create the new Bitmap(ms)
Does anyone have an idea of why?
please help!
 
Back
Top