problem in using asp.net stream graphic and image

M

miladhatam

hi
i want to put the name of my site in corner of my images
i've used from graphics and bitmap class and i have no problem with
putting the text
but it make problem with other works in my page
for example :
//-------------------------- begin
Bitmap bitMapImage = new
System.Drawing.Bitmap(Server.MapPath("image/" + 2 + ".jpg"));

Graphics graphicImage = Graphics.FromImage(bitMapImage);
graphicImage.SmoothingMode = SmoothingMode.AntiAlias;
Rectangle rect = new Rectangle(1,1,50,50);


graphicImage.DrawString("irankohan.com", new Font("Arial", 12,
FontStyle.Bold), SystemBrushes.WindowText, new Point(13, 27));
graphicImage.DrawArc(new Pen(Color.White, 3), 90, 235, 150, 50, 0,
360);
Response.ContentType = "image/jpeg";


bitMapImage.Save(Response.OutputStream, ImageFormat.Jpeg);
//--------------------------- end
Label lb = new Label();
lb.Text = "milad";
Controls.Add(lb);


i wanna show information about the picture dynamically but it can't
be shown
why ?
 
A

Anthony Jones

hi
i want to put the name of my site in corner of my images
i've used from graphics and bitmap class and i have no problem with
putting the text
but it make problem with other works in my page
for example :
//-------------------------- begin
Bitmap bitMapImage = new
System.Drawing.Bitmap(Server.MapPath("image/" + 2 + ".jpg"));

Graphics graphicImage = Graphics.FromImage(bitMapImage);
graphicImage.SmoothingMode = SmoothingMode.AntiAlias;
Rectangle rect = new Rectangle(1,1,50,50);


graphicImage.DrawString("irankohan.com", new Font("Arial", 12,
FontStyle.Bold), SystemBrushes.WindowText, new Point(13, 27));
graphicImage.DrawArc(new Pen(Color.White, 3), 90, 235, 150, 50, 0,
360);
Response.ContentType = "image/jpeg";


bitMapImage.Save(Response.OutputStream, ImageFormat.Jpeg);
//--------------------------- end
Label lb = new Label();
lb.Text = "milad";
Controls.Add(lb);


i wanna show information about the picture dynamically but it can't
be shown
why ?

Its not clear but my guess is that you believe that you can simply stream
out the image content as part of the rest of the HTML content of a page. Or
am I way off? If I am whats the Label code above doing?

You need to place this code in a .ashx file and have all your img srcs point
to it with the name of the image as a querystring parameter.

Make sure you configure the response cache headers correctly so that the
generated img can be cached clientside and hopeful by ASP.NET response
caching as well.
 
G

Guest

hi
i want to put the name of my site in corner of my images
i've used from graphics and bitmap class and i have no problem with
putting the text
but it make problem with other works in my page
for example :
//--------------------------  begin
 Bitmap bitMapImage = new
     System.Drawing.Bitmap(Server.MapPath("image/" + 2 + ".jpg"));

  Graphics graphicImage = Graphics.FromImage(bitMapImage);
  graphicImage.SmoothingMode = SmoothingMode.AntiAlias;
        Rectangle rect = new Rectangle(1,1,50,50);

  graphicImage.DrawString("irankohan.com", new Font("Arial", 12,
FontStyle.Bold), SystemBrushes.WindowText, new Point(13, 27));
  graphicImage.DrawArc(new Pen(Color.White, 3), 90, 235, 150, 50, 0,
360);
  Response.ContentType = "image/jpeg";

  bitMapImage.Save(Response.OutputStream, ImageFormat.Jpeg);
//--------------------------- end
 Label lb = new Label();
 lb.Text = "milad";
 Controls.Add(lb);

 i wanna show information about the picture dynamically but it can't
be shown
why ?

Because here you said that response is an image
Response.ContentType = "image/jpeg";

As Anthony already mentioned you should separate the code for images
from the code for html layout.
 
M

miladhatam

hi to both of you
thanks for your answers
but i change the Response.ContentType to text/html but no change was
happend
do you have sample about it ?
i wanna get my images url and information about it from Db
thanks for your helps
 
G

Guest

hi to both of you
thanks for your answers
but i change the Response.ContentType to text/html but no change was
happend
do you have sample about it ?
i wanna get my images url and information about it from Db
thanks for your helps

You have to move the code for images into ASPX, or ASHX "file".
I mean the code between

//-------------------------- begin
....
//--------------------------- end

Next, refer to that file as

<img src="MyImageFile.aspx">

and do the rest.

Regarding Response.ContentType. Sure, it's not only because of its
value. It does specify content type for the response for the browser
and browser will render the content on its own logic. In your example,
ContentType will not help because at the beginning you sent already
some piece of binary information and it cannot be rendered properly
together with HTML markup. This is the reason why you need to create a
separate web page that would serve for the binary output (your image)
and a regular ASP.NET webform to render the HTML markup.
 
A

Anthony Jones

hi to both of you
thanks for your answers
but i change the Response.ContentType to text/html but no change was
happend
do you have sample about it ?
i wanna get my images url and information about it from Db
thanks for your helps
You have to move the code for images into ASPX, or ASHX "file".
I mean the code between

//-------------------------- begin
....
//--------------------------- end

Next, refer to that file as

<img src="MyImageFile.aspx">

and do the rest.

Regarding Response.ContentType. Sure, it's not only because of its
value. It does specify content type for the response for the browser
and browser will render the content on its own logic. In your example,
ContentType will not help because at the beginning you sent already
some piece of binary information and it cannot be rendered properly
together with HTML markup. This is the reason why you need to create a
separate web page that would serve for the binary output (your image)
and a regular ASP.NET webform to render the HTML markup.
Use an .ashx, an aspx has way too much overhead that you're not going to
need.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top