List Info

Thread: Image Response using ASP.Net




Image Response using ASP.Net
user name
2006-10-16 10:53:45
I'm looking to optimise a web application that produces
images on the
fly.

My server side class has a method that returns a Bitmap
object (.Net 2,
C# Class).  When the user requests the page, this method is
invoked and
the generated image is displayed in the response.  I do this
by firstly
converting it to Jpeg, writing it to disk, then referencing
the new Jpeg
file using an imageControl on my asp page.

This is a bit clunky, I want to avoid writing to disk.  Has
anyone got
any good techniques for writing an image out directly from
memory to the
response?

Thanks for any advice.

Simon James.


The contents of this email are confidential to the intended
recipient
and may not be disclosed. Although it is believed that this
email and
any attachments are virus free, it is the responsibility of
the recipient to confirm this.

Smith & Williamson Corporate Finance Limited - A member
of the bond Stock Exchange.  
A member of M&A International Inc. http://www.mergers.net 
Registered in England No. 4533970. Authorised and regulated
by the Financial Services Authority 
Smith & Williamson Investment Management Limited,
Registered No. 976145. Authorised and regulated by the
Financial Services Authority.
Smith & Williamson Pension Consultancy Limited -
Independent Intermediary. Registered No. 3133226. Authorised
and regulated by the Financial Services Authority.
Smith & Williamson Fund Administration Limited,
Registered No. 1934644. Authorised and regulated by the
Financial Services Authority.
Smith & Williamson Limited - A member of Nexia
International.  Registered in England No. 4534022. Regulated
by the Institute of Chartered Accountants in England &
Wales for a range of investment business activities.
NCL Investments Limited, Registered No. 1913794.
Member of the bond Stock Exchange authorised and regulated
by the Financial Services Authority.

Registered Office: 25 Moorgate, bond EC2R 6AY
Telephone: 020 7131 4000 http://www.smith.wi
lliamson.co.uk

Nexia Smith & Williamson Audit Limited - A member of
Nexia International. Registered in England No. 4469576.
Nexia Smith & Williamson Audit Limited is a company
registered to carry out audit work and is regulated for a
range of investment activities by the Institute of Chartered
Accountants in England and Wales.  Smith & Williamson
Limited is a separate company that provides professional
resources and certain services to Nexia Smith &
Williamson Audit Limited under the terms of a formal
agreement on an arm’s length basis.

Registered Office: 25 Moorgate, bond EC2R 6AY
Telephone: 020 7131 4000 http://www.nex
iasmith.williamson.co.uk

All telephone calls are recorded for business purposes.

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Image Response using ASP.Net
user name
2006-10-16 11:02:55
Use an httphandler, a lot of samples are available on the
web. But writing to disk may be a good caching model.

Paul van Brenk

-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:ADVANCED-DOTNETDISCUSS.DEVELOP.COM] On Behalf Of Simon
Cansick
Sent: Monday, October 16, 2006 12:54
To: ADVANCED-DOTNETDISCUSS.DEVELOP.COM
Subject: [ADVANCED-DOTNET] Image Response using ASP.Net

I'm looking to optimise a web application that produces
images on the
fly.

