Thanks for that, the:

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

Is exactly what I'm after.

Simon. 


-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Efran Cobisi
Sent: 16 October 2006 12:29
To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
Subject: Re: [ADVANCED-DOTNET] Image Response using ASP.Net

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 London
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 London Stock Exchange authorised and regulated by the
Financial Services Authority.
>
> Registered Office: 25 Moorgate, London EC2R 6AY
> Telephone: 020 7131 4000 http://www.smith.williamson.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, London EC2R 6AY
> Telephone: 020 7131 4000 http://www.nexiasmith.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

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

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

Reply via email to