Generate image on the fly c#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

HI guy



I am working on the web application that required to display

the chart image on the page. The process is clicking the button

and browser will popup another windows that displayed the

image. The problem is the image is not a file but a array of

bytes so that i couldn't using it's image url to display in

different browser. Is there any way to create an image on the

fly i.e. get the array of bytes and display it on the browser

Assume i have an Generate.aspx that contain the button and its

input to generate the image ie.image width, image height, an Display.aspx to
show the image

and the following method



//Returns array of bytes

private byte[] GetBinaryImage(int width,int height)

{

//Get data from database

}

This is urgent someone help me to do so please.
Thank you
Popoxinhxan
 
You can create another aspx, say, GimmeDaImage.aspx, which would actually
output the image bytes and return the correct MIME type in the HTTP headers.

See docs on Response.ContentType and Response.BinaryWrite.

And your image tag would look like

<IMG SRC="GimmeDaImage.aspx?ImageID=1">
 
GimmieDaImage lol
You can create another aspx, say, GimmeDaImage.aspx, which would
actually output the image bytes and return the correct MIME type in
the HTTP headers.

See docs on Response.ContentType and Response.BinaryWrite.

And your image tag would look like

<IMG SRC="GimmeDaImage.aspx?ImageID=1">

HI guy

I am working on the web application that required to display

the chart image on the page. The process is clicking the button

and browser will popup another windows that displayed the

image. The problem is the image is not a file but a array of

bytes so that i couldn't using it's image url to display in

different browser. Is there any way to create an image on the

fly i.e. get the array of bytes and display it on the browser

Assume i have an Generate.aspx that contain the button and its

input to generate the image ie.image width, image height, an
Display.aspx
to
show the image
and the following method

//Returns array of bytes

private byte[] GetBinaryImage(int width,int height)

{

//Get data from database

}

This is urgent someone help me to do so please.
Thank you
Popoxinhxan
 
Dmitriy Lapshin said:
You can create another aspx, say, GimmeDaImage.aspx, which would actually
output the image bytes and return the correct MIME type in the HTTP headers.

See docs on Response.ContentType and Response.BinaryWrite.

Yes, I've try this but it's doesn't work. Could you please give me the
specific example
Thank you
And your image tag would look like

<IMG SRC="GimmeDaImage.aspx?ImageID=1">

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Popoxinhxan said:
HI guy



I am working on the web application that required to display

the chart image on the page. The process is clicking the button

and browser will popup another windows that displayed the

image. The problem is the image is not a file but a array of

bytes so that i couldn't using it's image url to display in

different browser. Is there any way to create an image on the

fly i.e. get the array of bytes and display it on the browser

Assume i have an Generate.aspx that contain the button and its

input to generate the image ie.image width, image height, an Display.aspx
to
show the image

and the following method



//Returns array of bytes

private byte[] GetBinaryImage(int width,int height)

{

//Get data from database

}

This is urgent someone help me to do so please.
Thank you
Popoxinhxan
 
Mind the line wraps:

http://groups-beta.google.com/group..._doneTitle=Back+to+Search&&d#a79c8d3397488915 -
contains a reply from someone at Microsoft!

http://groups-beta.google.com/group..._doneTitle=Back+to+Search&&d#c9af7b762dfdb6bc

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Popoxinhxan said:
Dmitriy Lapshin said:
You can create another aspx, say, GimmeDaImage.aspx, which would actually
output the image bytes and return the correct MIME type in the HTTP
headers.

See docs on Response.ContentType and Response.BinaryWrite.

Yes, I've try this but it's doesn't work. Could you please give me the
specific example
Thank you
And your image tag would look like

<IMG SRC="GimmeDaImage.aspx?ImageID=1">

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Popoxinhxan said:
HI guy



I am working on the web application that required to display

the chart image on the page. The process is clicking the button

and browser will popup another windows that displayed the

image. The problem is the image is not a file but a array of

bytes so that i couldn't using it's image url to display in

different browser. Is there any way to create an image on the

fly i.e. get the array of bytes and display it on the browser

Assume i have an Generate.aspx that contain the button and its

input to generate the image ie.image width, image height, an
Display.aspx
to
show the image

and the following method



//Returns array of bytes

private byte[] GetBinaryImage(int width,int height)

{

//Get data from database

}

This is urgent someone help me to do so please.
Thank you
Popoxinhxan
 
Heres the steps i do it in

create an aspx page that calls your image draw routing in its page load
event

write a function that draws your image onto a bitmap

use bitmap.save to output your image to a stream. Use
Response.OutputStream as this stream.

for example


private void Page_Load(object sender, System.EventArgs e)
{
//initialise etc first

Renderer.RenderToStream(Response.OutputStream);
}

in my renderer class

Public void RenderToStream(Stream target)
{
//---
//do all your drawing
//---

//then to send back a jpg

EncoderParameters encoderParams = new EncoderParameters();
long[] quality = new long[1];
quality[0] = 99;

EncoderParameter encoderParam = new EncoderParameter(Encoder.Quality,
quality);
encoderParams.Param[0] = encoderParam;
ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo jpegICI = null;

for (int x = 0; x < arrayICI.Length; x++)
{
if (arrayICI[x].FormatDescription.Equals("JPEG"))
{
jpegICI = arrayICI[x];
break;
}
}

if (jpegICI != null)
{
bm.Save(target, jpegICI, encoderParams);
}

//clean up everything here

}


call this from another page (programatically) like

picDial.ImageUrl=@"dial.aspx?ID=1&VALUE="+sValue+"&TYPE="+sType+"&TITLE="+sTitle;




http://darkhold.aspxconnection.com/Default.aspx

for the end result of what ive done.

hth
Scott
 
Back
Top