[Mono-list] libgdiplus

Charlie irgendetwas at charlie.at
Sat Oct 22 06:13:23 EDT 2005


Hi,

I wrote a little c# program to 'stamp' a copyright string onto an image
(http://www.charlie.at/images/200509Klatovy/im_000086_08.jpg)
 
i would eventually like to incorporate this functionality into an online
image gallery viewer (something akin to quickthumbs). in doing this a
few differences between the win32 and mono implementations of libgdiplus
popped up. I am using mono 1.1.9.3 (rpm's from the download page) under
suse 9.3 with the ms fonts installed. 

- the texture brush works in win32 but not in mono.
- the font size calculation seems to be different 565.4896x79.5 win32 to
530x74 mono (this may have something to do with the font?)
- the default Image.Save under win32 is jpeg, in mono it is bmp 

included below a small test app where these differences become visible.
am i doing something stupid here? are there better ways to achieve the
wanted results? for now i can live with doing the copyright stamp under
win32 but eventually it would be nice to upload my pictures to a linux
server and have it automatically stamp, resize and display the images.

thanks for any input,
  charlie 

using System;
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

namespace TransTextTest
{
	class Class1
	{
		[STAThread]
		static void Main(string[] args)
		{
      Image img = Image.FromFile(args[0]);
      string cr = "©"+ DateTime.Now.Year +" don't copy";
      Bitmap bm= new Bitmap(img.Width, img.Height,
PixelFormat.Format32bppArgb);
    
      Graphics g = Graphics.FromImage(bm);
      SolidBrush sb = new SolidBrush(Color.FromArgb(255, 0, 0, 0));  
      g.FillRectangle(sb, new Rectangle(0, 0, img.Width, img.Height));

      float[][] ptsArray = { 
                            new float[] {1, 0, 0, 0, 0},
                            new float[] {0, 1, 0, 0, 0},
                            new float[] {0, 0, 1, 0, 0},
                            new float[] {0, 0, 0, 0.65f, 0}, 
                            new float[] {0, 0, 0, 0, 1}};            
      ColorMatrix clrMatrix = new ColorMatrix(ptsArray);
      ImageAttributes imgAttributes = new ImageAttributes();
      imgAttributes.SetColorMatrix(clrMatrix, ColorMatrixFlag.Default,
ColorAdjustType.Bitmap);
 
      TextureBrush tb = new TextureBrush(img, new
Rectangle(0,0,img.Width,img.Height),imgAttributes);
      Font fnt = new Font("arial", 48, FontStyle.Bold);
      SizeF sf = g.MeasureString(cr,fnt);  
      g.DrawString(cr, fnt, tb, (img.Width - sf.Width), 0); 
      SolidBrush sw = new SolidBrush(Color.FromArgb(255, 255, 255,
255));  
      Console.WriteLine("FontSize: " +sf.Width+"x"+sf.Height);
      g.DrawString(cr, fnt, sw, (img.Width - sf.Width), (img.Height -
sf.Height));
      img.Dispose();
      img = bm;
      g.Dispose();
      

img.Save(System.Environment.OSVersion.Platform.ToString()+args[0]);

    }
	}
}


-- 
----------------------------------------------------------------------
"Charlie's Air Action Adventure"                    Karl-Heinz Woytech
www.charlie.at                                  irgendetwas at charlie.at



More information about the Mono-list mailing list