473,403 Members | 2,222 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,403 software developers and data experts.

How do I create a Stream object from a Bitmap

I have a need to write a Bitmap to a Stream, but get an error message on all
my attempts. I am doing something like the following:

Stream _appImage;

public frmCustomerFeedback(Bitmap bm)
{
InitializeComponent();

bm.Save(_appImage, System.Drawing.Imaging.ImageFormat.Jpeg); <== this
fails
//bm.Save("testimg.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); <==
this works
ugPictureBox.Image = bm;
}

Any suggestions?
Nov 4 '08 #1
2 17077
On Mon, 03 Nov 2008 16:33:27 -0800, Bill Fuller <so*****@nospam.comwrote:
I have a need to write a Bitmap to a Stream, but get an error message on
all
my attempts. I am doing something like the following:

Stream _appImage;

public frmCustomerFeedback(Bitmap bm)
{
InitializeComponent();

bm.Save(_appImage, System.Drawing.Imaging.ImageFormat.Jpeg); <==
this fails
//bm.Save("testimg.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
<== this works
ugPictureBox.Image = bm;
}

Any suggestions?
Yes. Initialize your _appImage variable so that it actually references an
instance of the Stream class.

Just as the documentation promises, if you pass "null" for that argument
(or the second, for that matter), you'll get an ArgumentNullException.

So: don't pass null. How can the method know what Stream to write to if
you don't pass it a valid reference to one?

Pete
Nov 4 '08 #2
Never mind... found my problem.

MemoryStream _appImage = new MemoryStream();
"Bill Fuller" <so*****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>I have a need to write a Bitmap to a Stream, but get an error message on
all my attempts. I am doing something like the following:

Stream _appImage;

public frmCustomerFeedback(Bitmap bm)
{
InitializeComponent();

bm.Save(_appImage, System.Drawing.Imaging.ImageFormat.Jpeg); <== this
fails
//bm.Save("testimg.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); <==
this works
ugPictureBox.Image = bm;
}

Any suggestions?

Nov 4 '08 #3

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

Similar topics

2
by: stephen fx | last post by:
Hello all! Using C/C++ I can do this: struct MyStruct { int a; char b; }; MyStruct test;
3
by: Bradford | last post by:
I have an Windows application that displays lots of different colored lines in a Panel by using the Graphics.DrawLine method. The location and length of each line comes from a database query that...
8
by: TJ | last post by:
I need to be able to pass a pointer to a (managed code) Stream object to a COM method so it can serialize its data into the stream. I have a C# application that makes uses of Randolf Duke's...
2
by: | last post by:
Hello All, I am writing a web application that reads a bitmap from a file and outputing it to a HTTP response stream to return the image to the requesting client. The image file is a regular...
5
by: Lance | last post by:
I need to create a Drawing.Bitmap from an array of integer values. My current technique creates a bitmap that eventually becomes corrupt (i.e., the bitmap's pixels change to a different color...
1
by: Tom Edelbrok | last post by:
I'm reading embedded bitmaps from an EXE project and everthing works fine. I do a GetExecutingAssembly, followed by setting a stream object to...
1
by: Martin Widmer | last post by:
Hi Folks In my object I am trying to implement a function in order to render the picture to XML (to generate RDL for SQL Server). That Function causes the error mentioned in the subject at the...
11
by: Mark B | last post by:
I want to display a pre-designed graphical 'performance badge' on certain webpages (round, about 2cm diameter) next to a salesperson's details. I have a function,...
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: 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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.