2014-02-05 1 views
0

AccuSoft의 ImagXpress를 통해 이미지에 스탬프를 삽입하는 데 문제가 있습니다. C#의 속성에 액세스하면 이미지 프레임의 너비와 높이가 표시되지만 이미지의 높이와 너비는 실제 높이와 너비가 픽셀이므로 화면에 표시되는 것보다 훨씬 큽니다.ImagXpress 및 C# - ImagXpress를 통해 이미지에 스탬프 찍기

누구도 ImagXpress에 경험이 있고 인쇄하기 전에 이미지에 스탬프 또는 워터 마크를 삽입 한 경험이 있습니까? 인쇄 할 때 픽셀에서 트윕으로 변환하여 배치하려고 시도했지만 너무 많은 크기 측정 (픽셀 단위의 프레임, 실제 파일 크기 (픽셀 단위), 트윕 단위의 인쇄 작업 용지 폭)이 있기 때문에 올바르게 변환되지 않습니다.

아니면 누가이 작업을 수행하는 방법에 대한 자세한 정보를 찾을 수 있습니까? 나는 AccuSoft의 사이트를 방문하려했지만 포럼을 가지고있는 것처럼 보이지는 않았다. 단지 매뉴얼과 FAQ만이 그렇게 많이 도움이되지는 않았다.

답변

0

여기에 많은 노력을 기울여야 할 때, 여기 나와 있습니다. 그것은 여러 페이지 tif 이미지의 각 페이지에 스탬프를 집어 넣습니다.

public class AccusoftStamper 
{ 
    public string Stamp() 
    { 
      var fileNameOrStream = ... // Get your image from somewhere 

      using (var lifetime = AccusoftProvider.ImagXpress) // Replace this with your own license 
      { 
       var load = new LoadOptions(); 

       // All my images are multipage tiff files 
       var save = new SaveOptions { Format = ImageXFormat.Tiff }; 
       save.Tiff.MultiPage = true; 

       using (ImageX image = ImageX.FromFile(lifetime, fileNameOrStream, load)) 
       { 
        int offset = 0; 
        int pages = ImageX.NumPages(lifetime, fileNameOrStream); 
        for (int i = 0; i < pages; i++) 
        { 
         image.Page = i + 1; 
         save.Tiff.Compression = image.ImageXData.Compression; 

         var pageStamp = ".." // Get your stamp 
         StampImage(lifetime, pageStamp, image); 

         save.Tiff.UseIFDOffset = offset > 0; 
         save.Tiff.IFDOffset = offset; 

         image.Save(outputFileName, save); 

         offset = save.Tiff.IFDOffset; 
        } 
       } 
      } 
    } 

    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); 
     } 
    } 

    public Point GetStampLocation(Size imageSize, SizeF textSize) 
    { 
     var p = new Point(0, 0); 

     // Top Right 
     //p.X += destination.ImageXData.Width; 

     // Top left 
     //p.Y += (int)Math.Round(textSize.Width, MidpointRounding.AwayFromZero); 

     // Need to figure out where you want the stamp to be 

     return p; 
    } 
} 
+0

AccusoftProvider.ImagXpress를 사용하면 무엇입니까? 나는 당신이 당신의 면허를 사용 함으로서 당신이 의미하는 것이 확실하지 않습니다. 이미 작업을 시작했을 때 이미 구현 되었기 때문에 ImagXpress에 익숙하지 않습니다. – Justin

+0

또한 프로그램 사용 중에 언제 발생합니까? 나는 우리의 목표가 페이지에서 우표가 어디로 갈 것인지를 나타내는 그것을 보면서 그들의 이미지 위에 영역을 배치하도록하는 것이라고 믿습니다. – Justin

+0

라이센스를 확인하는 ImagXpress 객체를 인스턴스화하는 데 사용하는 속성입니다. http://help.accusoft.com/ImagXpress/v12.0/dotnet/Accusoft.ImagXpress12.Net~Accusoft.ImagXpressSdk.ImagXpress.html – Frank