Generally, you will want to do this in a "Handler" type file. This type =
of file doenst have the overhead that a normal page has, so it is a =
little bit more lightweight. Here is an example of that below. =20
<%@ WebHandler Language=3D"VB" Class=3D"ImgGen" %>
Imports System
Imports System.Web
Imports System.Drawing
Public Class ImgGen : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements =
IHttpHandler.ProcessRequest
context.Response.ContentType =3D "image/jpeg"
Dim aBitmap As New Bitmap(100, 100, Imaging.PixelFormat.Format32bppArgb)
Dim aBrush As New Drawing2D.LinearGradientBrush(New Point(0, 0), New =
Point(100, 100), Color.Red, Color.Blue)
Graphics.FromImage(aBitmap).FillRectangle(aBrush, 0, 0, 100, 100)
aBrush.Dispose()
aBitmap.Save(context.Response.OutputStream, Imaging.ImageFormat.Jpeg)
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements =
IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
The same code can be used in an ASPX page as well, if you wanted to use =
that as the source. Note that nothing else can be returned via the =
response object except valid image data.
Imports System.Drawing
Partial Class ImgGenInPage
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As =
System.EventArgs) Handles Me.Load
Dim aBitmap As New Bitmap(100, 100, Imaging.PixelFormat.Format32bppArgb)
Dim aBrush As New Drawing2D.LinearGradientBrush(New Point(0, 0), New =
Point(100, 100), Color.Red, Color.Blue)
Graphics.FromImage(aBitmap).FillRectangle(aBrush, 0, 0, 100, 100)
aBrush.Dispose()
aBitmap.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg)
End Sub
End Class
These examples were made using VS2005, so if you are using VS2003, just =
take the code out of it and paste it into VS2003. Some of the example =
will not work, since 2005 uses partial classes.
Let me know if you need more detailed examples.
-Rick
[quoted text, click to view] "B. Chernick" <BChernick@discussions.microsoft.com> wrote in message =
news:BDD0A767-9AEA-4D05-90F6-A2BF27652F81@microsoft.com...
> Not to be ungrateful but as one more accustomed to WinForms =
programming, =20
> these are the kind of answers that made me post my question in the =
first=20
> place. A day or two ago I had no idea at all what you are talking =
about and=20
> I may not be entirely sure now. (And I got the page to work without =
any=20
> reference to Reponse.ContentType. So perhaps I'm still missing =
something.) =20
>=20
> The entire concept of using page links in ImageURLs does not seem to =
be=20
> particularly well documented, and is not at all intuitive to us =
conventional=20
> programmers.
>=20
> "Rick Mogstad" wrote:
>=20
>> You simply change the Response.ContentType of the page you are using =
in the=20
>> ImageURL to be something like "image/jpeg" (or whatever MIME type you =
want=20
>> to return), and then save the image to the Response output stream.
>>=20
>>=20
>> "B. Chernick" <BChernick@discussions.microsoft.com> wrote in message=20
>> news:B3211044-6E74-4678-B21A-91EB8616F2D4@microsoft.com...
>> >I keep seeing references (from a number of MVPs among others) about =
how one
>> > can generate temporary graphics by pointing the ImageURL of a =
control to a
>> > web page rather than fixed location.
>> >
>> > Could someone give me a coherent example? So far I'm stumped. I =
really
>> > can't see how this scheme is supposed to work. Is the act of =
setting an
>> > ImageURL to a webpage enough to cause that webpage to run in the=20
>> > background,
>> > so to speak, and return an image?=20
>>=20
>>=20