Results 1 to 11 of 11

Thread: ASP.NET and GDI+

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2002
    Posts
    20

    ASP.NET and GDI+

    Please,

    I need help
    What I want is:
    Using ASP.NET, VB.NET and GDI+in the same aspx PAGE to be able to display a simple text using a text box, a button and ??? to place to display the text.

    Thanks.

    Best regards.

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    What do you need GDI for? Just add a button, a textbiox, and a label. Set the label text..That is all.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2002
    Posts
    20

    ASP.NET GDI+

    I don't need a Label because with GDI+ I have infinite posibilities to do with a text .

    Best regards.

  4. #4
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    but it will be a lot more time consuming

  5. #5
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    and if many ppl go to ur page it will eat ur ram up all

  6. #6
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Is the text custom to every visitor? If it isn't, and is just changed every now and then, you might want to look into having the page create one graphic, store it on the server, and include that in the page. Whenever you want a new graphic created, you can schedule your app to do so, and overwrite the old one.

  7. #7
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    i think I see what you mean. Look into the Bitmap object. You can create a new Bitmap object, then use the graphics object DrawString to write text to it, and use Bitmap.Save to write it out to the response object. Here is a little mor ecomplex example

    Code:
    <%@ Page Language="VB" ContentType="image/jpeg" %>
    <%@ Import Namespace="System" %>
    <%@ Import Namespace="System.Drawing" %>
    <%@ Import Namespace="System.Drawing.Drawing2D" %>
    <%@ Import Namespace="System.Drawing.Imaging" %>
    
    <script language="VB" runat="server">
    
    Sub Page_Load(Sender as Object, E as EventArgs) 
    	Dim rnd As New Random()
    	Dim strText As String
    	' create a font
    	Dim fnt As Font = New Font("Arial", 12, FontStyle.Bold)
    	' Load a bitmap based image from a file
    	Dim newBitmap As Bitmap = New Bitmap(Server.MapPath("back.jpg"))
    	' This line is for creating a blank bitmap.
    	'Dim newBitmap As Bitmap = New Bitmap(400,50,PixelFormat.Format32bppARGB)
    	' Bind the Bitmap to the graphics object
    	Dim g As Graphics = Graphics.FromImage(newBitmap)
            
            ' Get a random number to choose what text to show
    	Select Case rnd.Next(5)
    		Case 1
    			strText = "The place to be!"
    		Case 2
    			strText = "What did you expect this message to say?"
    		Case 3
    			strText = "How about a nice hot cup of STFU!"
    		Case 4
    			strText = "Proving Monkeys CAN fly!"
    		Case Else
    			strText = "D'oh!"
    	End Select	
    	
    	' get the length of the string in pixels
    	Dim tempg As Graphics = Graphics.FromImage(new Bitmap(1,1))
    	Dim StringLength As Integer = tempg.MeasureString(strText,fnt).Width
    	tempg.Dispose
    	
    	g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias
    	g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias
    	
            ' Draw the string to the Graphics object. Subtract the strings pixel length from the 
            ' images width do determine postioning so that the lst character is always along the
            ' right edge of the image. Draw shadow first
            g.DrawString(strText, fnt, New SolidBrush(Color.Black), newBitmap.Width - StringLength, 65)
    	g.DrawString(strText, fnt, New SolidBrush(Color.LightSteelBlue), newBitmap.Width - StringLength - 2, 63)
            
            ' Get an array of ImageEncoders..array item 1 is Jpeg.
            Dim imgCodecs() As ImageCodecInfo  = ImageCodecInfo.GetImageEncoders()
    	
    	' Set quality Parameter for the Jpeg codec
    	Dim imgParams As EncoderParameters = New EncoderParameters(1)
    	Dim imgQuality As EncoderParameter = New EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 80)
    	' Set quality
    	imgParams.Param(0) = imgQuality
    	 
    	' Render BitMap Stream Back To Client
    	newBitmap.Save(Response.OutputStream,imgCodecs(1), imgParams)
    	fnt.Dispose()
    	g.Dispose()
    End Sub
    
    </script>
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  8. #8

    Thread Starter
    Junior Member
    Join Date
    May 2002
    Posts
    20

    ASP.NET and GDI+

    Because it seams that is not possible to write in the same page the input and the output.Please help me with 2 aspx pages
    First ask.aspx
    1.Text box = Your text.
    2. DropDownList = My size
    3 Radio Button = Shdow : Yes No
    3 .DropDownList = My TFF font
    4. Button = Submit
    Based on imput with GDI+ I will generate a GIF file.
    How can I submit this info in the second answer.aspx
    1.Label = My Size
    2.Label = My Font
    3. ?????? to use for display the gif file.
    4 Button = Back
    and when I am back I want to don't loose the info entered, the file created by the user to don't be destroyed by other user, and when I choose the final submit "This is what you want?" I need to drop all info in a database.
    Please try to help me !

  9. #9
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    i was just trying this ...i created a file pic.aspx and put the code there...puted the line of the picture a picture of the same folder of the aspx file...tryed but got an error about path2...*** does that mean?!?

  10. #10
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    how can i implement this?

    ........ in what file?
    \m/\m/

  11. #11
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    never mind..did it
    \m/\m/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width