Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Monday, October 29, 2018 3:54:11 PM(UTC)
Rob Cline

Groups: Registered
Posts: 52

Thanks: 14 times

I have the following code a ported from my old application that used version 17 and individual page files saved as .tif files.
I am trying to perform commands that are NOT supported by the documentViewer command system.
Below is an example.

// Rotate image .5 degrees CCW
private void tsbtnRotateLeft_Click(object sender, EventArgs e)
{
if (!documentViewer.HasDocument)
return;

documentViewer.BeginUpdate();
RotateCommand cmdRotate = new RotateCommand(-50, RotateCommandFlags.Bicubic, RasterColor.FromRgb(0x888888));
//cmdRotate.Run(documentViewer.View.ImageViewer.Image);
cmdRotate.Run(leadDocument.Pages[CurrentPageNo].GetImage(300));
documentViewer.EndUpdate();
UpdateUIState();
}


The UpdateUIState() method is the same one as the one that is part of 'DocumentViewerDemo_4'.

The code above does not throw an error, but neither does it update the DocumentViewer.View.
I have tried code using both of versions of cmdRotate.Run() shown above (with one or the other line commented out).

I assume I am missing something very fundamental on how to use the existing page commands with the new DocumentViewer control.

Do I need to use the SaveToCache and LoadFromCache features to make this work or do I need to save to a file and load from a file to refresh the viewer?

Edited by user Tuesday, October 30, 2018 11:21:21 AM(UTC)  | Reason: Further clarification based on additional research of documentation.

 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Tuesday, October 30, 2018 1:18:25 PM(UTC)
Josh Clark

Groups: Registered, Tech Support, Administrators
Posts: 54

Thanks: 2 times
Was thanked: 10 time(s) in 10 post(s)

Hello Rob,

Do you want to rotate the way the document page is viewed or the content of the page itself? To rotate the way the page is viewed, which is preferred as this would preserve the page's vector status, you can set the RotateAngle like so:

Code:
documentViewer.View.ImageViewer.Items[_documentViewer.CurrentPageNumber-1].RotateAngle = -0.5;

Documentation for this property can be found here:
https://www.leadtools.com/help/leadtools/v20/dh/c/imagevieweritem-rotateangle.html

Internally the DocumentViewer uses an ImageViewer to display the document. This ImageViewer has an ImageViewerItem for each page. Modifying this ImageViewerItem affects how the corresponding page is displayed.

If you would like to rotate the content of the page itself which will affect how the document is saved, let me know and I can assist you further.

Thanks,
Josh Clark
Developer Support Engineer
LEAD Technologies, Inc.

LEAD Logo
 
#3 Posted : Tuesday, October 30, 2018 1:31:57 PM(UTC)
Rob Cline

Groups: Registered
Posts: 52

Thanks: 14 times

The operator is making a fine grained rotation to the individual page.
They need to see the result of the rotation in the DocumentViewer.ImageViewer to know if they need to perform the rotation more than once.
Also, please understand that our code needs to perform a number of other RasterImage level commands not supported by the DocumentViewer.

Finally, I do need to save to rotation of this page for the document.
So, your last sentence is also what I need help with.

Do I need to use the cache to make this happen; or can I do what I need to with a temporary multi-page .tif file that is saved to a local working file before the final save.
 
#4 Posted : Friday, November 2, 2018 9:07:24 AM(UTC)
Josh Clark

Groups: Registered, Tech Support, Administrators
Posts: 54

Thanks: 2 times
Was thanked: 10 time(s) in 10 post(s)

Hello Rob,

To use raster image commands, you will need to create a copy of the image using GetImage, however you will need to set it back in the DocumentViewer with SetImage. See the following code as an example:

Code:
using (RasterImage image = _documentViewer.Document.Pages[_documentViewer.CurrentPageNumber - 1].GetImage(300))
{
    new RotateCommand(-50, RotateCommandFlags.Resample, RasterColor.FromRgb(0x888888)).Run(image);
    bool readOnly = _documentViewer.Document.IsReadOnly;
    _documentViewer.Document.IsReadOnly = false;
    _documentViewer.Document.Pages[_documentViewer.CurrentPageNumber - 1].SetImage(image);
    _documentViewer.View.ImageViewer.Items[_documentViewer.CurrentPageNumber - 1].Image = image.Clone();
    _documentViewer.Document.IsReadOnly = readOnly;
    _documentViewer.Document.SaveToCache();
}
if (_documentViewer.Commands.CanRun(DocumentViewerCommands.ViewItemType, DocumentViewerItemType.Image))
    _documentViewer.Commands.Run(DocumentViewerCommands.ViewItemType, DocumentViewerItemType.Image);
_documentViewer.View.Invalidate();
_documentViewer.Thumbnails.Invalidate();
UpdateUIState();


Note that as this is a slow process, you may want to find the angle you wish to rotate to by first rotating the image using the aforementioned RotateAngle method. Once you know the angle you wish to rotate to, you can use the RotateCommand once ensuring the best processing speed and image accuracy.
Josh Clark
Developer Support Engineer
LEAD Technologies, Inc.

LEAD Logo
thanks 1 user thanked Josh Clark for this useful post.
Rob Cline on 11/6/2018(UTC)
 
#5 Posted : Tuesday, November 6, 2018 5:00:50 PM(UTC)
Rob Cline

