示例#1
0
 private void StampImage(ImagXpress lifetime, string text, ImageX destination)
 {
     using (var processor = new Processor(lifetime, destination))
     {
         int bitsPerPixel = destination.ImageXData.BitsPerPixel;
         if (bitsPerPixel != 24)     // we can only paint on a 24 bit image.
         {
             processor.ColorDepth(24, PaletteType.Optimized, DitherType.NoDither);
         }
         using (var g = destination.GetGraphics())
             using (var font = new Font(FontFamily.GenericMonospace, 16, FontStyle.Bold))
                 using (var matrix = new Matrix())
                 {
                     try
                     {
                         SizeF textSize = g.MeasureString(text, font);
                         Point location = GetStampLocation(new Size(destination.ImageXData.Width, destination.ImageXData.Height), textSize);
                         // All my stamping is vertically along the left edge
                         matrix.Translate(1, 1);
                         matrix.RotateAt(-90, new PointF(location.X, location.Y));
                         g.Transform = matrix;
                         g.DrawString(text,
                                      font,
                                      Brushes.Black,
                                      location.X, location.Y,
                                      new StringFormat());
                     }
                     finally
                     {
                         destination.ReleaseGraphics();
                     }
                 }
         // The BPP may change accoding to Accusofts documentation, so change it back to what is was
         if (bitsPerPixel != destination.ImageXData.BitsPerPixel)
         {
             processor.ColorDepth(bitsPerPixel, PaletteType.Optimized, DitherType.NoDither);
         }
     }
 }