473,605 Members | 2,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.

Jun 27 '08 #1
11 5356
Mark-

You mean something like this,

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

Cor

"Mark B" <no**@none.coms chreef in bericht
news:eJ******** ******@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.
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.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 (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****@microsof t.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 .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]" <ji****@online. microsoft.comwr ote in message
news:fM******** ******@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 (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****@microsof t.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****@microsof t.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=============== =============== =============== ====
"Mark B" <no**@none.comw rote in message
news:uA******** ********@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]" <ji****@online. microsoft.comwr ote in message
news:fM******** ******@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 (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****@microsof t.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(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]" <ji****@online. microsoft.comwr ote in message
news:eE******** ******@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 (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****@microsof t.com.

This posting is provided "AS IS" with no warranties, and confers no
rights.
=============== =============== =============== ====
"Mark B" <no**@none.comw rote in message
news:uA******** ********@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]" <ji****@online. microsoft.comwr ote in message
news:fM******* *******@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 (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****@microsof t.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\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" <no**@none.comw rote in message
news:e%******** ********@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]" <ji****@online. microsoft.comwr ote in message
news:eE******** ******@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 (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****@microsof t.com.

This posting is provided "AS IS" with no warranties, and confers no
rights.
============== =============== =============== =====
"Mark B" <no**@none.comw rote in message
news:uA******* *********@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]" <ji****@online. microsoft.comwr ote in message
news:fM****** ********@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 (ji****@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:
ms****@microsof t.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.co ma é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(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]" <ji****@online. microsoft.comwr ote in message
news:eE******** ******@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 (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****@microsof t.com.

This posting is provided "AS IS" with no warranties, and confers no
rights.
============== =============== =============== =====
"Mark B" <no**@none.comw rote in message
news:uA******* *********@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]" <ji****@online. microsoft.comwr ote in message
news:fM****** ********@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 (ji****@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:
ms****@microsof t.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="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
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.co mwrote in message
news:ey******** **********@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
Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3643
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
3219
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: /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUG etc.... I've been through the form I built over and over: string PostData = ""; PostData += "-----------------------------7d41fb3081216"; PostData += "\r"; PostData += "\n";
7
5199
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 name from inbound xml to my internal elements to standardize disparate input. Now I could just create an xslt stylesheet for each possible inbound format and be done, but I think it would be powerful to be able store this mapping in a database and...
6
3161
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
3259
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
4160
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
3424
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 excel file.But Gembox not support the excel chart.So i am in trouble. I want to create excel chart by using data available on excel file whichever i have created by using Gembox programatically. Is anybody knows the solution. ...
7
6744
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 my code and tell me how to fix it. Thanks The Mad Ape
3
2070
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, depending with the number of cameras i got. The code is: var tabela = "<table border=2 width='100%' heigth='100%'><tr>"; var lastCol = 3; for (var i = 1; i <= nCam; i++) {
1
8069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8286
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6742
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5886
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3912
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3958
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2438
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1537
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1270
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.