Groups: Registered
Posts: 52

Thanks: 14 times

That seems to be doing the job.

Thanks.
 
#6 Posted : Tuesday, February 12, 2019 1:27:40 PM(UTC)
Rob Cline

Groups: Registered
Posts: 52

Thanks: 14 times

It seems I spoke too soon.

The code below does the job for one rotation but does not allow the user to rotate the image a second time.

The user needs to be able to perform the small rotation as many times as needed in order to correct a skewed document.
I am using ver.20 without caching. Instead our workstations save to a local file until all annotations are complete.

// Rotate image .5 degrees CCW
private void tsbtnRotateLeft_Click(object sender, EventArgs e)
{
if (!documentViewer.HasDocument)
return;

using (RasterImage image = documentViewer.Document.Pages[documentViewer.CurrentPageNumber - 1].GetImage(300))
{
//var rotateCommand = new RotateCommand();
//var currentAngle = rotateCommand.Angle;

var command = new RotateCommand(- 50, RotateCommandFlags.Bicubic, RasterColor.White);
command.Run(image);
//ImageDirty = true;
ImageFileIO.SaveDocumentToTemp(leadDocument, automation, HasRedactions);

documentViewer.Document.Pages[documentViewer.CurrentPageNumber - 1].SetImage(image);
documentViewer.View.ImageViewer.Items[documentViewer.CurrentPageNumber - 1].Image = image.Clone();
//documentViewer.Document.SaveToCache();

if (documentViewer.Commands.CanRun(DocumentViewerCommands.ViewItemType, DocumentViewerItemType.Image))
documentViewer.Commands.Run(DocumentViewerCommands.ViewItemType, DocumentViewerItemType.Image);
documentViewer.View.Invalidate();
documentViewer.Thumbnails.Invalidate();
UpdateUIState();
}
}

 
#7 Posted : Thursday, February 14, 2019 11:51:03 AM(UTC)
Josh Clark

Groups: Registered, Tech Support, Administrators
Posts: 54

Thanks: 2 times
Was thanked: 10 time(s) in 10 post(s)

Without caching enabled, each time that you call GetImage, you are actually getting the original unmodified image from the disk. You will want to enable caching by either directly setting the cache property of the DocumentFactory, or through the DocumentLoadOptions used when loading the file. You will also need to set LoadDocumentOptions.UseCache to true as well. This should allow you to use the RotateCommand consecutively on the image you have loaded.

Note that performing this operation in succession might produce distortions within the image due to compounded error. To solve this, you will want to rotate the original image by an angle that you will increase each time. I have written a sample of this below. Note that this only works for the first page and to support multiple pages you will have to store an image and a rotation angle for each page.

Code:
private int rotateCommandAngle = 0;
private RasterImage documentCopy = null;

// Rotate image .5 degrees CCW
private void tsbtnRotateLeft_Click(object sender, EventArgs e)
{
   if (!documentViewer.HasDocument)
      return;

   // Use a copy of the original image
   int index = 0;
   if (documentCopy == null)
      documentCopy = documentViewer.Document.Pages[index].GetImage(300);

   // Use a copy of the original image every time
   using (RasterImage image = documentCopy.CloneAll())
   {
      rotateCommandAngle -= 50;
      var command = new RotateCommand(rotateCommandAngle, RotateCommandFlags.Bicubic, RasterColor.White);
      command.Run(image);

      bool readOnly = documentViewer.Document.IsReadOnly;
      documentViewer.Document.IsReadOnly = false;
      documentViewer.Document.Pages[index].SetImage(image);
      documentViewer.View.ImageViewer.Items[index].Image = image.Clone();
      documentViewer.Document.IsReadOnly = readOnly;

      if (documentViewer.Commands.CanRun(DocumentViewerCommands.ViewItemType, DocumentViewerItemType.Image))
         documentViewer.Commands.Run(DocumentViewerCommands.ViewItemType, DocumentViewerItemType.Image);
      documentViewer.View.Invalidate();
      documentViewer.Thumbnails.Invalidate();
      UpdateUIState();
   }
}
Josh Clark
Developer Support Engineer
LEAD Technologies, Inc.

LEAD Logo
thanks 1 user thanked Josh Clark for this useful post.
Rob Cline on 2/14/2019(UTC)
 
#8 Posted : Thursday, February 14, 2019 1:18:08 PM(UTC)
Rob Cline

Groups: Registered
Posts: 52

Thanks: 14 times

Thanks for the quick reply Josh.

The original program would have saved and reloaded the individual page image files after any page edits were performed.
I assume that is why it has no problems when the operator performs multiple rotations.

One quick point to note: when the operator rotates the page it is because the original page image is skewed.
Therefore the operator will never rotate the page to create distortions, they rotate it to remove distortions and line up the document correctly.
This is usually only one page of a multiple page document.

Therefore, it appears I need to reimplement the cache, which I disabled thinking it had no real value to me because I store the image files in a working directory before they are saved to their archive location.
Plus, the cache would speed up the update of a single page in a large document.

I actually discovered that sometimes our current 32 bit program will run out of memory if the document is too large and using the cache would appear to handle that situation as well.
We have had to redact some documents in excess of 1000 (one thousand) pages.

Thanks for putting me back on track.

Edited by user Thursday, February 14, 2019 5:25:41 PM(UTC)  | Reason: Not specified

 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.149 seconds.