all groups > dotnet drawing api > december 2005 >
You're in the

dotnet drawing api

group:

Question on the use of other webpages to generate temporary graphi


Question on the use of other webpages to generate temporary graphi B. Chernick
12/27/2005 6:35:02 AM
dotnet drawing api: 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 background,
Re: Question on the use of other webpages to generate temporary graphi Rick Mogstad
12/27/2005 8:54:44 AM
You simply change the Response.ContentType of the page you are using in the
ImageURL to be something like "image/jpeg" (or whatever MIME type you want
to return), and then save the image to the Response output stream.


[quoted text, click to view]

Re: Question on the use of other webpages to generate temporary gr B. Chernick
12/27/2005 9:35:38 AM
Not to be ungrateful but as one more accustomed to WinForms programming,
these are the kind of answers that made me post my question in the first
place. A day or two ago I had no idea at all what you are talking about and
I may not be entirely sure now. (And I got the page to work without any
reference to Reponse.ContentType. So perhaps I'm still missing something.)

The entire concept of using page links in ImageURLs does not seem to be
particularly well documented, and is not at all intuitive to us conventional
programmers.

[quoted text, click to view]
Re: Question on the use of other webpages to generate temporary gr Rick Mogstad
12/27/2005 11:22:19 AM
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]
Re: Question on the use of other webpages to generate temporary gr Jon M. Gohr
12/27/2005 1:07:30 PM
A quick google search on "asp.net generate images" will turn up about a ton
of very good information for you. From simple beginner tutorials to more
advanced examples.

Good luck.

[quoted text, click to view]

Re: Question on the use of other webpages to generate temporary gr B. Chernick
12/27/2005 4:48:02 PM
Again, thanks. (And again, no offense intended but a beginner might not
think of that particular search string and the sheer wealth of information is
likely to overwhelm him in any case. Maybe I should write a 'Dummies' book.
:-)

[quoted text, click to view]
Re: Question on the use of other webpages to generate temporary gr pamela fluente
12/29/2005 10:50:54 AM
Right!
If you do, let me know! I'll be your first reader!

-Pam
AddThis Social Bookmark Button