Create Jpeg/Png programatically?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark B

    Create Jpeg/Png programatically?

    I want to display a pre-designed graphical 'performance badge' on certain
    webpages (round, about 2cm diameter) next to a salesperson's details.

    I have a function, fGetPerformance Grade(SalesPers onID as Long) as String to
    retrieve that salesperson's grade (e.g. A+, A, A-, B+, B... D). Also one
    other function, fGetMonthlySale s(SalesPersonID as Long) as String to get
    their sales figure, e.g. "$87K".

    I want web visitors to be able to click the badge to then be redirected to a
    sales low-level detail page.

    I want the performance badge to include the two figures inside it.

    I want the whole badge to be clickable so I am guessing the results of the
    functions can't be text else the cursor will appear when people click on the
    badge.

    My thought then is that the badge needs to be constructed programmically at
    run-time to incorporate those figures as pictures, or better still as part
    of the overall graphic.

    How would I do this? (I am a bit of a newbie to VB.NET)

    Thanks very much in advance.

  • Cor Ligthert[MVP]

    #2
    Re: Create Jpeg/Png programatically ?

    Mark-

    You mean something like this,



    Cor

    "Mark B" <none@none.coms chreef in bericht
    news:eJQMAg2xIH A.2184@TK2MSFTN GP02.phx.gbl...
    >I want to display a pre-designed graphical 'performance badge' on certain
    >webpages (round, about 2cm diameter) next to a salesperson's details.
    >
    I have a function, fGetPerformance Grade(SalesPers onID as Long) as String
    to retrieve that salesperson's grade (e.g. A+, A, A-, B+, B... D). Also
    one other function, fGetMonthlySale s(SalesPersonID as Long) as String to
    get their sales figure, e.g. "$87K".
    >
    I want web visitors to be able to click the badge to then be redirected to
    a sales low-level detail page.
    >
    I want the performance badge to include the two figures inside it.
    >
    I want the whole badge to be clickable so I am guessing the results of the
    functions can't be text else the cursor will appear when people click on
    the badge.
    >
    My thought then is that the badge needs to be constructed programmically
    at run-time to incorporate those figures as pictures, or better still as
    part of the overall graphic.
    >
    How would I do this? (I am a bit of a newbie to VB.NET)
    >
    Thanks very much in advance.

    Comment

    • Jialiang Ge [MSFT]

      #3
      Re: Create Jpeg/Png programatically ?

      Hello Mark,

      As Cor suggested, we can
      1. Create a Bitmap object
      'Create Bitmap object of specific width and height
      Dim Img As New Bitmap(intWidth , intHeight)

      2. Create the Graphics object using the Bitmap object
      'Obtain Graphics object to perform graphics opration
      Dim g As Graphics = Graphics.FromIm age(Img)

      3. Use the DrawString() method of the Graphics class to draw the figures in
      the badge
      'Use drawString method of the graphics object to write text on target bitmap
      g.DrawString("T est", New Font("Arial", 15, FontStyle.Bold) , _
      New SolidBrush(Colo r.Red), 25, 35)

      4. Save the image to a temporary directory:
      'Save this bitmap using its save method as .Tiff,.jpg or any other image
      ImgStamp.Save(Y ourPath &
      "\MyStamp.jpg", System.Drawing. Imaging.ImageFo rmat.Jpg))

      After then, display the image in your page.

      Regards,
      Jialiang Ge (jialge@online. microsoft.com, remove 'online.')
      Microsoft Online Community Support

      =============== =============== =============== ====
      Delighting our customers is our #1 priority. We welcome your comments and
      suggestions about how we can improve the support we provide to you. Please
      feel free to let my manager know what you think of the level of service
      provided. You can send feedback directly to my manager at:
      msdnmg@microsof t.com.

      This posting is provided "AS IS" with no warranties, and confers no rights.
      =============== =============== =============== ====

      Comment

      • Mark B

        #4
        Re: Create Jpeg/Png programatically ?

        An error message shows when I try and execute that code: "A generic error
        occurred in GDI+. "

        Description: An unhandled exception occurred during the execution of the
        current web request. Please review the stack trace for more information
        about the error and where it originated in the code.

        Exception Details: System.Runtime. InteropServices .ExternalExcept ion: A
        generic error occurred in GDI+.

        Source Error:

        Line 73: <td rowspan="2">g
        Line 74:
        Line 75: <% =SharedFunction s.fDisplayBadge ("28K", "B+")
        Line 76:
        Line 77:

        Source File: C:\Users\Mark\D ocuments\Visual Studio
        2008\WebSites\L ocalWeb\pages\v erify\group\def ault.aspx Line: 75

        Stack Trace:

        [ExternalExcepti on (0x80004005): A generic error occurred in GDI+.]
        System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo encoder,
        EncoderParamete rs encoderParams) +397778
        System.Drawing. Image.Save(Stri ng filename, ImageFormat format) +69
        SharedFunctions .fDisplayBadge( String strDot, String strGrade) +178
        ASP.pages_verif y_group_default _aspx.__Render_ _control1(HtmlT extWriter
        __w, Control parameterContai ner) in C:\Users\Mark\D ocuments\Visual Studio
        2008\WebSites\L ocalWeb\pages\v erify\group\def ault.aspx:75
        System.Web.UI.C ontrol.RenderCh ildrenInternal( HtmlTextWriter writer,
        ICollection children) +98
        System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer) +20
        System.Web.UI.P age.Render(Html TextWriter writer) +26
        System.Web.UI.C ontrol.RenderCo ntrolInternal(H tmlTextWriter writer,
        ControlAdapter adapter) +25
        System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer, ControlAdapter
        adapter) +121
        System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer) +22
        System.Web.UI.P age.ProcessRequ estMain(Boolean
        includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +2558

        --------------------------------------------------------------------------------
        Version Information: Microsoft .NET Framework Version:2.0.507 27.1433;
        ASP.NET Version:2.0.507 27.1433


        The code I used was:

        <% =SharedFunction s.fDisplayBadge ("28K", "B+") %>

        in an aspx page and:

        Shared Function fDisplayBadge(B yVal strDot As String, ByVal strGrade As
        String) As Object

        Dim Img As New Bitmap(100, 100)
        Dim g As Graphics = Graphics.FromIm age(Img)
        g.DrawString("T est", New Font("Arial", 15, FontStyle.Bold) , _
        New SolidBrush(Colo r.Red), 25, 35)
        Img.Save("C:\My Stamp.jpg", System.Drawing. Imaging.ImageFo rmat.Jpeg)

        End Function











        "Jialiang Ge [MSFT]" <jialge@online. microsoft.comwr ote in message
        news:fMRKO$4xIH A.4564@TK2MSFTN GHUB02.phx.gbl. ..
        Hello Mark,
        >
        As Cor suggested, we can
        1. Create a Bitmap object
        'Create Bitmap object of specific width and height
        Dim Img As New Bitmap(intWidth , intHeight)
        >
        2. Create the Graphics object using the Bitmap object
        'Obtain Graphics object to perform graphics opration
        Dim g As Graphics = Graphics.FromIm age(Img)
        >
        3. Use the DrawString() method of the Graphics class to draw the figures
        in
        the badge
        'Use drawString method of the graphics object to write text on target
        bitmap
        g.DrawString("T est", New Font("Arial", 15, FontStyle.Bold) , _
        New SolidBrush(Colo r.Red), 25, 35)
        >
        4. Save the image to a temporary directory:
        'Save this bitmap using its save method as .Tiff,.jpg or any other image
        ImgStamp.Save(Y ourPath &
        "\MyStamp.jpg", System.Drawing. Imaging.ImageFo rmat.Jpg))
        >
        After then, display the image in your page.
        >
        Regards,
        Jialiang Ge (jialge@online. microsoft.com, remove 'online.')
        Microsoft Online Community Support
        >
        =============== =============== =============== ====
        Delighting our customers is our #1 priority. We welcome your comments and
        suggestions about how we can improve the support we provide to you. Please
        feel free to let my manager know what you think of the level of service
        provided. You can send feedback directly to my manager at:
        msdnmg@microsof t.com.
        >
        This posting is provided "AS IS" with no warranties, and confers no
        rights.
        =============== =============== =============== ====
        >

        Comment

        • Jialiang Ge [MSFT]

          #5
          Re: Create Jpeg/Png programatically ?

          It is because the source stream was closed before we save it.
          You may have a look at this KB article

          or this thread that I once handled:


          Regards,
          Jialiang Ge (jialge@online. microsoft.com, remove 'online.')
          Microsoft Online Community Support

          =============== =============== =============== ====
          Delighting our customers is our #1 priority. We welcome your comments and
          suggestions about how we can improve the support we provide to you. Please
          feel free to let my manager know what you think of the level of service
          provided. You can send feedback directly to my manager at:
          msdnmg@microsof t.com.

          This posting is provided "AS IS" with no warranties, and confers no rights.
          =============== =============== =============== ====


          "Mark B" <none@none.comw rote in message
          news:uA%23o8j7x IHA.2068@TK2MSF TNGP05.phx.gbl. ..
          An error message shows when I try and execute that code: "A generic error
          occurred in GDI+. "
          >
          Description: An unhandled exception occurred during the execution of the
          current web request. Please review the stack trace for more information
          about the error and where it originated in the code.
          >
          Exception Details: System.Runtime. InteropServices .ExternalExcept ion: A
          generic error occurred in GDI+.
          >
          Source Error:
          >
          Line 73: <td rowspan="2">g
          Line 74:
          Line 75: <% =SharedFunction s.fDisplayBadge ("28K", "B+")
          Line 76:
          Line 77:
          >
          Source File: C:\Users\Mark\D ocuments\Visual Studio
          2008\WebSites\L ocalWeb\pages\v erify\group\def ault.aspx Line: 75
          >
          Stack Trace:
          >
          [ExternalExcepti on (0x80004005): A generic error occurred in GDI+.]
          System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo encoder,
          EncoderParamete rs encoderParams) +397778
          System.Drawing. Image.Save(Stri ng filename, ImageFormat format) +69
          SharedFunctions .fDisplayBadge( String strDot, String strGrade) +178
          ASP.pages_verif y_group_default _aspx.__Render_ _control1(HtmlT extWriter
          __w, Control parameterContai ner) in C:\Users\Mark\D ocuments\Visual Studio
          2008\WebSites\L ocalWeb\pages\v erify\group\def ault.aspx:75
          System.Web.UI.C ontrol.RenderCh ildrenInternal( HtmlTextWriter writer,
          ICollection children) +98
          System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer) +20
          System.Web.UI.P age.Render(Html TextWriter writer) +26
          System.Web.UI.C ontrol.RenderCo ntrolInternal(H tmlTextWriter writer,
          ControlAdapter adapter) +25
          System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer,
          ControlAdapter adapter) +121
          System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer) +22
          System.Web.UI.P age.ProcessRequ estMain(Boolean
          includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +2558
          >
          --------------------------------------------------------------------------------
          Version Information: Microsoft .NET Framework Version:2.0.507 27.1433;
          ASP.NET Version:2.0.507 27.1433
          >
          >
          The code I used was:
          >
          <% =SharedFunction s.fDisplayBadge ("28K", "B+") %>
          >
          in an aspx page and:
          >
          Shared Function fDisplayBadge(B yVal strDot As String, ByVal strGrade As
          String) As Object
          >
          Dim Img As New Bitmap(100, 100)
          Dim g As Graphics = Graphics.FromIm age(Img)
          g.DrawString("T est", New Font("Arial", 15, FontStyle.Bold) , _
          New SolidBrush(Colo r.Red), 25, 35)
          Img.Save("C:\My Stamp.jpg", System.Drawing. Imaging.ImageFo rmat.Jpeg)
          >
          End Function
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          "Jialiang Ge [MSFT]" <jialge@online. microsoft.comwr ote in message
          news:fMRKO$4xIH A.4564@TK2MSFTN GHUB02.phx.gbl. ..
          >Hello Mark,
          >>
          >As Cor suggested, we can
          >1. Create a Bitmap object
          >'Create Bitmap object of specific width and height
          >Dim Img As New Bitmap(intWidth , intHeight)
          >>
          >2. Create the Graphics object using the Bitmap object
          >'Obtain Graphics object to perform graphics opration
          >Dim g As Graphics = Graphics.FromIm age(Img)
          >>
          >3. Use the DrawString() method of the Graphics class to draw the figures
          >in
          >the badge
          >'Use drawString method of the graphics object to write text on target
          >bitmap
          >g.DrawString(" Test", New Font("Arial", 15, FontStyle.Bold) , _
          > New SolidBrush(Colo r.Red), 25, 35)
          >>
          >4. Save the image to a temporary directory:
          >'Save this bitmap using its save method as .Tiff,.jpg or any other image
          >ImgStamp.Save( YourPath &
          >"\MyStamp.jpg" ,System.Drawing .Imaging.ImageF ormat.Jpg))
          >>
          >After then, display the image in your page.
          >>
          >Regards,
          >Jialiang Ge (jialge@online. microsoft.com, remove 'online.')
          >Microsoft Online Community Support
          >>
          >============== =============== =============== =====
          >Delighting our customers is our #1 priority. We welcome your comments and
          >suggestions about how we can improve the support we provide to you.
          >Please
          >feel free to let my manager know what you think of the level of service
          >provided. You can send feedback directly to my manager at:
          >msdnmg@microsof t.com.
          >>
          >This posting is provided "AS IS" with no warranties, and confers no
          >rights.
          >============== =============== =============== =====
          >>
          >

          Comment

          • Mark B

            #6
            Re: Create Jpeg/Png programatically ?

            Hmm. I don't know where I can see where was it closed before save:

            Shared Function fDisplayBadge(B yVal strDot As String, ByVal strGrade As
            String) As Object
            >
            Dim Img As New Bitmap(100, 100)
            Dim g As Graphics = Graphics.FromIm age(Img)
            g.DrawString("T est", New Font("Arial", 15, FontStyle.Bold) , _
            New SolidBrush(Colo r.Red), 25, 35)
            Img.Save("C:\My Stamp.jpg", System.Drawing. Imaging.ImageFo rmat.Jpeg)
            >
            End Function





            "Jialiang Ge [MSFT]" <jialge@online. microsoft.comwr ote in message
            news:eEetuK8xIH A.5472@TK2MSFTN GP06.phx.gbl...
            It is because the source stream was closed before we save it.
            You may have a look at this KB article

            or this thread that I once handled:

            >
            Regards,
            Jialiang Ge (jialge@online. microsoft.com, remove 'online.')
            Microsoft Online Community Support
            >
            =============== =============== =============== ====
            Delighting our customers is our #1 priority. We welcome your comments and
            suggestions about how we can improve the support we provide to you. Please
            feel free to let my manager know what you think of the level of service
            provided. You can send feedback directly to my manager at:
            msdnmg@microsof t.com.
            >
            This posting is provided "AS IS" with no warranties, and confers no
            rights.
            =============== =============== =============== ====
            >
            >
            "Mark B" <none@none.comw rote in message
            news:uA%23o8j7x IHA.2068@TK2MSF TNGP05.phx.gbl. ..
            >An error message shows when I try and execute that code: "A generic error
            >occurred in GDI+. "
            >>
            >Description: An unhandled exception occurred during the execution of the
            >current web request. Please review the stack trace for more information
            >about the error and where it originated in the code.
            >>
            >Exception Details: System.Runtime. InteropServices .ExternalExcept ion: A
            >generic error occurred in GDI+.
            >>
            >Source Error:
            >>
            >Line 73: <td rowspan="2">g
            >Line 74:
            >Line 75: <% =SharedFunction s.fDisplayBadge ("28K", "B+")
            >Line 76:
            >Line 77:
            >>
            >Source File: C:\Users\Mark\D ocuments\Visual Studio
            >2008\WebSites\ LocalWeb\pages\ verify\group\de fault.aspx Line: 75
            >>
            >Stack Trace:
            >>
            >[ExternalExcepti on (0x80004005): A generic error occurred in GDI+.]
            > System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo encoder,
            >EncoderParamet ers encoderParams) +397778
            > System.Drawing. Image.Save(Stri ng filename, ImageFormat format) +69
            > SharedFunctions .fDisplayBadge( String strDot, String strGrade) +178
            > ASP.pages_verif y_group_default _aspx.__Render_ _control1(HtmlT extWriter
            >__w, Control parameterContai ner) in C:\Users\Mark\D ocuments\Visual Studio
            >2008\WebSites\ LocalWeb\pages\ verify\group\de fault.aspx:75
            > System.Web.UI.C ontrol.RenderCh ildrenInternal( HtmlTextWriter writer,
            >ICollection children) +98
            > System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer) +20
            > System.Web.UI.P age.Render(Html TextWriter writer) +26
            > System.Web.UI.C ontrol.RenderCo ntrolInternal(H tmlTextWriter writer,
            >ControlAdapt er adapter) +25
            > System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer,
            >ControlAdapt er adapter) +121
            > System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer) +22
            > System.Web.UI.P age.ProcessRequ estMain(Boolean
            >includeStagesB eforeAsyncPoint , Boolean includeStagesAf terAsyncPoint)
            >+2558
            >>
            >--------------------------------------------------------------------------------
            >Version Information: Microsoft .NET Framework Version:2.0.507 27.1433;
            >ASP.NET Version:2.0.507 27.1433
            >>
            >>
            >The code I used was:
            >>
            ><% =SharedFunction s.fDisplayBadge ("28K", "B+") %>
            >>
            >in an aspx page and:
            >>
            > Shared Function fDisplayBadge(B yVal strDot As String, ByVal strGrade As
            >String) As Object
            >>
            > Dim Img As New Bitmap(100, 100)
            > Dim g As Graphics = Graphics.FromIm age(Img)
            > g.DrawString("T est", New Font("Arial", 15, FontStyle.Bold) , _
            > New SolidBrush(Colo r.Red), 25, 35)
            > Img.Save("C:\My Stamp.jpg",
            >System.Drawing .Imaging.ImageF ormat.Jpeg)
            >>
            > End Function
            >>
            >>
            >>
            >>
            >>
            >>
            >>
            >>
            >>
            >>
            >>
            >"Jialiang Ge [MSFT]" <jialge@online. microsoft.comwr ote in message
            >news:fMRKO$4xI HA.4564@TK2MSFT NGHUB02.phx.gbl ...
            >>Hello Mark,
            >>>
            >>As Cor suggested, we can
            >>1. Create a Bitmap object
            >>'Create Bitmap object of specific width and height
            >>Dim Img As New Bitmap(intWidth , intHeight)
            >>>
            >>2. Create the Graphics object using the Bitmap object
            >>'Obtain Graphics object to perform graphics opration
            >>Dim g As Graphics = Graphics.FromIm age(Img)
            >>>
            >>3. Use the DrawString() method of the Graphics class to draw the figures
            >>in
            >>the badge
            >>'Use drawString method of the graphics object to write text on target
            >>bitmap
            >>g.DrawString( "Test", New Font("Arial", 15, FontStyle.Bold) , _
            >> New SolidBrush(Colo r.Red), 25, 35)
            >>>
            >>4. Save the image to a temporary directory:
            >>'Save this bitmap using its save method as .Tiff,.jpg or any other image
            >>ImgStamp.Save (YourPath &
            >>"\MyStamp.jpg ",System.Drawin g.Imaging.Image Format.Jpg))
            >>>
            >>After then, display the image in your page.
            >>>
            >>Regards,
            >>Jialiang Ge (jialge@online. microsoft.com, remove 'online.')
            >>Microsoft Online Community Support
            >>>
            >>============= =============== =============== ======
            >>Delighting our customers is our #1 priority. We welcome your comments
            >>and
            >>suggestions about how we can improve the support we provide to you.
            >>Please
            >>feel free to let my manager know what you think of the level of service
            >>provided. You can send feedback directly to my manager at:
            >>msdnmg@microsof t.com.
            >>>
            >>This posting is provided "AS IS" with no warranties, and confers no
            >>rights.
            >>============= =============== =============== ======
            >>>
            >>
            >
            >

            Comment

            • Mark B

              #7
              Re: Create Jpeg/Png programatically ?

              Never mind it must have been a file permissions issue:
              C:\Users\Mark\D ocuments\Visual Studio 2008\MyStamp.jp g rather than
              'C:\MyStamp.jpg ' worked.

              What if I want the text to overlay an existing graphic object (e.g. badge
              template jpeg)?


              "Mark B" <none@none.comw rote in message
              news:e%23i06f8x IHA.3384@TK2MSF TNGP03.phx.gbl. ..
              Hmm. I don't know where I can see where was it closed before save:
              >
              >
              > Shared Function fDisplayBadge(B yVal strDot As String, ByVal strGrade As
              >String) As Object
              >>
              > Dim Img As New Bitmap(100, 100)
              > Dim g As Graphics = Graphics.FromIm age(Img)
              > g.DrawString("T est", New Font("Arial", 15, FontStyle.Bold) , _
              > New SolidBrush(Colo r.Red), 25, 35)
              > Img.Save("C:\My Stamp.jpg",
              >System.Drawing .Imaging.ImageF ormat.Jpeg)
              >>
              > End Function
              >
              >
              >
              >
              >
              >
              "Jialiang Ge [MSFT]" <jialge@online. microsoft.comwr ote in message
              news:eEetuK8xIH A.5472@TK2MSFTN GP06.phx.gbl...
              >It is because the source stream was closed before we save it.
              >You may have a look at this KB article
              >http://support.microsoft.com/kb/814675/en-us
              >or this thread that I once handled:
              >http://www.microsoft.com/communities...r=us&sloc=&p=1
              >>
              >Regards,
              >Jialiang Ge (jialge@online. microsoft.com, remove 'online.')
              >Microsoft Online Community Support
              >>
              >============== =============== =============== =====
              >Delighting our customers is our #1 priority. We welcome your comments and
              >suggestions about how we can improve the support we provide to you.
              >Please feel free to let my manager know what you think of the level of
              >service provided. You can send feedback directly to my manager at:
              >msdnmg@microsof t.com.
              >>
              >This posting is provided "AS IS" with no warranties, and confers no
              >rights.
              >============== =============== =============== =====
              >>
              >>
              >"Mark B" <none@none.comw rote in message
              >news:uA%23o8j7 xIHA.2068@TK2MS FTNGP05.phx.gbl ...
              >>An error message shows when I try and execute that code: "A generic
              >>error occurred in GDI+. "
              >>>
              >>Description : An unhandled exception occurred during the execution of the
              >>current web request. Please review the stack trace for more information
              >>about the error and where it originated in the code.
              >>>
              >>Exception Details: System.Runtime. InteropServices .ExternalExcept ion: A
              >>generic error occurred in GDI+.
              >>>
              >>Source Error:
              >>>
              >>Line 73: <td rowspan="2">g
              >>Line 74:
              >>Line 75: <% =SharedFunction s.fDisplayBadge ("28K", "B+")
              >>Line 76:
              >>Line 77:
              >>>
              >>Source File: C:\Users\Mark\D ocuments\Visual Studio
              >>2008\WebSites \LocalWeb\pages \verify\group\d efault.aspx Line: 75
              >>>
              >>Stack Trace:
              >>>
              >>[ExternalExcepti on (0x80004005): A generic error occurred in GDI+.]
              >> System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo encoder,
              >>EncoderParame ters encoderParams) +397778
              >> System.Drawing. Image.Save(Stri ng filename, ImageFormat format) +69
              >> SharedFunctions .fDisplayBadge( String strDot, String strGrade) +178
              >> ASP.pages_verif y_group_default _aspx.__Render_ _control1(HtmlT extWriter
              >>__w, Control parameterContai ner) in C:\Users\Mark\D ocuments\Visual
              >>Studio 2008\WebSites\L ocalWeb\pages\v erify\group\def ault.aspx:75
              >> System.Web.UI.C ontrol.RenderCh ildrenInternal( HtmlTextWriter writer,
              >>ICollection children) +98
              >> System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer) +20
              >> System.Web.UI.P age.Render(Html TextWriter writer) +26
              >> System.Web.UI.C ontrol.RenderCo ntrolInternal(H tmlTextWriter writer,
              >>ControlAdapte r adapter) +25
              >> System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer,
              >>ControlAdapte r adapter) +121
              >> System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer) +22
              >> System.Web.UI.P age.ProcessRequ estMain(Boolean
              >>includeStages BeforeAsyncPoin t, Boolean includeStagesAf terAsyncPoint)
              >>+2558
              >>>
              >>--------------------------------------------------------------------------------
              >>Version Information: Microsoft .NET Framework Version:2.0.507 27.1433;
              >>ASP.NET Version:2.0.507 27.1433
              >>>
              >>>
              >>The code I used was:
              >>>
              >><% =SharedFunction s.fDisplayBadge ("28K", "B+") %>
              >>>
              >>in an aspx page and:
              >>>
              >> Shared Function fDisplayBadge(B yVal strDot As String, ByVal strGrade As
              >>String) As Object
              >>>
              >> Dim Img As New Bitmap(100, 100)
              >> Dim g As Graphics = Graphics.FromIm age(Img)
              >> g.DrawString("T est", New Font("Arial", 15, FontStyle.Bold) , _
              >> New SolidBrush(Colo r.Red), 25, 35)
              >> Img.Save("C:\My Stamp.jpg",
              >>System.Drawin g.Imaging.Image Format.Jpeg)
              >>>
              >> End Function
              >>>
              >>>
              >>>
              >>>
              >>>
              >>>
              >>>
              >>>
              >>>
              >>>
              >>>
              >>"Jialiang Ge [MSFT]" <jialge@online. microsoft.comwr ote in message
              >>news:fMRKO$4x IHA.4564@TK2MSF TNGHUB02.phx.gb l...
              >>>Hello Mark,
              >>>>
              >>>As Cor suggested, we can
              >>>1. Create a Bitmap object
              >>>'Create Bitmap object of specific width and height
              >>>Dim Img As New Bitmap(intWidth , intHeight)
              >>>>
              >>>2. Create the Graphics object using the Bitmap object
              >>>'Obtain Graphics object to perform graphics opration
              >>>Dim g As Graphics = Graphics.FromIm age(Img)
              >>>>
              >>>3. Use the DrawString() method of the Graphics class to draw the
              >>>figures in
              >>>the badge
              >>>'Use drawString method of the graphics object to write text on target
              >>>bitmap
              >>>g.DrawString ("Test", New Font("Arial", 15, FontStyle.Bold) , _
              >>> New SolidBrush(Colo r.Red), 25, 35)
              >>>>
              >>>4. Save the image to a temporary directory:
              >>>'Save this bitmap using its save method as .Tiff,.jpg or any other
              >>>image
              >>>ImgStamp.Sav e(YourPath &
              >>>"\MyStamp.jp g",System.Drawi ng.Imaging.Imag eFormat.Jpg))
              >>>>
              >>>After then, display the image in your page.
              >>>>
              >>>Regards,
              >>>Jialiang Ge (jialge@online. microsoft.com, remove 'online.')
              >>>Microsoft Online Community Support
              >>>>
              >>>============ =============== =============== =======
              >>>Delighting our customers is our #1 priority. We welcome your comments
              >>>and
              >>>suggestion s about how we can improve the support we provide to you.
              >>>Please
              >>>feel free to let my manager know what you think of the level of service
              >>>provided. You can send feedback directly to my manager at:
              >>>msdnmg@microsof t.com.
              >>>>
              >>>This posting is provided "AS IS" with no warranties, and confers no
              >>>rights.
              >>>============ =============== =============== =======
              >>>>
              >>>
              >>
              >>
              >

              Comment

              • Patrice

                #8
                Re: Create Jpeg/Png programatically ?

                Does it fail on the first run or does it works before failing ?

                1) Always call dispose when exposed (g.dispose and img.dispose) else
                unmanaged resources could be kept alive and as you always write to the same
                file
                2) the function doesn't return anything
                3) a web page usually display an image fetched as an external resource
                though even returning somethying directly in the html page won"t work
                4) strDot,strGrade are not used (I assume you are in a testing phase)

                You could make the page refers to another ASPX page (or better a handler)
                that would stream the image content instead of refering to a real image
                file.
                The browser won't care it will see the page returns the appropriate content
                type and then takes whetever is rendered by the page as an image (this is if
                you want to render this image on the fly, not sure what you are trying to
                do)...


                --
                Patrice

                "Mark B" <none@none.co ma écrit dans le message de groupe de discussion :
                e#i06f8xIHA.338 4@TK2MSFTNGP03. phx.gbl...
                Hmm. I don't know where I can see where was it closed before save:
                >
                >
                > Shared Function fDisplayBadge(B yVal strDot As String, ByVal strGrade As
                >String) As Object
                >>
                > Dim Img As New Bitmap(100, 100)
                > Dim g As Graphics = Graphics.FromIm age(Img)
                > g.DrawString("T est", New Font("Arial", 15, FontStyle.Bold) , _
                > New SolidBrush(Colo r.Red), 25, 35)
                > Img.Save("C:\My Stamp.jpg",
                >System.Drawing .Imaging.ImageF ormat.Jpeg)
                >>
                > End Function
                >
                >
                >
                >
                >
                >
                "Jialiang Ge [MSFT]" <jialge@online. microsoft.comwr ote in message
                news:eEetuK8xIH A.5472@TK2MSFTN GP06.phx.gbl...
                >It is because the source stream was closed before we save it.
                >You may have a look at this KB article
                >http://support.microsoft.com/kb/814675/en-us
                >or this thread that I once handled:
                >http://www.microsoft.com/communities...r=us&sloc=&p=1
                >>
                >Regards,
                >Jialiang Ge (jialge@online. microsoft.com, remove 'online.')
                >Microsoft Online Community Support
                >>
                >============== =============== =============== =====
                >Delighting our customers is our #1 priority. We welcome your comments and
                >suggestions about how we can improve the support we provide to you.
                >Please feel free to let my manager know what you think of the level of
                >service provided. You can send feedback directly to my manager at:
                >msdnmg@microsof t.com.
                >>
                >This posting is provided "AS IS" with no warranties, and confers no
                >rights.
                >============== =============== =============== =====
                >>
                >>
                >"Mark B" <none@none.comw rote in message
                >news:uA%23o8j7 xIHA.2068@TK2MS FTNGP05.phx.gbl ...
                >>An error message shows when I try and execute that code: "A generic
                >>error occurred in GDI+. "
                >>>
                >>Description : An unhandled exception occurred during the execution of the
                >>current web request. Please review the stack trace for more information
                >>about the error and where it originated in the code.
                >>>
                >>Exception Details: System.Runtime. InteropServices .ExternalExcept ion: A
                >>generic error occurred in GDI+.
                >>>
                >>Source Error:
                >>>
                >>Line 73: <td rowspan="2">g
                >>Line 74:
                >>Line 75: <% =SharedFunction s.fDisplayBadge ("28K", "B+")
                >>Line 76:
                >>Line 77:
                >>>
                >>Source File: C:\Users\Mark\D ocuments\Visual Studio
                >>2008\WebSites \LocalWeb\pages \verify\group\d efault.aspx Line: 75
                >>>
                >>Stack Trace:
                >>>
                >>[ExternalExcepti on (0x80004005): A generic error occurred in GDI+.]
                >> System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo encoder,
                >>EncoderParame ters encoderParams) +397778
                >> System.Drawing. Image.Save(Stri ng filename, ImageFormat format) +69
                >> SharedFunctions .fDisplayBadge( String strDot, String strGrade) +178
                >> ASP.pages_verif y_group_default _aspx.__Render_ _control1(HtmlT extWriter
                >>__w, Control parameterContai ner) in C:\Users\Mark\D ocuments\Visual
                >>Studio 2008\WebSites\L ocalWeb\pages\v erify\group\def ault.aspx:75
                >> System.Web.UI.C ontrol.RenderCh ildrenInternal( HtmlTextWriter writer,
                >>ICollection children) +98
                >> System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer) +20
                >> System.Web.UI.P age.Render(Html TextWriter writer) +26
                >> System.Web.UI.C ontrol.RenderCo ntrolInternal(H tmlTextWriter writer,
                >>ControlAdapte r adapter) +25
                >> System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer,
                >>ControlAdapte r adapter) +121
                >> System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer) +22
                >> System.Web.UI.P age.ProcessRequ estMain(Boolean
                >>includeStages BeforeAsyncPoin t, Boolean includeStagesAf terAsyncPoint)
                >>+2558
                >>>
                >>--------------------------------------------------------------------------------
                >>Version Information: Microsoft .NET Framework Version:2.0.507 27.1433;
                >>ASP.NET Version:2.0.507 27.1433
                >>>
                >>>
                >>The code I used was:
                >>>
                >><% =SharedFunction s.fDisplayBadge ("28K", "B+") %>
                >>>
                >>in an aspx page and:
                >>>
                >> Shared Function fDisplayBadge(B yVal strDot As String, ByVal strGrade As
                >>String) As Object
                >>>
                >> Dim Img As New Bitmap(100, 100)
                >> Dim g As Graphics = Graphics.FromIm age(Img)
                >> g.DrawString("T est", New Font("Arial", 15, FontStyle.Bold) , _
                >> New SolidBrush(Colo r.Red), 25, 35)
                >> Img.Save("C:\My Stamp.jpg",
                >>System.Drawin g.Imaging.Image Format.Jpeg)
                >>>
                >> End Function
                >>>
                >>>
                >>>
                >>>
                >>>
                >>>
                >>>
                >>>
                >>>
                >>>
                >>>
                >>"Jialiang Ge [MSFT]" <jialge@online. microsoft.comwr ote in message
                >>news:fMRKO$4x IHA.4564@TK2MSF TNGHUB02.phx.gb l...
                >>>Hello Mark,
                >>>>
                >>>As Cor suggested, we can
                >>>1. Create a Bitmap object
                >>>'Create Bitmap object of specific width and height
                >>>Dim Img As New Bitmap(intWidth , intHeight)
                >>>>
                >>>2. Create the Graphics object using the Bitmap object
                >>>'Obtain Graphics object to perform graphics opration
                >>>Dim g As Graphics = Graphics.FromIm age(Img)
                >>>>
                >>>3. Use the DrawString() method of the Graphics class to draw the
                >>>figures in
                >>>the badge
                >>>'Use drawString method of the graphics object to write text on target
                >>>bitmap
                >>>g.DrawString ("Test", New Font("Arial", 15, FontStyle.Bold) , _
                >>> New SolidBrush(Colo r.Red), 25, 35)
                >>>>
                >>>4. Save the image to a temporary directory:
                >>>'Save this bitmap using its save method as .Tiff,.jpg or any other
                >>>image
                >>>ImgStamp.Sav e(YourPath &
                >>>"\MyStamp.jp g",System.Drawi ng.Imaging.Imag eFormat.Jpg))
                >>>>
                >>>After then, display the image in your page.
                >>>>
                >>>Regards,
                >>>Jialiang Ge (jialge@online. microsoft.com, remove 'online.')
                >>>Microsoft Online Community Support
                >>>>
                >>>============ =============== =============== =======
                >>>Delighting our customers is our #1 priority. We welcome your comments
                >>>and
                >>>suggestion s about how we can improve the support we provide to you.
                >>>Please
                >>>feel free to let my manager know what you think of the level of service
                >>>provided. You can send feedback directly to my manager at:
                >>>msdnmg@microsof t.com.
                >>>>
                >>>This posting is provided "AS IS" with no warranties, and confers no
                >>>rights.
                >>>============ =============== =============== =======
                >>>>
                >>>
                >>
                >>
                >

                Comment

                • =?ISO-8859-1?Q?G=F6ran_Andersson?=

                  #9
                  Re: Create Jpeg/Png programatically ?

                  Mark B wrote:
                  I want the performance badge to include the two figures inside it.
                  >
                  I want the whole badge to be clickable so I am guessing the results of
                  the functions can't be text else the cursor will appear when people
                  click on the badge.
                  >
                  My thought then is that the badge needs to be constructed programmically
                  at run-time to incorporate those figures as pictures, or better still as
                  part of the overall graphic.
                  Why make it so very complicated? A browser is capable of displaying text
                  on top of an image, and also capable of showing a pointer cursor instead
                  of a text cursor.

                  Example:

                  <a href="detailspa ge.html" target="_blank"
                  style="display: block;width:50p x;height:50px;b ackground:url(b adge.gif);text-align:center;li ne-height:25px;cur sor:pointer;">A +<br/>$87K</a>

                  --
                  Göran Andersson
                  _____
                  Göran Anderssons privata hemsida.

                  Comment

                  • Mark B

                    #10
                    Re: Create Jpeg/Png programatically ?

                    If they click on the text, will it re-direct to a URL like it would if they
                    clicked on the image?


                    "Göran Andersson" <guffa@guffa.co mwrote in message
                    news:eyANK%23%2 3xIHA.1768@TK2M SFTNGP03.phx.gb l...
                    Mark B wrote:
                    >I want the performance badge to include the two figures inside it.
                    >>
                    >I want the whole badge to be clickable so I am guessing the results of
                    >the functions can't be text else the cursor will appear when people click
                    >on the badge.
                    >>
                    >My thought then is that the badge needs to be constructed programmically
                    >at run-time to incorporate those figures as pictures, or better still as
                    >part of the overall graphic.
                    >
                    Why make it so very complicated? A browser is capable of displaying text
                    on top of an image, and also capable of showing a pointer cursor instead
                    of a text cursor.
                    >
                    Example:
                    >
                    <a href="detailspa ge.html" target="_blank"
                    style="display: block;width:50p x;height:50px;b ackground:url(b adge.gif);text-align:center;li ne-height:25px;cur sor:pointer;">A +<br/>$87K</a>
                    >
                    --
                    Göran Andersson
                    _____
                    http://www.guffa.com

                    Comment

                    • =?ISO-8859-1?Q?G=F6ran_Andersson?=

                      #11
                      Re: Create Jpeg/Png programatically ?

                      Mark B wrote:
                      If they click on the text, will it re-direct to a URL like it would if
                      they clicked on the image?
                      In my example there is no separate image element and separate text
                      elements. The link contains the text and has a background image. There
                      is no difference if you click on the part of the link where there is
                      text or the part where there is just the background image.

                      --
                      Göran Andersson
                      _____
                      Göran Anderssons privata hemsida.

                      Comment

                      • Mark B

                        #12
                        Re: Create Jpeg/Png programatically ?

                        That all works OK now.

                        Now what about if I want to allow other webmasters to have our dynamic
                        salesperson performance badges on their websites?

                        I could pass them the salesperson ID number but what else would I need to
                        have them include in their HTML? I want them to be able to 'click-to-verify'
                        to be taken to the salesperson's details page.






                        "Jialiang Ge [MSFT]" <jialge@online. microsoft.comwr ote in message
                        news:eEetuK8xIH A.5472@TK2MSFTN GP06.phx.gbl...
                        It is because the source stream was closed before we save it.
                        You may have a look at this KB article

                        or this thread that I once handled:

                        >
                        Regards,
                        Jialiang Ge (jialge@online. microsoft.com, remove 'online.')
                        Microsoft Online Community Support
                        >
                        =============== =============== =============== ====
                        Delighting our customers is our #1 priority. We welcome your comments and
                        suggestions about how we can improve the support we provide to you. Please
                        feel free to let my manager know what you think of the level of service
                        provided. You can send feedback directly to my manager at:
                        msdnmg@microsof t.com.
                        >
                        This posting is provided "AS IS" with no warranties, and confers no
                        rights.
                        =============== =============== =============== ====
                        >
                        >
                        "Mark B" <none@none.comw rote in message
                        news:uA%23o8j7x IHA.2068@TK2MSF TNGP05.phx.gbl. ..
                        >An error message shows when I try and execute that code: "A generic error
                        >occurred in GDI+. "
                        >>
                        >Description: An unhandled exception occurred during the execution of the
                        >current web request. Please review the stack trace for more information
                        >about the error and where it originated in the code.
                        >>
                        >Exception Details: System.Runtime. InteropServices .ExternalExcept ion: A
                        >generic error occurred in GDI+.
                        >>
                        >Source Error:
                        >>
                        >Line 73: <td rowspan="2">g
                        >Line 74:
                        >Line 75: <% =SharedFunction s.fDisplayBadge ("28K", "B+")
                        >Line 76:
                        >Line 77:
                        >>
                        >Source File: C:\Users\Mark\D ocuments\Visual Studio
                        >2008\WebSites\ LocalWeb\pages\ verify\group\de fault.aspx Line: 75
                        >>
                        >Stack Trace:
                        >>
                        >[ExternalExcepti on (0x80004005): A generic error occurred in GDI+.]
                        > System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo encoder,
                        >EncoderParamet ers encoderParams) +397778
                        > System.Drawing. Image.Save(Stri ng filename, ImageFormat format) +69
                        > SharedFunctions .fDisplayBadge( String strDot, String strGrade) +178
                        > ASP.pages_verif y_group_default _aspx.__Render_ _control1(HtmlT extWriter
                        >__w, Control parameterContai ner) in C:\Users\Mark\D ocuments\Visual Studio
                        >2008\WebSites\ LocalWeb\pages\ verify\group\de fault.aspx:75
                        > System.Web.UI.C ontrol.RenderCh ildrenInternal( HtmlTextWriter writer,
                        >ICollection children) +98
                        > System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer) +20
                        > System.Web.UI.P age.Render(Html TextWriter writer) +26
                        > System.Web.UI.C ontrol.RenderCo ntrolInternal(H tmlTextWriter writer,
                        >ControlAdapt er adapter) +25
                        > System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer,
                        >ControlAdapt er adapter) +121
                        > System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer) +22
                        > System.Web.UI.P age.ProcessRequ estMain(Boolean
                        >includeStagesB eforeAsyncPoint , Boolean includeStagesAf terAsyncPoint)
                        >+2558
                        >>
                        >--------------------------------------------------------------------------------
                        >Version Information: Microsoft .NET Framework Version:2.0.507 27.1433;
                        >ASP.NET Version:2.0.507 27.1433
                        >>
                        >>
                        >The code I used was:
                        >>
                        ><% =SharedFunction s.fDisplayBadge ("28K", "B+") %>
                        >>
                        >in an aspx page and:
                        >>
                        > Shared Function fDisplayBadge(B yVal strDot As String, ByVal strGrade As
                        >String) As Object
                        >>
                        > Dim Img As New Bitmap(100, 100)
                        > Dim g As Graphics = Graphics.FromIm age(Img)
                        > g.DrawString("T est", New Font("Arial", 15, FontStyle.Bold) , _
                        > New SolidBrush(Colo r.Red), 25, 35)
                        > Img.Save("C:\My Stamp.jpg",
                        >System.Drawing .Imaging.ImageF ormat.Jpeg)
                        >>
                        > End Function
                        >>
                        >>
                        >>
                        >>
                        >>
                        >>
                        >>
                        >>
                        >>
                        >>
                        >>
                        >"Jialiang Ge [MSFT]" <jialge@online. microsoft.comwr ote in message
                        >news:fMRKO$4xI HA.4564@TK2MSFT NGHUB02.phx.gbl ...
                        >>Hello Mark,
                        >>>
                        >>As Cor suggested, we can
                        >>1. Create a Bitmap object
                        >>'Create Bitmap object of specific width and height
                        >>Dim Img As New Bitmap(intWidth , intHeight)
                        >>>
                        >>2. Create the Graphics object using the Bitmap object
                        >>'Obtain Graphics object to perform graphics opration
                        >>Dim g As Graphics = Graphics.FromIm age(Img)
                        >>>
                        >>3. Use the DrawString() method of the Graphics class to draw the figures
                        >>in
                        >>the badge
                        >>'Use drawString method of the graphics object to write text on target
                        >>bitmap
                        >>g.DrawString( "Test", New Font("Arial", 15, FontStyle.Bold) , _
                        >> New SolidBrush(Colo r.Red), 25, 35)
                        >>>
                        >>4. Save the image to a temporary directory:
                        >>'Save this bitmap using its save method as .Tiff,.jpg or any other image
                        >>ImgStamp.Save (YourPath &
                        >>"\MyStamp.jpg ",System.Drawin g.Imaging.Image Format.Jpg))
                        >>>
                        >>After then, display the image in your page.
                        >>>
                        >>Regards,
                        >>Jialiang Ge (jialge@online. microsoft.com, remove 'online.')
                        >>Microsoft Online Community Support
                        >>>
                        >>============= =============== =============== ======
                        >>Delighting our customers is our #1 priority. We welcome your comments
                        >>and
                        >>suggestions about how we can improve the support we provide to you.
                        >>Please
                        >>feel free to let my manager know what you think of the level of service
                        >>provided. You can send feedback directly to my manager at:
                        >>msdnmg@microsof t.com.
                        >>>
                        >>This posting is provided "AS IS" with no warranties, and confers no
                        >>rights.
                        >>============= =============== =============== ======
                        >>>
                        >>
                        >
                        >

                        Comment

                        Working...