473,387 Members | 1,492 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,387 software developers and data experts.

MemoryStream() method show Exception

hi
i am working on dicom image.this is code which gives exception on
"System.Drawing.Image imgInFile = System.Drawing.Image.FromStream(new
System.IO.MemoryStream(destPixels ) "
..The exception is "System.ArgumentException: Parameter is not valid."
could any body help me
i am waiting for help
regards,
Neeraj Kumar

protected internal virtual System.Drawing.Image scaleImage()
{
int scaledWidth = w / 2;
int scaledHeight = h / 2;
int index = 0;
int value_Renamed = 0;
byte[] destPixels = null;
this.pixData = dHR.data;
System.GC.Collect();

destPixels = new byte[scaledWidth * scaledHeight];
for (int i = 0; i < h; i += 2)
{
for (int j = 0; j < w; j += 2)
{
destPixels[index++] = (byte)pixData[(i * w) + j];
}
}
pixData = null;
Tools.gc("PIXDATA == NULL");
System.Drawing.Image imgInFile =
System.Drawing.Image.FromStream(new System.IO.MemoryStream(destPixels )
return imgInFile;
}

May 10 '06 #1
3 2095
Can you provide more code?

SG

"Neeraj" <kn*******@gmail.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
hi
i am working on dicom image.this is code which gives exception on
"System.Drawing.Image imgInFile = System.Drawing.Image.FromStream(new
System.IO.MemoryStream(destPixels ) "
.The exception is "System.ArgumentException: Parameter is not valid."
could any body help me
i am waiting for help
regards,
Neeraj Kumar

protected internal virtual System.Drawing.Image scaleImage()
{
int scaledWidth = w / 2;
int scaledHeight = h / 2;
int index = 0;
int value_Renamed = 0;
byte[] destPixels = null;
this.pixData = dHR.data;
System.GC.Collect();

destPixels = new byte[scaledWidth * scaledHeight];
for (int i = 0; i < h; i += 2)
{
for (int j = 0; j < w; j += 2)
{
destPixels[index++] = (byte)pixData[(i * w) + j];
}
}
pixData = null;
Tools.gc("PIXDATA == NULL");
System.Drawing.Image imgInFile =
System.Drawing.Image.FromStream(new System.IO.MemoryStream(destPixels )
return imgInFile;
}

May 10 '06 #2
Neeraj <kn*******@gmail.com> wrote:
i am working on dicom image.this is code which gives exception on
"System.Drawing.Image imgInFile = System.Drawing.Image.FromStream(new
System.IO.MemoryStream(destPixels ) "
.The exception is "System.ArgumentException: Parameter is not valid."


Indeed. Image.FromStream expects you to provide an image file in one of
the supported formats - jpeg, gif etc. You've given raw data.

(It's unfortunate that the documentation doesn't make this obvious,
admittedly.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 10 '06 #3
Some code I have had laying around here for a while; This should help your
problem as well.

public System.Drawing.Image ResizeImage(System.Drawing.Image
poImage, System.Drawing.Size poSize) {
//Detach image from its source
System.Drawing.Image oImageOriginal =
(System.Drawing.Image)poImage.Clone();

//Resize new image
System.Drawing.Image oResizedImage = new
System.Drawing.Bitmap(poSize.Width, poSize.Height,
oImageOriginal.PixelFormat);
System.Drawing.Graphics oGraphic =
Graphics.FromImage(oResizedImage);
oGraphic.CompositingQuality =
System.Drawing.Drawing2D.CompositingQuality.HighQu ality ;
oGraphic.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.HighQuality ;
oGraphic.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQua lityBicubic ;
Rectangle oRectangle = new Rectangle(0, 0,
poSize.Width, poSize.Height);
oGraphic.DrawImage(oImageOriginal, oRectangle);
oGraphic.Dispose() ;
oImageOriginal.Dispose();
return oResizedImage;
}

Cheers,

Greg Young
MVP - C#
"Neeraj" <kn*******@gmail.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
hi
i am working on dicom image.this is code which gives exception on
"System.Drawing.Image imgInFile = System.Drawing.Image.FromStream(new
System.IO.MemoryStream(destPixels ) "
.The exception is "System.ArgumentException: Parameter is not valid."
could any body help me
i am waiting for help
regards,
Neeraj Kumar

protected internal virtual System.Drawing.Image scaleImage()
{
int scaledWidth = w / 2;
int scaledHeight = h / 2;
int index = 0;
int value_Renamed = 0;
byte[] destPixels = null;
this.pixData = dHR.data;
System.GC.Collect();

destPixels = new byte[scaledWidth * scaledHeight];
for (int i = 0; i < h; i += 2)
{
for (int j = 0; j < w; j += 2)
{
destPixels[index++] = (byte)pixData[(i * w) + j];
}
}
pixData = null;
Tools.gc("PIXDATA == NULL");
System.Drawing.Image imgInFile =
System.Drawing.Image.FromStream(new System.IO.MemoryStream(destPixels )
return imgInFile;
}

May 11 '06 #4

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

Similar topics

1
by: xmlguy | last post by:
PREVIOUS BACKGROUND POST: I am trying to reuse a Memory Stream for loading and transforming the xml it contains Basically I have defined following interfaces: Class Render {
1
by: Arcnet | last post by:
Using MemoryStream I Have a problem to create a new Image from byte array that originaly was created from an older image (Everything is being preformed in the same Thread) //Get Image...
3
by: Nicolas | last post by:
Hi Everybody, I'm working with the MemoryStream and I'm having problems with the ReadBytes method. When I use it, this method never returns bytes!!!! MemoryStream sw = new MemoryStream();...
1
by: Rogerio Jun | last post by:
my code : MemoryStream AStream = new MemoryStream(); byte AImage = null; try { picTreeview.Image.Save(AStream, System.Drawing.Imaging.ImageFormat.Icon); AImage = AStream.GetBuffer();...
3
by: T. Davis | last post by:
In C#, I am able to successfully stream a TIFF image that comes from a BLOB field in a database, save it to file, then convert the pages within TIFF file into jpegs (using GDI+) and display on the...
7
by: Robson Carvalho Machado | last post by:
Does anyone knows how to CAST this SQL Response into a MemoryStream ?? When executing below code an error message says "Specified cast is not valid" I need to put this into MemoryStream to use it...
5
by: Naamat | last post by:
Hello, I am the sample FPSEPublish (http://blog.baeke.info/blog/_archives/2005/3/3/393158.html) code to upload a document to Sharepoint (WSS). This works perfectly for samll documents. ...
4
by: Heron | last post by:
Hi, Could someone explain me why the following code doesn't work? The memorystream always remains with length 0. MemoryStream input = new MemoryStream();
3
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hi, I am using dotnet remoting with a binarry formatter. I have a property that returns a memorystream that has had a file loaded into it. When I try to access this property though I get an...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.