HighTechTalks DotNet Forums  

Error on streaming new bitmap

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss Error on streaming new bitmap in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
TumurS
 
Posts: n/a

Default Error on streaming new bitmap - 05-03-2007 , 09:32 AM






exact code:

try
{
Bitmap err_bmp = new Bitmap(200, 50, PixelFormat.Format16bppRgb555);
err_bmp.SetResolution(72, 72);
Graphics err_g = Graphics.FromImage(err_bmp);
Font err_f = new Font("Arial", 8);
SolidBrush err_b = new SolidBrush(Color.White);
err_g.FillRectangle(err_b, 0, 0, err_bmp.Width, err_bmp.Height);
err_b.Color = Color.Black;
err_g.DrawString(some_text, err_f, err_b, new RectangleF(new PointF(0,
0),
new SizeF(err_bmp.Width, err_bmp.Height)));
Response.ContentType = "image/bmp";
err_bmp.Save(Response.OutputStream, ImageFormat.Bmp);
...
}
catch (Exception err)
{
err_g.DrawString(err.Message, err_f, err_b, new RectangleF(new PointF(0,
0),
new SizeF(err_bmp.Width, err_bmp.Height)));
err_bmp.Save("c:\\err.bmp");
}

The last showed line inside try{} block (save to stream) raises "Generic
error occurred in GDI+".
But saving to a file (inside catch{} block) works well. I read the exception
text inside the saved bmp.
Any ideas?



Reply With Quote
  #2  
Old   
TumurS
 
Posts: n/a

Default Re: Error on streaming new bitmap - 05-03-2007 , 09:41 AM






I found solution. I had to save to the memory stream before.
But I thought that the memory stream is required only for PNG images???

"TumurS" <spam_tumur (AT) magicnet (DOT) mn> wrote

Quote:
exact code:

try
{
Bitmap err_bmp = new Bitmap(200, 50, PixelFormat.Format16bppRgb555);
err_bmp.SetResolution(72, 72);
Graphics err_g = Graphics.FromImage(err_bmp);
Font err_f = new Font("Arial", 8);
SolidBrush err_b = new SolidBrush(Color.White);
err_g.FillRectangle(err_b, 0, 0, err_bmp.Width, err_bmp.Height);
err_b.Color = Color.Black;
err_g.DrawString(some_text, err_f, err_b, new RectangleF(new PointF(0,
0),
new SizeF(err_bmp.Width, err_bmp.Height)));
Response.ContentType = "image/bmp";
err_bmp.Save(Response.OutputStream, ImageFormat.Bmp);
...
}
catch (Exception err)
{
err_g.DrawString(err.Message, err_f, err_b, new RectangleF(new
PointF(0, 0),
new SizeF(err_bmp.Width, err_bmp.Height)));
err_bmp.Save("c:\\err.bmp");
}

The last showed line inside try{} block (save to stream) raises "Generic
error occurred in GDI+".
But saving to a file (inside catch{} block) works well. I read the
exception text inside the saved bmp.
Any ideas?




Reply With Quote
  #3  
Old   
Michael Phillips, Jr.
 
Posts: n/a

Default Re: Error on streaming new bitmap - 05-03-2007 , 09:42 AM



Try disposing of your graphics object before saving to a stream.

"TumurS" <spam_tumur (AT) magicnet (DOT) mn> wrote

Quote:
exact code:

try
{
Bitmap err_bmp = new Bitmap(200, 50, PixelFormat.Format16bppRgb555);
err_bmp.SetResolution(72, 72);
Graphics err_g = Graphics.FromImage(err_bmp);
Font err_f = new Font("Arial", 8);
SolidBrush err_b = new SolidBrush(Color.White);
err_g.FillRectangle(err_b, 0, 0, err_bmp.Width, err_bmp.Height);
err_b.Color = Color.Black;
err_g.DrawString(some_text, err_f, err_b, new RectangleF(new PointF(0,
0),
new SizeF(err_bmp.Width, err_bmp.Height)));
Response.ContentType = "image/bmp";
err_bmp.Save(Response.OutputStream, ImageFormat.Bmp);
...
}
catch (Exception err)
{
err_g.DrawString(err.Message, err_f, err_b, new RectangleF(new
PointF(0, 0),
new SizeF(err_bmp.Width, err_bmp.Height)));
err_bmp.Save("c:\\err.bmp");
}

The last showed line inside try{} block (save to stream) raises "Generic
error occurred in GDI+".
But saving to a file (inside catch{} block) works well. I read the
exception text inside the saved bmp.
Any ideas?




Reply With Quote
  #4  
Old   
TumurS
 
Posts: n/a

Default Re: Error on streaming new bitmap - 05-03-2007 , 12:51 PM



I tried it, but it does not help.


"Michael Phillips, Jr." <mphillips53 (AT) nospam (DOT) jun0.c0m> wrote

Quote:
Try disposing of your graphics object before saving to a stream.

"TumurS" <spam_tumur (AT) magicnet (DOT) mn> wrote in message
news:uwCsSdYjHHA.1624 (AT) TK2MSFTNGP06 (DOT) phx.gbl...
exact code:

try
{
Bitmap err_bmp = new Bitmap(200, 50, PixelFormat.Format16bppRgb555);
err_bmp.SetResolution(72, 72);
Graphics err_g = Graphics.FromImage(err_bmp);
Font err_f = new Font("Arial", 8);
SolidBrush err_b = new SolidBrush(Color.White);
err_g.FillRectangle(err_b, 0, 0, err_bmp.Width, err_bmp.Height);
err_b.Color = Color.Black;
err_g.DrawString(some_text, err_f, err_b, new RectangleF(new PointF(0,
0),
new SizeF(err_bmp.Width, err_bmp.Height)));
Response.ContentType = "image/bmp";
err_bmp.Save(Response.OutputStream, ImageFormat.Bmp);
...
}
catch (Exception err)
{
err_g.DrawString(err.Message, err_f, err_b, new RectangleF(new
PointF(0, 0),
new SizeF(err_bmp.Width, err_bmp.Height)));
err_bmp.Save("c:\\err.bmp");
}

The last showed line inside try{} block (save to stream) raises "Generic
error occurred in GDI+".
But saving to a file (inside catch{} block) works well. I read the
exception text inside the saved bmp.
Any ideas?






Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.