473,672 Members | 2,435 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.FromStrea m(new
System.IO.Memor yStream(destPix els ) "
..The exception is "System.Argumen tException: 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.Colle ct();

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("PIXDA TA == NULL");
System.Drawing. Image imgInFile =
System.Drawing. Image.FromStrea m(new System.IO.Memor yStream(destPix els )
return imgInFile;
}

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

SG

"Neeraj" <kn*******@gmai l.com> wrote in message
news:11******** **************@ g10g2000cwb.goo glegroups.com.. .
hi
i am working on dicom image.this is code which gives exception on
"System.Drawing .Image imgInFile = System.Drawing. Image.FromStrea m(new
System.IO.Memor yStream(destPix els ) "
.The exception is "System.Argumen tException: 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.Colle ct();

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("PIXDA TA == NULL");
System.Drawing. Image imgInFile =
System.Drawing. Image.FromStrea m(new System.IO.Memor yStream(destPix els )
return imgInFile;
}

May 10 '06 #2
Neeraj <kn*******@gmai l.com> wrote:
i am working on dicom image.this is code which gives exception on
"System.Drawing .Image imgInFile = System.Drawing. Image.FromStrea m(new
System.IO.Memor yStream(destPix els ) "
.The exception is "System.Argumen tException: Parameter is not valid."


Indeed. Image.FromStrea m 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.co m>
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(Sys tem.Drawing.Ima ge
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.W idth, poSize.Height,
oImageOriginal. PixelFormat);
System.Drawing. Graphics oGraphic =
Graphics.FromIm age(oResizedIma ge);
oGraphic.Compos itingQuality =
System.Drawing. Drawing2D.Compo sitingQuality.H ighQuality ;
oGraphic.Smooth ingMode =
System.Drawing. Drawing2D.Smoot hingMode.HighQu ality ;
oGraphic.Interp olationMode =
System.Drawing. Drawing2D.Inter polationMode.Hi ghQualityBicubi c ;
Rectangle oRectangle = new Rectangle(0, 0,
poSize.Width, poSize.Height);
oGraphic.DrawIm age(oImageOrigi nal, oRectangle);
oGraphic.Dispos e() ;
oImageOriginal. Dispose();
return oResizedImage;
}

Cheers,

Greg Young
MVP - C#
"Neeraj" <kn*******@gmai l.com> wrote in message
news:11******** **************@ g10g2000cwb.goo glegroups.com.. .
hi
i am working on dicom image.this is code which gives exception on
"System.Drawing .Image imgInFile = System.Drawing. Image.FromStrea m(new
System.IO.Memor yStream(destPix els ) "
.The exception is "System.Argumen tException: 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.Colle ct();

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("PIXDA TA == NULL");
System.Drawing. Image imgInFile =
System.Drawing. Image.FromStrea m(new System.IO.Memor yStream(destPix els )
return imgInFile;
}

May 11 '06 #4

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

Similar topics

1
11163
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
5567
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 From File byte arr;
3
10946
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(); sw.Write(System.Text.UnicodeEncoding.Unicode.GetBytes("Testing"),0,6); System.Text.StringBuilder sb = new System.Text.StringBuilder(); byte buffer = new byte; byte result = sw.GetBuffer(); int a = sw.Read(buffer,2,4);
1
3452
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(); AStream.Close();
3
5864
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 web (using ASP.NET). However, when I generate the Image object using FromStream (passing in the MemoryStream containing image bytes), an exception of "A generic error occurred in GDI+" is thrown when performing the conversion/save for display....
7
2395
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 into imgPhoto Dim imgPhoto As System.Drawing.Image = System.Drawing.Image.FromStream(myStream) Dim dbConn, SQLStmt, dbComm, dbRead, img Dim myStream 'As New MemoryStream dbConn = New
5
26264
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. Problem: When I attempt to upload a huge document (300Megabayte) on a PC with 3.6Gig RAM I am getting a OutOfMemoryException when the program attempts to read the
4
8421
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
5550
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 error regarding "the proxy has no channel sink.......or no suitable Client channel to talk to the server."
0
8488
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8611
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7449
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6240
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2067
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1819
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.