473,382 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 5320
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Phil Powell | last post by:
PHP 4.3.2 with --enable-exif I have the following class: <?php class ThumbGenerator extends MethodGeneratorForActionPerformer { function ThumbGenerator() { // CONSTRUCTOR
5
by: Magnus | last post by:
Hi, I'm programatically posting an image using multipart/form-data. It sends to the server OK, but when I try to view it in the browser, it is still in the base64 string I sent it as:...
7
by: pintihar | last post by:
Hi, As a follow on from an earlier post I have another question about xslt. Is it possible to create the stylsheet programatically? Is this sensible? In the first phase I needed to map element...
6
by: twins | last post by:
Please let me know the easiest method to create a JPEG/GIF bar chart from PHP. I have found solutions that allow creation of swf/flash charts but I need a jpeg/jpg/gif bar chart.
1
by: Onwuka Emeka | last post by:
is there a way to reduce or modify the color depth of a jpeg image, i currently need to programatically change the color depth of a jpeg image from 24bits to 8bits. any help would be appreciated
2
by: Onwuka Emeka | last post by:
is there a way to reduce or modify the color depth of a jpeg image, i currently need to programatically change the color depth of a jpeg image from 24bits to 8bits. any help would be appreciated
1
by: vijay | last post by:
HI ALL, How to create excel chart programatically using C#.net 2005. I have created an excel file by using Gembox.Spreadsheet component.Now i want to add excel Chart to this...
7
by: The Mad Ape | last post by:
Hi I have code to programatically create a label. It works but when I try to call a sub to create a tooltip it does not work. I do not get an error so have no idea what it wrong. Please review...
3
by: Rambaldi | last post by:
Although i'm working on ASP.net, i think the problem i'm facing is related to my javascript function so i hope i create the thread in the right section. My goal is to create a table dynamically,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.