Re: Drawing Text onto Image
- From: "Bob Powell [MVP]" <bob@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 7 Jan 2006 18:12:56 +0100
You can definitely get better image quality from GIF than from a JPEG of the
same file-size because GIF uses lossless compression whereas JPEG is lossy.
The problem arises however when GIF is saved from GDI+ using the standard
method. The GDI+ GIF encoder does no palette manipulation and provides a
standard spead-palette for all images. This doesn't make best use of the
available palette and many colours are often not used at-all.
Either save as jpeg using less compression or save as GIF using an optimised
palette.
The GDI+ FAQ discusses both of these subjects in some detail.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"landers" <landley_darlington@xxxxxxxxxxx> wrote in message
news:e6qQd5YEGHA.1088@xxxxxxxxxxxxxxxxxxxxxxx
> Hello All,
>
> I am having problems maintaining image quality when drawing text onto an
> image.
>
> I have a reasonable good quality GIF file with a transparent background.
> Whenever I write text onto it and save it as GIF / JPeg, it does image
> compression, resulting in a poor quality image.
>
> The image is being outputted to an ASPX page using the
> Response.OutputStream. I have written the resulting image to a file a
> viewed this, and the same problem occurs here also. I have included my
> code below. I would be grateful, if anyone can shed some light on this.
>
>
> Cheers,
>
> Landers
>
> {snippet start}
>
> Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles MyBase.PreRender
> Dim url As String = Request.RawUrl
> Dim imageUrl As String = "test.gif"
> Dim imageText As String = "Hello World"
>
> GetNewImage(imageUrl, imageText).Save(Response.OutputStream,
> Drawing.Imaging.ImageFormat.Jpeg)
>
> End Sub
>
> Private Function DrawTextOnImage(ByVal image As Drawing.Image, ByVal
> text As String) As Drawing.Image
> Dim n As Drawing.Bitmap = New Drawing.Bitmap(image)
> Dim g As Drawing.Graphics = Drawing.Graphics.FromImage(n)
>
> g.DrawImage(image, 0, 0)
> g.DrawString(text.ToLower, New Drawing.Font("Verdana", 16,
> FontStyle.Bold, GraphicsUnit.Pixel), Drawing.Brushes.White, 20, 8)
>
> Return n
>
> End Function
>
> Private Function GetNewImage(ByVal imageUrl As String, ByVal imageText
> As String) As Drawing.Image
> 'get image
> Dim imageStream As IO.StreamReader = New
> IO.StreamReader(Server.MapPath(imageUrl))
> Dim image As Drawing.Image =
> Drawing.Image.FromStream(imageStream.BaseStream)
> imageStream.Close()
>
> 'draw text on image
> Dim resultImage As Drawing.Image = DrawTextOnImage(image,
> imageText)
>
> Return resultImage
>
> End Function
>
> {snippet end}
>
>
.
- Follow-Ups:
- Re: Drawing Text onto Image
- From: landers
- Re: Drawing Text onto Image
- References:
- Drawing Text onto Image
- From: landers
- Drawing Text onto Image
- Prev by Date: Re: A newbie problem with gdiplus.h...
- Next by Date: Re: Working with Region
- Previous by thread: Re: Drawing Text onto Image
- Next by thread: Re: Drawing Text onto Image
- Index(es):
Relevant Pages
|