Home : Printing : Printing the Current View of the AnnotateViewer
Q10233 - HOWTO: Printing the Current View of the AnnotateViewer

The following will help you print just the visible region from the AnnotationViewer:

----- C# -----

AtalaImage img = (AtalaImage)annotateViewer1.Image.Clone();

int width = Convert.ToInt32(Math.Min((annotateViewer1.ClientSize.Width / annotateViewer1.Zoom), (annotateViewer1.Image.Width / annotateViewer1.Zoom)));

int height = Convert.ToInt32(Math.Min((annotateViewer1.ClientSize.Height / annotateViewer1.Zoom), (annotateViewer1.Image.Height / annotateViewer1.Zoom)));

int left = Convert.ToInt32(Math.Abs(annotateViewer1.ScrollPosition.X) / annotateViewer1.Zoom); int top = Convert.ToInt32(Math.Abs(annotateViewer1.ScrollPosition.Y) / annotateViewer1.Zoom);

Rectangle rcView = new Rectangle(left, top, width, height);

if (img.ColorDepth < 24)

     img = img.GetChangedPixelFormat(PixelFormat.Pixel24bppBgr);
}

Bitmap bmp = img.ToBitmap();
annotateViewer1.Annotations.RenderAnnotations(new Atalasoft.Annotate.AnnotationImage(bmp));
img = AtalaImage.FromBitmap(bmp);

CropCommand cmd = new CropCommand(rcView);
img = cmd.Apply(img).Image;

ImagePrintDocument doc = new ImagePrintDocument(img);
doc.ScaleMode = PrintScaleMode.FitToEdges;

using (PrintDialog dlg = new PrintDialog())
{
     dlg.Document = doc;

     if (dlg.ShowDialog() == DialogResult.OK) 
          doc.Print();
}

doc.Dispose();

 

----- VB.Net -----
Dim Img As Atalasoft.Imaging.AtalaImage = Me.AnnotateViewer1.Image.Clone

' Get the viewable area of an image.
Dim width As Integer = Convert.ToInt32(Math.Min((Me.AnnotateViewer1.ClientSize.Width / Me.AnnotateViewer1.Zoom), (Me.AnnotateViewer1.Image.Width / Me.AnnotateViewer1.Zoom)))

Dim height As Integer = Convert.ToInt32(Math.Min((Me.AnnotateViewer1.ClientSize.Height / Me.AnnotateViewer1.Zoom), (Me.AnnotateViewer1.Image.Height / Me.AnnotateViewer1.Zoom)))

Dim left As Integer = Convert.ToInt32(Math.Abs(Me.AnnotateViewer1.ScrollPosition.X) / Me.AnnotateViewer1.Zoom)
Dim top As Integer = Convert.ToInt32(Math.Abs(Me.AnnotateViewer1.ScrollPosition.Y) / Me.AnnotateViewer1.Zoom)
Dim rcView As Rectangle = New Rectangle(left, top, width, height)

If Img.ColorDepth < 24 Then 
    Dim cmd24 As Atalasoft.Imaging.ImageProcessing.ChangePixelFormatCommand = _ 
         New Atalasoft.Imaging.ImageProcessing.ChangePixelFormatCommand(Atalasoft.Imaging.PixelFormat.Pixel24bppBgr)

    Img = cmd24.Apply(Img).Image
End If

Dim bmp As Bitmap = Img.ToBitmap

'Render the annotations to the cloned image for printing only
Me.AnnotateViewer1.Annotations.RenderAnnotations(New Atalasoft.Annotate.AnnotationImage(bmp))
Img = Atalasoft.Imaging.AtalaImage.FromBitmap(bmp)

Dim crop As Atalasoft.Imaging.ImageProcessing.CropCommand crop = New Atalasoft.Imaging.ImageProcessing.CropCommand(rcView)

Img = crop.Apply(Img).Image

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.

Powered By InstantKB.NET v1.3
Copyright © 2002, 2017. InstantASP Ltd. All Rights Reserved