469,592 Members | 2,032 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

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, fGetPerformanceGrade(SalesPersonID as Long) as String to
retrieve that salesperson's grade (e.g. A+, A, A-, B+, B... D). Also one
other function, fGetMonthlySales(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.

Jun 27 '08 #1
11 4910
Mark-

You mean something like this,

http://www.vb-tips.com/ServerClock.aspx

Cor

"Mark B" <no**@none.comschreef in bericht
news:eJ**************@TK2MSFTNGP02.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, fGetPerformanceGrade(SalesPersonID as Long) as String
to retrieve that salesperson's grade (e.g. A+, A, A-, B+, B... D). Also
one other function, fGetMonthlySales(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.
Jun 27 '08 #2
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.FromImage(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(Color.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.ImageFormat. Jpg))

After then, display the image in your page.

Regards,
Jialiang Ge (ji****@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:
ms****@microsoft.com.

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

Jun 27 '08 #3
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.ExternalException: A
generic error occurred in GDI+.

Source Error:

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

Source File: C:\Users\Mark\Documents\Visual Studio
2008\WebSites\LocalWeb\pages\verify\group\default. aspx Line: 75

Stack Trace:

[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder,
EncoderParameters encoderParams) +397778
System.Drawing.Image.Save(String filename, ImageFormat format) +69
SharedFunctions.fDisplayBadge(String strDot, String strGrade) +178
ASP.pages_verify_group_default_aspx.__Render__cont rol1(HtmlTextWriter
__w, Control parameterContainer) in C:\Users\Mark\Documents\Visual Studio
2008\WebSites\LocalWeb\pages\verify\group\default. aspx:75
System.Web.UI.Control.RenderChildrenInternal(HtmlT extWriter writer,
ICollection children) +98
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +20
System.Web.UI.Page.Render(HtmlTextWriter writer) +26
System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer,
ControlAdapter adapter) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter
adapter) +121
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2558

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.1433;
ASP.NET Version:2.0.50727.1433
The code I used was:

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

in an aspx page and:

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

Dim Img As New Bitmap(100, 100)
Dim g As Graphics = Graphics.FromImage(Img)
g.DrawString("Test", New Font("Arial", 15, FontStyle.Bold), _
New SolidBrush(Color.Red), 25, 35)
Img.Save("C:\MyStamp.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)

End Function



"Jialiang Ge [MSFT]" <ji****@online.microsoft.comwrote in message
news:fM**************@TK2MSFTNGHUB02.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.FromImage(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(Color.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.ImageFormat. Jpg))

After then, display the image in your page.

Regards,
Jialiang Ge (ji****@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:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no
rights.
=================================================
Jun 27 '08 #4
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 (ji****@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:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
"Mark B" <no**@none.comwrote in message
news:uA****************@TK2MSFTNGP05.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.ExternalException: A
generic error occurred in GDI+.

Source Error:

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

Source File: C:\Users\Mark\Documents\Visual Studio
2008\WebSites\LocalWeb\pages\verify\group\default. aspx Line: 75

Stack Trace:

[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder,
EncoderParameters encoderParams) +397778
System.Drawing.Image.Save(String filename, ImageFormat format) +69
SharedFunctions.fDisplayBadge(String strDot, String strGrade) +178
ASP.pages_verify_group_default_aspx.__Render__cont rol1(HtmlTextWriter
__w, Control parameterContainer) in C:\Users\Mark\Documents\Visual Studio
2008\WebSites\LocalWeb\pages\verify\group\default. aspx:75
System.Web.UI.Control.RenderChildrenInternal(HtmlT extWriter writer,
ICollection children) +98
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +20
System.Web.UI.Page.Render(HtmlTextWriter writer) +26
System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer,
ControlAdapter adapter) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
ControlAdapter adapter) +121
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2558

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.1433;
ASP.NET Version:2.0.50727.1433
The code I used was:

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

in an aspx page and:

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

Dim Img As New Bitmap(100, 100)
Dim g As Graphics = Graphics.FromImage(Img)
g.DrawString("Test", New Font("Arial", 15, FontStyle.Bold), _
New SolidBrush(Color.Red), 25, 35)
Img.Save("C:\MyStamp.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)

End Function



"Jialiang Ge [MSFT]" <ji****@online.microsoft.comwrote in message
news:fM**************@TK2MSFTNGHUB02.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.FromImage(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(Color.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.ImageFormat .Jpg))

After then, display the image in your page.

Regards,
Jialiang Ge (ji****@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:
ms****@microsoft.com.

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

Jun 27 '08 #5
Hmm. I don't know where I can see where was it closed before save:

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

Dim Img As New Bitmap(100, 100)
Dim g As Graphics = Graphics.FromImage(Img)
g.DrawString("Test", New Font("Arial", 15, FontStyle.Bold), _
New SolidBrush(Color.Red), 25, 35)
Img.Save("C:\MyStamp.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)

End Function



"Jialiang Ge [MSFT]" <ji****@online.microsoft.comwrote in message
news:eE**************@TK2MSFTNGP06.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 (ji****@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:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no
rights.
=================================================
"Mark B" <no**@none.comwrote in message
news:uA****************@TK2MSFTNGP05.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.ExternalException: A
generic error occurred in GDI+.

Source Error:

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

Source File: C:\Users\Mark\Documents\Visual Studio
2008\WebSites\LocalWeb\pages\verify\group\default .aspx Line: 75

Stack Trace:

[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder,
EncoderParameters encoderParams) +397778
System.Drawing.Image.Save(String filename, ImageFormat format) +69
SharedFunctions.fDisplayBadge(String strDot, String strGrade) +178
ASP.pages_verify_group_default_aspx.__Render__cont rol1(HtmlTextWriter
__w, Control parameterContainer) in C:\Users\Mark\Documents\Visual Studio
2008\WebSites\LocalWeb\pages\verify\group\default .aspx:75
System.Web.UI.Control.RenderChildrenInternal(HtmlT extWriter writer,
ICollection children) +98
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +20
System.Web.UI.Page.Render(HtmlTextWriter writer) +26
System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer,
ControlAdapter adapter) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
ControlAdapter adapter) +121
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+2558

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.1433;
ASP.NET Version:2.0.50727.1433
The code I used was:

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

in an aspx page and:

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

Dim Img As New Bitmap(100, 100)
Dim g As Graphics = Graphics.FromImage(Img)
g.DrawString("Test", New Font("Arial", 15, FontStyle.Bold), _
New SolidBrush(Color.Red), 25, 35)
Img.Save("C:\MyStamp.jpg",
System.Drawing.Imaging.ImageFormat.Jpeg)

End Function



"Jialiang Ge [MSFT]" <ji****@online.microsoft.comwrote in message
news:fM**************@TK2MSFTNGHUB02.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.FromImage(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(Color.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.ImageForma t.Jpg))

After then, display the image in your page.

Regards,
Jialiang Ge (ji****@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:
ms****@microsoft.com.

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

Jun 27 '08 #6
Never mind it must have been a file permissions issue:
C:\Users\Mark\Documents\Visual Studio 2008\MyStamp.jpg 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" <no**@none.comwrote in message
news:e%****************@TK2MSFTNGP03.phx.gbl...
Hmm. I don't know where I can see where was it closed before save:

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

Dim Img As New Bitmap(100, 100)
Dim g As Graphics = Graphics.FromImage(Img)
g.DrawString("Test", New Font("Arial", 15, FontStyle.Bold), _
New SolidBrush(Color.Red), 25, 35)
Img.Save("C:\MyStamp.jpg",
System.Drawing.Imaging.ImageFormat.Jpeg)

End Function


"Jialiang Ge [MSFT]" <ji****@online.microsoft.comwrote in message
news:eE**************@TK2MSFTNGP06.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 (ji****@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:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no
rights.
=============================================== ==
"Mark B" <no**@none.comwrote in message
news:uA****************@TK2MSFTNGP05.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.ExternalException: A
generic error occurred in GDI+.

Source Error:

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

Source File: C:\Users\Mark\Documents\Visual Studio
2008\WebSites\LocalWeb\pages\verify\group\defaul t.aspx Line: 75

Stack Trace:

[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder,
EncoderParameters encoderParams) +397778
System.Drawing.Image.Save(String filename, ImageFormat format) +69
SharedFunctions.fDisplayBadge(String strDot, String strGrade) +178
ASP.pages_verify_group_default_aspx.__Render__cont rol1(HtmlTextWriter
__w, Control parameterContainer) in C:\Users\Mark\Documents\Visual
Studio 2008\WebSites\LocalWeb\pages\verify\group\default. aspx:75
System.Web.UI.Control.RenderChildrenInternal(HtmlT extWriter writer,
ICollection children) +98
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +20
System.Web.UI.Page.Render(HtmlTextWriter writer) +26
System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer,
ControlAdapter adapter) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
ControlAdapter adapter) +121
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+2558

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.1433;
ASP.NET Version:2.0.50727.1433
The code I used was:

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

in an aspx page and:

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

Dim Img As New Bitmap(100, 100)
Dim g As Graphics = Graphics.FromImage(Img)
g.DrawString("Test", New Font("Arial", 15, FontStyle.Bold), _
New SolidBrush(Color.Red), 25, 35)
Img.Save("C:\MyStamp.jpg",
System.Drawing.Imaging.ImageFormat.Jpeg)

End Function



"Jialiang Ge [MSFT]" <ji****@online.microsoft.comwrote in message
news:fM**************@TK2MSFTNGHUB02.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.FromImage(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(Color.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.ImageForm at.Jpg))

After then, display the image in your page.

Regards,
Jialiang Ge (ji****@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:
ms****@microsoft.com.

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


Jun 27 '08 #7
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" <no**@none.coma écrit dans le message de groupe de discussion :
e#**************@TK2MSFTNGP03.phx.gbl...
Hmm. I don't know where I can see where was it closed before save:

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

Dim Img As New Bitmap(100, 100)
Dim g As Graphics = Graphics.FromImage(Img)
g.DrawString("Test", New Font("Arial", 15, FontStyle.Bold), _
New SolidBrush(Color.Red), 25, 35)
Img.Save("C:\MyStamp.jpg",
System.Drawing.Imaging.ImageFormat.Jpeg)

End Function


"Jialiang Ge [MSFT]" <ji****@online.microsoft.comwrote in message
news:eE**************@TK2MSFTNGP06.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 (ji****@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:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no
rights.
=============================================== ==
"Mark B" <no**@none.comwrote in message
news:uA****************@TK2MSFTNGP05.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.ExternalException: A
generic error occurred in GDI+.

Source Error:

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

Source File: C:\Users\Mark\Documents\Visual Studio
2008\WebSites\LocalWeb\pages\verify\group\defaul t.aspx Line: 75

Stack Trace:

[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder,
EncoderParameters encoderParams) +397778
System.Drawing.Image.Save(String filename, ImageFormat format) +69
SharedFunctions.fDisplayBadge(String strDot, String strGrade) +178
ASP.pages_verify_group_default_aspx.__Render__cont rol1(HtmlTextWriter
__w, Control parameterContainer) in C:\Users\Mark\Documents\Visual
Studio 2008\WebSites\LocalWeb\pages\verify\group\default. aspx:75
System.Web.UI.Control.RenderChildrenInternal(HtmlT extWriter writer,
ICollection children) +98
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +20
System.Web.UI.Page.Render(HtmlTextWriter writer) +26
System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer,
ControlAdapter adapter) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
ControlAdapter adapter) +121
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+2558

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.1433;
ASP.NET Version:2.0.50727.1433
The code I used was:

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

in an aspx page and:

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

Dim Img As New Bitmap(100, 100)
Dim g As Graphics = Graphics.FromImage(Img)
g.DrawString("Test", New Font("Arial", 15, FontStyle.Bold), _
New SolidBrush(Color.Red), 25, 35)
Img.Save("C:\MyStamp.jpg",
System.Drawing.Imaging.ImageFormat.Jpeg)

End Function



"Jialiang Ge [MSFT]" <ji****@online.microsoft.comwrote in message
news:fM**************@TK2MSFTNGHUB02.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.FromImage(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(Color.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.ImageForm at.Jpg))

After then, display the image in your page.

Regards,
Jialiang Ge (ji****@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:
ms****@microsoft.com.

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


Jun 27 '08 #8
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="detailspage.html" target="_blank"
style="display:block;width:50px;height:50px;backgr ound:url(badge.gif);text-align:center;line-height:25px;cursor:pointer;">A+<br/>$87K</a>

--
Göran Andersson
_____
http://www.guffa.com
Jun 27 '08 #9
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" <gu***@guffa.comwrote in message
news:ey******************@TK2MSFTNGP03.phx.gbl...
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="detailspage.html" target="_blank"
style="display:block;width:50px;height:50px;backgr ound:url(badge.gif);text-align:center;line-height:25px;cursor:pointer;">A+<br/>$87K</a>

--
Göran Andersson
_____
http://www.guffa.com
Jun 27 '08 #10
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
_____
http://www.guffa.com
Jun 27 '08 #11
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]" <ji****@online.microsoft.comwrote in message
news:eE**************@TK2MSFTNGP06.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 (ji****@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:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no
rights.
=================================================
"Mark B" <no**@none.comwrote in message
news:uA****************@TK2MSFTNGP05.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.ExternalException: A
generic error occurred in GDI+.

Source Error:

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

Source File: C:\Users\Mark\Documents\Visual Studio
2008\WebSites\LocalWeb\pages\verify\group\default .aspx Line: 75

Stack Trace:

[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder,
EncoderParameters encoderParams) +397778
System.Drawing.Image.Save(String filename, ImageFormat format) +69
SharedFunctions.fDisplayBadge(String strDot, String strGrade) +178
ASP.pages_verify_group_default_aspx.__Render__cont rol1(HtmlTextWriter
__w, Control parameterContainer) in C:\Users\Mark\Documents\Visual Studio
2008\WebSites\LocalWeb\pages\verify\group\default .aspx:75
System.Web.UI.Control.RenderChildrenInternal(HtmlT extWriter writer,
ICollection children) +98
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +20
System.Web.UI.Page.Render(HtmlTextWriter writer) +26
System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer,
ControlAdapter adapter) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
ControlAdapter adapter) +121
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+2558

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.1433;
ASP.NET Version:2.0.50727.1433
The code I used was:

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

in an aspx page and:

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

Dim Img As New Bitmap(100, 100)
Dim g As Graphics = Graphics.FromImage(Img)
g.DrawString("Test", New Font("Arial", 15, FontStyle.Bold), _
New SolidBrush(Color.Red), 25, 35)
Img.Save("C:\MyStamp.jpg",
System.Drawing.Imaging.ImageFormat.Jpeg)

End Function



"Jialiang Ge [MSFT]" <ji****@online.microsoft.comwrote in message
news:fM**************@TK2MSFTNGHUB02.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.FromImage(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(Color.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.ImageForma t.Jpg))

After then, display the image in your page.

Regards,
Jialiang Ge (ji****@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:
ms****@microsoft.com.

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

Jun 27 '08 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Phil Powell | last post: by
7 posts views Thread by pintihar | last post: by
6 posts views Thread by twins | last post: by
1 post views Thread by Onwuka Emeka | last post: by
2 posts views Thread by Onwuka Emeka | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.