SNB Solutions - Baja California Software Company
Welcome Guest Search | Active Topics | Log In | Register

Tag as favorite
Asp.net 2.0 generate image on the fly
stoian_bycovich
#1 Posted : Friday, February 26, 2010 2:51:59 PM

Rank: Administration

Medals:

Groups: Administrators
Joined: 1/2/2010
Posts: 79
Points: 10,237
Location: Cabo San Lucas

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Ok, this time I will be straight to work.

- aspx file

<asp:Image ID="Image1" runat="server" /> <!-- only one control to show the image -->

- aspx.vb file

' Importing needed name spaces

Imports System.Drawing.Imaging

Imports System.Drawing



Than in page load event I am generating the image and inserting text on it

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Creating bitmap and giving size width = 80 and heigh = 50 px

Dim Bitmap As Bitmap = New Bitmap(80, 50)
' Getting the bitmap to use it as graphic image but default the bitmap is black colored

Dim Graphic As Graphics = Graphics.FromImage(Bitmap)
' Creating shaped graphic image in this case rectangle and setting it's background color and size to

' fit the bitmap size

Graphic.FillRectangle(Brushes.Beige, 0, 0, 80, 50)

' Setting font name and size

Dim font As New Font("Arial", 13)
'Using the graphics drawstring property to set our customer text, font, font color and outstepping distances from the top left corner by x an y axis

Graphic.DrawString("my text", font, Brushes.Black, 10, 10)
'Saving the image and choosing its file format

Bitmap.Save(Server.MapPath("image.jpg"), ImageFormat.Jpeg)
'Setting the asp image control ImageUrl property to show us the generated image

Image1.ImageUrl = "~/image.jpg"

End Sub

Hope it helps

P.S.

Any questions are welcome

Ok, here is how to use it with http response



'Sending the image in http response

Response.ContentType = "image/jpeg"

'Saving the image and choosing its file format

Bitmap.Save(Response.OutputStream, ImageFormat.Jpeg)

You can do the formatting of html in your response stream

Regards

Best regards,
Stoyan Bukovich
Executive manager
SNB Solutions

Cell.: +52 6241 616969
E-mail: s.bucovich@snb-bg.com
Web: www.snb-bg.com
Sponsor  
 
Eannouncements.net SNB Solutions Eanuncios.net

Eannouncements.net the place for your announcement.

SNB Solutions - Software and computing services company.

Eanuncios.net el lugar para su anuncio.

Users browsing this topic
Guest
Tag as favorite
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.