1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Image keeps getting ASPX extension

Discussion in 'C#' started by hirsch, Aug 2, 2006.

  1. #1
    Hello All,

    Could someone please tell me why my customized flyer will not let me right click the page and save it as a .jpg file? The form works fine and the flyer is displayed in the browser with the added text from the form, but when I try to save the image it saves it as an ASPX file only and even if you change the extension to jpeg it still does not open. Is there a way to fix this, or perhaps incorporate a save button that will let users save the customized flyer as a jpg? Thanks! Here's the code:

    <%@ Page Debug="True" %>
    <%@ Import Namespace="System.Drawing" %>
    <%@ Import Namespace="System.Drawing.Text" %>
    <%@ Import Namespace="System.Drawing.Imaging" %>
    <%@ Import Namespace="System.Drawing.Drawing2D" %>
    <script language="VB" runat="server">

    Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    If Page.IsPostBack Then
    ' load an existing bitmap
    Dim oCanvas As Bitmap = CType(Bitmap.FromFile(Server.MapPath("images\closeoutclocks.png")), Bitmap)
    Dim encoderParams as System.Drawing.Imaging.EncoderParameters = new System.Drawing.Imaging.EncoderParameters()
    Dim g As Graphics = Graphics.FromImage(oCanvas)
    g.SmoothingMode = SmoothingMode.HighQuality
    g.TextRenderingHint = TextRenderingHint.AntiAlias
    Dim oColor As System.Drawing.Color
    Dim tColor As String = Request("tColor")
    Select Case tColor
    Case "black"
    oColor = Color.Black
    Case "white"
    oColor = Color.White
    Case "navy"
    oColor = Color.Navy
    Case "orange"
    oColor = Color.Orange
    Case Else
    oColor = Color.Black
    End Select
    Dim oBrush As New SolidBrush(oColor)

    ' render some text
    Dim f1 As Font = New Font("Arial",22)
    Dim Company As String = Request("TextBox1")
    g.DrawString(Company, f1,oBrush ,5,5)

    Dim FullName As String = Request("TextBox2")
    g.DrawString(FullName,f1,oBrush ,5,35)

    Dim Telephone As String = Request("TextBox3")
    g.DrawString(Telephone,f1,oBrush ,300,5)

    Dim Email As String = Request("TextBox4")
    g.DrawString(Email,f1,oBrush ,300,35)

    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQua lityBicubic
    g.SmoothingMode = SmoothingMode.HighQuality
    Dim quality as long = 100
    Dim encoderParam as System.Drawing.Imaging.EncoderParameter = new System.Drawing.Imaging.EncoderParameter(System.Dra wing.Imaging.Encoder.Quality, quality)
    encoderParams.Param(0) = encoderParam

    Dim arrayICI as ImageCodecInfo() = ImageCodecInfo.GetImageEncoders()
    Dim jpegICI as ImageCodecInfo
    Dim x as integer
    for x = 0 to arrayICI.Length-1

    if (arrayICI(x).FormatDescription.Equals("JPEG")) then
    jpegICI = arrayICI(x)
    exit for
    end if

    next

    if not jpegICI is nothing then
    oCanvas.Save(Response.OutputStream, jpegICI, encoderParams)
    end if
    ' Now, we only need to send it to the client
    Response.ContentType = "image/jpeg"
    oCanvas.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.jpeg)


    ' Cleanup

    g.Dispose()
    oCanvas.Dispose()
    f1.Dispose()
    End If
    End Sub


    </script>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>E-Flyers</title>
    </head>
    <body>
    <form runat="server">
    <div>
    Company Name:
    <asp:TextBox runat="server" id="TextBox1"></asp:TextBox><br />
    Name:
    <asp:TextBox runat="server" id="TextBox2"></asp:TextBox><br />
    Telephone:
    <asp:TextBox runat="server" id="TextBox3"></asp:TextBox><br />
    Email:
    <asp:TextBox runat="server" id="TextBox4"></asp:TextBox><br />

    <asp:dropdownlist runat="server" id="tColor">
    <asp:ListItem Value="black">Black</asp:ListItem>
    <asp:ListItem Value="white">White</asp:ListItem>
    <asp:ListItem Value="navy">Navy</asp:ListItem>
    <asp:ListItem Value="orange">Orange</asp:ListItem>
    </asp:dropdownlist>
    </div>

    <asp:Button runat="Server" id="SubmitButton" Text="Generate Image" />
    SEMrush
    </form>

    </body>
    </html>
     
    hirsch, Aug 2, 2006 IP
    SEMrush
  2. Darrin

    Darrin Peon

    Messages:
    123
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This might be a silly question, but how are you trying to save the file? Are you right clicking the image in the browser and clicking Save As, or are you using the File menu of the browser and saving the whole page?

    This makes a difference in that if you are changing the output of the whole page to be just an image and nothing else, you can clear all the headers and just add the ones you need for content type and file name when prompted to save by the client. If it is a regular aspx page with an image on it, you would have to specifically try to save the image itself and not the whole page.
     
    Darrin, Aug 2, 2006 IP
  3. hirsch

    hirsch Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I am trying to right click the image and save it as jpeg, and its not working. Could it have anything to do with httphandlers?
     
    hirsch, Aug 3, 2006 IP
  4. hirsch

    hirsch Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I fixed of the errors but now I am getting a server run time error. Does anyone know why?

    <%@ Page Language="VB" Debug="True" %>
    <%@ Import Namespace="System.Drawing" %>
    <%@ Import Namespace="System.Drawing.Text" %>
    <%@ Import Namespace="System.Drawing.Imaging" %>
    <%
    Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    If Page.IsPostBack Then
    ' load an existing bitmap
    Dim oCanvas As Bitmap = CType(Bitmap.FromFile(Server.MapPath("images\closeoutclocks.png")), Bitmap)
    Dim encoderParams as System.Drawing.Imaging.EncoderParameters = new System.Drawing.Imaging.EncoderParameters()
    Dim g As Graphics = Graphics.FromImage(oCanvas)
    g.SmoothingMode = SmoothingMode.HighQuality
    g.TextRenderingHint = TextRenderingHint.AntiAlias
    Dim oColor As System.Drawing.Color
    Dim tColor As String = Request("tColor")
    Select Case tColor
    Case "black"
    oColor = Color.Black
    Case "white"
    oColor = Color.White
    Case "navy"
    oColor = Color.Navy
    Case "orange"
    oColor = Color.Orange
    Case Else
    oColor = Color.Black
    End Select
    Dim oBrush As New SolidBrush(oColor)

    ' render some text
    Dim f1 As Font = New Font("Arial",22)
    Dim Company As String = Request("TextBox1")
    g.DrawString(Company, f1,oBrush ,5,5)

    Dim FullName As String = Request("TextBox2")
    g.DrawString(FullName,f1,oBrush ,5,35)

    Dim Telephone As String = Request("TextBox3")
    g.DrawString(Telephone,f1,oBrush ,300,5)

    Dim Email As String = Request("TextBox4")
    g.DrawString(Email,f1,oBrush ,300,35)

    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
    g.SmoothingMode = SmoothingMode.HighQuality
    Dim quality as long = 100
    Dim encoderParam as System.Drawing.Imaging.EncoderParameter = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality)
    encoderParams.Param(0) = encoderParam

    Dim arrayICI as ImageCodecInfo() = ImageCodecInfo.GetImageEncoders()
    Dim jpegICI as ImageCodecInfo
    Dim x as integer
    for x = 0 to arrayICI.Length-1

    if (arrayICI(x).FormatDescription.Equals("JPEG")) then
    jpegICI = arrayICI(x)
    exit for
    end if

    next

    if not jpegICI is nothing then
    oCanvas.Save(Response.OutputStream, jpegICI, encoderParams)
    end if
    ' Now, we only need to send it to the client
    Response.ContentType = "image/jpeg"
    oCanvas.Save(Response.OutputStream, ImageFormat.Jpeg)

    ' Cleanup

    g.Dispose()
    oCanvas.Dispose()
    f1.Dispose()
    End If
    End Sub
    %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="image/jpeg" />

    </head>
    <body>
    <form method="post">

    <%
    runat="server"
    <div>
    Company Name:
    <asp:TextBox runat="server" id="TextBox1"></asp:TextBox><br />
    Name:
    <asp:TextBox runat="server" id="TextBox2"></asp:TextBox><br />
    Telephone:
    <asp:TextBox runat="server" id="TextBox3"></asp:TextBox><br />
    Email:
    <asp:TextBox runat="server" id="TextBox4"></asp:TextBox><br />

    <asp:dropdownlist runat="server" id="tColor">
    <asp:ListItem Value="black">Black</asp:ListItem>
    <asp:ListItem Value="white">White</asp:ListItem>
    <asp:ListItem Value="navy">Navy</asp:ListItem>
    <asp:ListItem Value="orange">Orange</asp:ListItem>
    </asp:dropdownlist>

    </div>

    <asp:Button runat="Server" id="SubmitButton" Text="Generate Image" />
    %>

    </form>

    </body>
    </html>
     
    hirsch, Aug 3, 2006 IP