RE: How can I get a bitmap into a WebControl?
- From: wawang@xxxxxxxxxxxxxxxxxxxx (Walter Wang [MSFT])
- Date: Mon, 11 Sep 2006 12:22:09 GMT
Hi Dave,
Based on my understanding, your situation is:
1) You currently have a WinForm control that can show image which is
dynamically generated on the fly;
2) You want to create a Web control that can also do the same thing;
3) Also, you don't want to create a WebForm to generate the image;
If I've misunderstood anything, please feel free to post here.
I suppose you already have working code that generates the image on the fly
which I also assume it's something like a Bitmap object. A Bitmap object
can save to a MemoryStream which again can write to ASP.NET Response
directly; for example:
Bitmap bitmap = <your code to generate the image on the fly>;
MemoryStream ms = new MemoryStream();
Response.Clear();
Response.ContentType = "image/jpeg";
bitmap.Save(ms, ImageFormat.Jpeg);
ms.WriteTo(Response.OutputStream);
Next, we need to create a ASP.NET custom control which takes some
properties and generate a resource url which uses a custom http handler to
generate the image:
public class MyDynamicImage: System.Web.UI.WebControls.Image
{
protected override void OnPreRender(EventArgs e)
{
...
ImageUrl = String.Format("~/__ImageGrabber.axd?p1={0}&p2={1}",
...);
}
}
The __ImageGrabber.axd is a custom http handler which is configured in
web.config like this:
<configuration>
<system.web>
<httpHandlers>
<add verb="GET" path="__ImageGrabber.axd"
type="MsdnMag.ImageGrabber" />
</httpHandlers>
</system.web>
</configuration>
The type MsdnMag.ImageGrabber is derived from IHttpHandler:
namespace MsdnMag
{
public class ImageGrabber : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
...
}
}
}
Then in your ASP.NET WebForm, just use the MyDynamicImage control and pass
required properties to generate different images.
For more complete code listing, please refer to following MSDN Magazine
article:
#Wicked Code: Power Programming Tips for ASP.NET 2.0
http://msdn.microsoft.com/msdnmag/issues/05/06/WickedCode/
Search the section named "Fetching Images from DataBases."
I hope this helps. Please feel free to post here if anything is unclear.
Sincerely,
Walter Wang (wawang@xxxxxxxxxxxxxxxxxxxx, remove 'online.')
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
.
- Follow-Ups:
- RE: How can I get a bitmap into a WebControl?
- From: Walter Wang [MSFT]
- RE: How can I get a bitmap into a WebControl?
- Prev by Date: Re: ASP/HTML Editor
- Next by Date: Re: Background thread in ASP.net
- Previous by thread: Re: How can I get a bitmap into a WebControl?
- Next by thread: RE: How can I get a bitmap into a WebControl?
- Index(es):
Relevant Pages
|
Loading