Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Render Image from Font

Reply
Thread Tools

Render Image from Font

 
 
localhost
Guest
Posts: n/a
 
      10-11-2004

I have a custom TrueType .ttf font in the filesystem (not installed)
on the web server.

I want to take the letter "A" from this font, render it as an image,
and return that as a byte stream in a web page.

How can I do that?


Thanks.

 
Reply With Quote
 
 
 
 
Patrice
Guest
Posts: n/a
 
      10-11-2004
See System.Drawing. You can do a "usual" Windows graphics app and then
stream the bitmap to the browser...

Patrice

--

"localhost" <(E-Mail Removed)> a écrit dans le message de
news:(E-Mail Removed)...
>
> I have a custom TrueType .ttf font in the filesystem (not installed)
> on the web server.
>
> I want to take the letter "A" from this font, render it as an image,
> and return that as a byte stream in a web page.
>
> How can I do that?
>
>
> Thanks.
>



 
Reply With Quote
 
 
 
 
Gabe Garza
Guest
Posts: n/a
 
      10-11-2004
Why not just create image files (.png, .jpg, .gif) of each letter.
Then just reference your letter with an <IMG> tag.

<IMG src='letterCapA.png'> Good Example


"localhost" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> I have a custom TrueType .ttf font in the filesystem (not installed)
> on the web server.
>
> I want to take the letter "A" from this font, render it as an image,
> and return that as a byte stream in a web page.
>
> How can I do that?
>
>
> Thanks.
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      10-12-2004
Hi Localhost,

As for your question, I think the GDI+ components under the System.Drawing
/System.Drawing.Text namespace can finish the task. Also, w can use the
"PrivateFontCollection" class to load a (true type font) ttf file from disk
into memory and create a tempory font instance so as to use it(without
installed in the system's font library), here is a simple code snippet.
Hope helps:


=====================================
private void Page_Load(object sender, System.EventArgs e)
{
try
{
System.Drawing.Text.PrivateFontCollection pfc = new
PrivateFontCollection();
pfc.AddFontFile(Server.MapPath("DarkGardenMK.ttf") );

FontFamily family=new FontFamily("Dark Garden",pfc);
Font dgFont=new Font(family,40);

Bitmap tmpBitmap = new Bitmap(400,100,PixelFormat.Format32bppArgb);
Graphics objGraphics = Graphics.FromImage(tmpBitmap);


objGraphics.DrawString("Hello World!", dgFont, new
SolidBrush(Color.White ),0,0);

Response.Clear();
Response.ContentType = "image/jpeg";
tmpBitmap.Save(Response.OutputStream,ImageFormat.J peg);

Response.End();
tmpBitmap.Dispose();

}
catch(Exception ex)
{
Response.Write("<br>" + ex.Message);
}

}

============================================

In addtion, below is the codeproject article I refer to , that has the more
detailed explanition.

#C# Barcode Generator WebService
http://www.thecodeproject.com/cs/web.../wsbarcode.asp

Hope helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


 
Reply With Quote
 
Gabe Garza
Guest
Posts: n/a
 
      10-12-2004
I'm just curious with this code.
> tmpBitmap.Save(Response.OutputStream,ImageFormat.J peg);

This line makes the browser display a image only or can you include HTML
Tags as well, as in the following code:

Response.Write("<a href='www.server.com'>Home</a><br><hr>");
tmpBitmap.Save(Response.OutputStream,ImageFormat.J peg);

Response.Write("<hr><a href='www.server.com'>Home</a>");


"Steven Cheng[MSFT]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Localhost,
>
> As for your question, I think the GDI+ components under the System.Drawing
> /System.Drawing.Text namespace can finish the task. Also, w can use the
> "PrivateFontCollection" class to load a (true type font) ttf file from

disk
> into memory and create a tempory font instance so as to use it(without
> installed in the system's font library), here is a simple code snippet.
> Hope helps:
>
>
> =====================================
> private void Page_Load(object sender, System.EventArgs e)
> {
> try
> {
> System.Drawing.Text.PrivateFontCollection pfc = new
> PrivateFontCollection();
> pfc.AddFontFile(Server.MapPath("DarkGardenMK.ttf") );
>
> FontFamily family=new FontFamily("Dark Garden",pfc);
> Font dgFont=new Font(family,40);
>
> Bitmap tmpBitmap = new Bitmap(400,100,PixelFormat.Format32bppArgb);
> Graphics objGraphics = Graphics.FromImage(tmpBitmap);
>
>
> objGraphics.DrawString("Hello World!", dgFont, new
> SolidBrush(Color.White ),0,0);
>
> Response.Clear();
> Response.ContentType = "image/jpeg";
> tmpBitmap.Save(Response.OutputStream,ImageFormat.J peg);
>
> Response.End();
> tmpBitmap.Dispose();
>
> }
> catch(Exception ex)
> {
> Response.Write("<br>" + ex.Message);
> }
>
> }
>
> ============================================
>
> In addtion, below is the codeproject article I refer to , that has the

more
> detailed explanition.
>
> #C# Barcode Generator WebService
> http://www.thecodeproject.com/cs/web.../wsbarcode.asp
>
> Hope helps. Thanks.
>
> Regards,
>
> Steven Cheng
> Microsoft Online Support
>
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      10-13-2004
Hi Gabe,

Of course not, one response stream can only be specified one content-type.
IF we return image stream, we must clear other content. That's why I use

Response.Clear();//clear other content
Response.ContentType = "image/jpeg";
tmpBitmap.Save(Response.OutputStream,ImageFormat.J peg);
Response.End();// end the current response and render to client

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cross platform TTF font render from Python [was: Load TTF from pycairounder Windows] Laszlo Nagy Python 1 09-19-2009 02:43 AM
Swing Font, it's Java Font? ot native? how install new font? mttc Java 2 07-03-2009 07:29 PM
Accessing rails render method outside of view / Decorating render Glenn Gillen Ruby 0 11-17-2006 02:30 PM
Page.Render do not render complete page Lau Lei Cheong ASP .Net 1 05-15-2004 04:10 AM
Font class, external font files question Karl Hungus ASP .Net 1 02-04-2004 04:26 PM



Advertisments