My server side class has a method that returns a Bitmap
object (.Net 2,
C# Class).  When the user requests the page, this method is
invoked and
the generated image is displayed in the response.  I do this
by firstly
converting it to Jpeg, writing it to disk, then referencing
the new Jpeg
file using an imageControl on my asp page.

This is a bit clunky, I want to avoid writing to disk.  Has
anyone got
any good techniques for writing an image out directly from
memory to the
response?

Thanks for any advice.

Simon James.


The contents of this email are confidential to the intended
recipient
and may not be disclosed. Although it is believed that this
email and
any attachments are virus free, it is the responsibility of
the recipient to confirm this.

Smith & Williamson Corporate Finance Limited - A member
of the bond Stock Exchange.  
A member of M&A International Inc. http://www.mergers.net 
Registered in England No. 4533970. Authorised and regulated
by the Financial Services Authority 
Smith & Williamson Investment Management Limited,
Registered No. 976145. Authorised and regulated by the
Financial Services Authority.
Smith & Williamson Pension Consultancy Limited -
Independent Intermediary. Registered No. 3133226. Authorised
and regulated by the Financial Services Authority.
Smith & Williamson Fund Administration Limited,
Registered No. 1934644. Authorised and regulated by the
Financial Services Authority.
Smith & Williamson Limited - A member of Nexia
International.  Registered in England No. 4534022. Regulated
by the Institute of Chartered Accountants in England &
Wales for a range of investment business activities.
NCL Investments Limited, Registered No. 1913794.
Member of the bond Stock Exchange authorised and regulated
by the Financial Services Authority.

Registered Office: 25 Moorgate, bond EC2R 6AY
Telephone: 020 7131 4000 http://www.smith.wi
lliamson.co.uk

Nexia Smith & Williamson Audit Limited - A member of
Nexia International. Registered in England No. 4469576.
Nexia Smith & Williamson Audit Limited is a company
registered to carry out audit work and is regulated for a
range of investment activities by the Institute of Chartered
Accountants in England and Wales.  Smith & Williamson
Limited is a separate company that provides professional
resources and certain services to Nexia Smith &
Williamson Audit Limited under the terms of a formal
agreement on an arm’s length basis.

Registered Office: 25 Moorgate, bond EC2R 6AY
Telephone: 020 7131 4000 http://www.nex
iasmith.williamson.co.uk

All telephone calls are recorded for business purposes.

===================================
This list is hosted by DevelopMentor  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Image Response using ASP.Net
user name
2006-10-16 11:29:27
Hi,

The ASP.Net HttpResponse object exposes its underlying
output stream,
via the OutputStream property.
You can use this reference to write directly to the output
stream from,
among others, any in-memory buffer.
Here's an example of how to build a 100x100 pixels image
which, for the
sake of the example, has a yellow background built at
runtime and pass
it as output on the fly, inside an http handler:

~~~~~~~~~~~~~~

int iWidth = 100;
int iHeight = 100;

using (Bitmap bmpThumbnail = new Bitmap(iWidth, iHeight))
{
    Rectangle rcCanvas = new Rectangle(0, 0, iWidth,
iHeight);

    using (Graphics grThumbnail =
Graphics.FromImage(bmpThumbnail))
    {
        grThumbnail.FillRectangle(new
SolidBrush(Color.Yellow), rcCanvas);
    }

    // Output the bitmap data to the http response

    context.Response.ContentType = "image/jpeg";
    bmpThumbnail.Save(context.Response.OutputStream,
ImageFormat.Jpeg);
}

~~~~~~~~~~~~~~

HTH,

Efran Cobisi, cobisi.com

Simon Cansick wrote:
> I'm looking to optimise a web application that produces
images on the
> fly.
>
> My server side class has a method that returns a Bitmap
object (.Net 2,
> C# Class).  When the user requests the page, this
method is invoked and
> the generated image is displayed in the response.  I do
this by firstly
> converting it to Jpeg, writing it to disk, then
referencing the new Jpeg
> file using an imageControl on my asp page.
>
> This is a bit clunky, I want to avoid writing to disk. 
Has anyone got
> any good techniques for writing an image out directly
from memory to the
> response?
>
> Thanks for any advice.
>
> Simon James.
>
>
> The contents of this email are confidential to the
intended recipient
> and may not be disclosed. Although it is believed that
this email and
> any attachments are virus free, it is the
responsibility of the recipient to confirm this.
>
> Smith & Williamson Corporate Finance Limited - A
member of the bond Stock Exchange.
> A member of M&A International Inc. http://www.mergers.net 
Registered in England No. 4533970. Authorised and regulated
by the Financial Services Authority
> Smith & Williamson Investment Management Limited,
Registered No. 976145. Authorised and regulated by the
Financial Services Authority.
> Smith & Williamson Pension Consultancy Limited -
Independent Intermediary. Registered No. 3133226. Authorised
and regulated by the Financial Services Authority.
> Smith & Williamson Fund Administration Limited,
Registered No. 1934644. Authorised and regulated by the
Financial Services Authority.
> Smith & Williamson Limited - A member of Nexia
International.  Registered in England No. 4534022. Regulated
by the Institute of Chartered Accountants in England &
Wales for a range of investment business activities.
> NCL Investments Limited, Registered No. 1913794.
> Member of the bond Stock Exchange authorised and
regulated by the Financial Services Authority.
>
> Registered Office: 25 Moorgate, bond EC2R 6AY
> Telephone: 020 7131 4000 http://www.smith.wi
lliamson.co.uk
>
> Nexia Smith & Williamson Audit Limited - A member
of Nexia International. Registered in England No. 4469576.
> Nexia Smith & Williamson Audit Limited is a company
registered to carry out audit work and is regulated for a
range of investment activities by the Institute of Chartered
Accountants in England and Wales.  Smith & Williamson
Limited is a separate company that provides professional
resources and certain services to Nexia Smith &
Williamson Audit Limited under the terms of a formal
agreement on an arm’s length basis.
>
> Registered Office: 25 Moorgate, bond EC2R 6AY
> Telephone: 020 7131 4000 http://www.nex
iasmith.williamson.co.uk
>
> All telephone calls are recorded for business purposes.
>
> ===================================
> This list is hosted by DevelopMentor�  http://www.develop.com
>
> View archives and manage your subscription(s) at http://discuss.develop.com

>

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Image Response using ASP.Net
user name
2006-10-17 18:10:13
Write a handler that emits the JPG as the respone. Here's an
example:

http://staff.develop.com/ballen/blog
/PermaLink.aspx?guid=2d8b430b-8361-416d-
9df8-9aff48bf2481

-Brock
http://staff.develop.
com/ballen


> -----Original Message-----
> From: Discussion of advanced .NET topics.
> [mailto:ADVANCED-DOTNETDISCUSS.DEVELOP.COM] On
Behalf Of
> Simon Cansick
> Sent: Monday, October 16, 2006 11:54 AM
> To: ADVANCED-DOTNETDISCUSS.DEVELOP.COM
> Subject: [ADVANCED-DOTNET] Image Response using ASP.Net
>
> I'm looking to optimise a web application that produces
images on the
> fly.
>
> My server side class has a method that returns a Bitmap
> object (.Net 2,
> C# Class).  When the user requests the page, this
method is
> invoked and
> the generated image is displayed in the response.  I do
this
> by firstly
> converting it to Jpeg, writing it to disk, then
referencing
> the new Jpeg
> file using an imageControl on my asp page.
>
> This is a bit clunky, I want to avoid writing to disk. 
Has anyone got
> any good techniques for writing an image out directly
from
> memory to the
> response?
>
> Thanks for any advice.
>
> Simon James.
>
>
> The contents of this email are confidential to the
intended recipient
> and may not be disclosed. Although it is believed that
this email and
> any attachments are virus free, it is the
responsibility of
> the recipient to confirm this.
>
> Smith & Williamson Corporate Finance Limited - A
member of
> the bond Stock Exchange.
> A member of M&A International Inc. http://www.mergers.net
> Registered in England No. 4533970. Authorised and
regulated
> by the Financial Services Authority
> Smith & Williamson Investment Management Limited,
Registered
> No. 976145. Authorised and regulated by the Financial
> Services Authority.
> Smith & Williamson Pension Consultancy Limited -
Independent
> Intermediary. Registered No. 3133226. Authorised and
> regulated by the Financial Services Authority.
> Smith & Williamson Fund Administration Limited,
Registered
> No. 1934644. Authorised and regulated by the Financial
> Services Authority.
> Smith & Williamson Limited - A member of Nexia
International.
>  Registered in England No. 4534022. Regulated by the
> Institute of Chartered Accountants in England &
Wales for a
> range of investment business activities.
> NCL Investments Limited, Registered No. 1913794.
> Member of the bond Stock Exchange authorised and
regulated
> by the Financial Services Authority.
>
> Registered Office: 25 Moorgate, bond EC2R 6AY
> Telephone: 020 7131 4000 http://www.smith.wi
lliamson.co.uk
>
> Nexia Smith & Williamson Audit Limited - A member
of Nexia
> International. Registered in England No. 4469576.
> Nexia Smith & Williamson Audit Limited is a company
> registered to carry out audit work and is regulated for
a
> range of investment activities by the Institute of
Chartered
> Accountants in England and Wales.  Smith &
Williamson Limited
> is a separate company that provides professional
resources
> and certain services to Nexia Smith & Williamson
Audit
> Limited under the terms of a formal agreement on an
arm's
> length basis.
>
> Registered Office: 25 Moorgate, bond EC2R 6AY
> Telephone: 020 7131 4000 http://www.nex
iasmith.williamson.co.uk
>
> All telephone calls are recorded for business purposes.
>
> ===================================
> This list is hosted by DevelopMentor  http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com

>

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )