Re: GDI+ Question

From: Kevin Spencer (kspencer_at_takempis.com)
Date: 08/13/04


Date: Fri, 13 Aug 2004 09:39:50 -0400

Using a class to dynamically-generate an image in a web application is
fairly simple. You create a class that can render an image, in a format that
can be viewed in a browser (e.g. JPG, GIF, PNG). That class has a method
similar to the one you have posted, which sets the Response.ContentType to
"image/jpg" (for example), and sends the image to the Response.OutputStream,
BUT doesn't include any other code for outputting text or any other data -
just the image. the reason for this? In an HTML document, images are
embedded by putting a URL to the image in the page. The browser then
requests that URL, and displays the image in the page according to the
markup in the HTML. IOW, the image file is a separate resource from the HTML
document. This makes sense, as HTML documents are pure text, and images are
pure binary data.

One the image class has been created, you can use it in an ASPX page to
render an image, by having the ASPX page call its method for sending the
image to the page. The page has no HTML, but only sends the image to the
browser. You can now use that page's URL as an image URL in a page, or, in
your case, an image control.

Sizing the image can best be done by the class that creates the image. It
can also be done on the client browser by setting the height and/or width
attributes or styles.

-- 
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"m3ckon" <anonymous@devdex.com> wrote in message
news:uz2gssRgEHA.3944@tk2msftngp13.phx.gbl...
> Hi there,
>
> was wondering if someone could help me.. I've been using GDI + to
> overlay some text onto an image and it's displaying without any
> problems.
>
> However, I wanted to put the output into an image control so that I
> could format it and manipulate it better.
>
> I'm using the code below: (can someone tell me how I can either resize
> the image I'm displaying or preferably how to add it to an image
> control?? (please)
>
>     Public Function DisplayImage(ByVal imagepath As String)
>         Dim strimagepath As String
>         Dim strimgheight As String
>         Dim strimgWidth As String
>         Response.Clear()
>
>         strimagepath = imagepath
>         Dim imgOutput As New Bitmap(strimagepath)
>         Dim g As Graphics = Graphics.FromImage(imgOutput)
>
>         g.DrawString("Copyright  2004", New Font("verdana", 16,
> FontStyle.Bold), SystemBrushes.WindowText, New PointF(2, 20))
>         imgOutput.Save(Response.OutputStream, ImageFormat.Jpeg) ' output
> to the user
>
>         ' tidy up
>         g.Dispose()
>         imgOutput.Dispose()
>         Response.End()
>     End Function
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!


Relevant Pages

  • Re: Simple question ??
    ... A web page is basically an HTML document. ... a technology that, at the most basic level, delivers HTML to a web browser. ... Internet Explorer, for example, can display Word documents, ... file format to a browser in its native state. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Simple question ??
    ... "Kevin Spencer" wrote: ... > A web page is basically an HTML document. ... > a technology that, at the most basic level, delivers HTML to a web browser. ... > file format to a browser in its native state. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Webclient.downloaddata
    ... what html the controls render is determined by the browser and since by ... neutral styles and html. ... > We are creating a web application using .NET which renders some reports. ...
    (microsoft.public.dotnet.framework.aspnet)
  • OT: HTML (WAS: MF having issues?)
    ... Even though he is only serving up static HTML pages and has no idea how they work or the fine points of the language, he has a very professional looking site that he built in about an hour. ... Though leading browser makers have been involved in the creation of web standards since W3C was formed, for many years compliance was observed in the breach. ... By releasing browsers that failed to uniformly support standards, manufacturers needlessly fragmented the Web, injuring designers, developers, users, and businesses alike. ... It is not enough for the website to simply "look okay" on any one particular browser; the HTML should be structurally correct, and the tags used for their semantics, rather than how they render in one particular browser. ...
    (comp.lang.cobol)
  • Re: italic, bold, etc. in Safari
    ... > visual browsers, through bold text, then use CSS to say so: ... Is there HTML logical markup for "example of foreign ... I specifically chose to do this because I figured that any browser, ... render any differently from regular text either. ...
    (comp.sys.mac.system)

Loading