Page Arranger: 25 Projects in 25 Days

Page Arranger Screenshot
Page Arranger Screenshot
Page Arranger Rearranged
Page Arranger Rearranged

As part of the LEAD Technologies 25th anniversary, we are creating 25 projects in 25 days to celebrate LEAD’s depth of features and ease of use. Today’s project comes from Nick.

What it Does

This project uses drag-and-drop to reorder pages within document or image files using LEADTOOLS Version 19.

Features Used

Development Progress Journal

Hello, I’m Nick and I’m going to be using LEADTOOLS to create an application in which pages in a document can be re-ordered with drag-and-drop functionality. For this, I’m going to create a basic document viewer, then create a custom InteractiveMode to handle the functionality.

First, I created the UI using WinForms for the application. Since the application is basically a document viewer, I sourced the C# Document Viewer demo and used several components within it, primarily the saving and loading routine. At this point, I have a basic document viewer: I can load a PDF and have it displayed as both pages and thumbnails, save the PDF, and exit the program. At this point, saving the PDF really only creates another copy of it since the pages are still in the same order. It’s taken me maybe 90 minutes to get to this point.

For a proof of concept, I modified my code to change the order of the pages programatically, and was able to save out the new page order. Turns out LEADTOOLS already handles this by providing Move() in the DocumentPages property of the Document in the DocumentViewer which uses the LeadCollection object to hold the pages:
Documentation: LeadCollection class

I’m really only interested in modifying the thumbnail pane at this point. Turns out the thumbnail pane contains two InteractiveModes by default: ImageViewerSelectItemsInteractiveMode, and ImageViewerPanZoomInteractiveMode, in that priority order.
Documentation: ImageViewerSelectItemsInteractiveMode
Documentation: ImageViewerPanZoomInteractiveMode

We’ll be creating our own InteractiveMode to handle the drag-and-drop by creating the ImageViewerDragDropInteractiveMode class. This new class will extend the ImageViewerSelectItemsInteractiveMode, because it already includes the SelectItem functionality we’ll use as a foundation. It took me maybe a half hour to read up on the functionality I’m going to need.

I’m going to do this by polling for various events: particularly, DragStarted and DragCompleted. If no drag occurs — that is, the user clicks a thumbnail and releases the mouse button without moving it — the new InteractiveMode simply behaves as its base class, and selects the item. However, if a drag event occurs, we want the InteractiveMode to handle it as a drag and drop event. This means we don’t need the included SelectItem InteractiveMode. In addition, since lots of clicking and dragging is going to occur, the PanZoom InteractiveMode may cause some conflicts, regardless of the priority order. Since these two are added by default to the thumbnail pane, I’ve decided to clear them out before adding mine, so only mine will have any effect.

I’ve finished writing the code to handle the events now. I’m able to detect when a thumbnail page is selected, and which thumbnail page is under it when the mouse is complete and the drag operation finishes. This took maybe an hour of coding, tweaking, and breakpointing.

However, it turns out my new ImageViewerDragDropInteractiveMode doesn’t have access to the loaded document. Rather than pass the document into the InteractiveMode directly, the InteractiveMode will raise an event that a drag-and-drop operation has completed, passing both the original index of the location and the target. From here, the UI which owns the document will handle reordering the pages.

I’ve made some aesthetic changes to the InteractiveMode, like changing the mouse cursor when the InteractiveMode is functioning to provide visual feedback to the user. Initially, when performing a drag-and-drop operation, the “Selected Items” rectangle was still drawn, but I’ve suppressed this.

At this point, I can open a PDF in this application, drag-and-drop the pages to change their order in the thumbnail viewer, and save the reordered pages as a new file. After cleaning up, organizing, and commenting my code, I’d say the entire task took just over eight hours. If I weren’t using LEADTOOLS, I’d still be working on getting the document to display.

Download the Project

The source code for this sample project can be downloaded from here. To run the project, extract it to the C:\LEADTOOLS 19\Examples\DotNet\CS directory.

Posted in Document Imaging | Tagged , , , , , , , , , , | Leave a comment

OCR Screen Capture: 25 Projects in 25 Days

OCR Snipping Screenshot
OCR Snipping Screenshot
Selecting Area
Selecting Area
Display Result
Display Result

As part of the LEAD Technologies 25th anniversary, we are creating 25 projects in 25 days to celebrate LEAD’s depth of features and ease of use. Today’s project comes from Amin.

What it Does

This C# application uses OCR on screen capture image snips using LEADTOOLS Version 19.

Features Used

Development Progress Journal

Hello, my name is Amin and I’ll be creating a program captures an image from the computer’s screen using a user-selected rectangle, then extracts text from the captured image using LEAD’s Optical Character Recognition (OCR) technology.

I will be coding with C# using VS 2010 since its projects can be easily upgraded to later versions of Visual Studio.

First, I’ll start by creating a form that has the Leadtools.Controls.ImageViewer control to display the captured image and a text box for the recognition result.

To perform screen capturing, I will use the LEADTOOLS ScreenCaptureEngine class.

I have added a button to initiate capturing and an event handler to receive the capture image. The entire code needed to do the user-selection screen capturing, or snipping, is about a dozen lines long and took less than an hour to finish. Attempting a similar feat without LEADTOOLS would take most programmers days, or even weeks, if we consider the smooth and flawless mouse-controlled user-interface.

Next, I’ll add code to perform OCR. A good starting point is to download one of the "Minimum OCR demos" on our support forums:

LEADTOOLS Forum: Minimum OCR Demos

Using code from that page, I was able to implement OCR within one hour as well. Using the image returned from screen capturing with the OCR engine was very simple and straightforward, since the various LEADTOOLS modules are designed to work together seamlessly.

Since most screens have a default resolution of 96 dots per inch, my code changes the image resolution to 150 DPI before using it with OCR. The reason is that OCR takes into consideration the image’s DPI when attempting to recognize the shapes of the characters, and a value of 150 is more suitable for OCR than 96.

Finally, I added a couple of bells and whistles to enable copying either the image or the recognition result text to the Windows clipboard, then spent some time testing, commenting and refining the code.

All in all, the whole thing took less than 6 hours to make.

Please note that LEADTOOLS 19 ships with an OCR and Screen Capture demo that has more advanced features. The demo is installed with the toolkit in these folders:

LEADTOOLS 19\Examples\DotNet\CS\OcrScreenCaptureDemo
LEADTOOLS 19\Examples\DotNet\VB\OcrScreenCaptureDemo

Download the Project

The source code for this sample project can be downloaded from here. To run the project, extract it to the C:\LEADTOOLS 19\Examples\DotNet\CS directory.

Posted in OCR | Tagged , , , , , , | Leave a comment

Universal Viewer: 25 Projects in 25 Days

LEADUniversalViewer Video
LEADUniversalViewer Video
LEADUniversalViewer Audio
LEADUniversalViewer Audio
LEADUniversalViewer Image
LEADUniversalViewer Image

As part of the LEAD Technologies 25th anniversary, we are creating 25 projects in 25 days to celebrate LEAD’s depth of features and ease of use. Today’s project comes from Maen.

What it Does

This C# WinForms project will load/play both raster images and videos in the same window using LEADTOOLS Version 19.

Features Used

Development Progress Journal

Hello, my name is Maen and I am going to create a project that allows the user to select a folder on his machine’s hard drive, and display/playback any supported image/Media (Video or Audio) file in the selected folder.

Using LEADTOOLS Document Imaging Suite and LEADTOOLS Multimedia SDKs will provide me with the support of huge set of images and multimedia file formats, without writing many lines of code. For example, the following code shows how you can play a file using LEADTOOLS PlayCtrl control:


TempPlayer.AutoStart = true;
TempPlayer.SourceFile = _fileName;

  

Also, the following code shows how you can load and display an image file in our ImageViewer control:


RasterCodecs codecs = new RasterCodecs();
imageViewer1.Image =  codecs.Load(SelectedListItem.FileFullName);

  

I am going to use the LEADTOOLS RasterCodecs class as this is the class that provides support for loading raster images:

Documentation: RasterCodecs

I have finished adding the required controls (LEADTOOLS PlayCtrl and ImageViewer) and writing the code to load images and media files:

Documentation: PlayCtrl Control

Documentation: ImageViewer

I have finished writing a user-defined class (MyListItem class) that represents the list-box item.

I successfully ran the project and displayed the different images and media files using this application. So far, I have 7 hours total invested in this application. I have added some comments to the code for easier reading.

Finally, the application is done!  It took me around 9 hours to put this together, including designing, testing and debugging.

Thank you my beloved tools for providing this huge set of formats, that I cannot even imagine how long a task like this would take without using our toolkit.

Download the Project

The source code for this sample project can be downloaded from here. To run the project, extract it to the C:\LEADTOOLS 19\Examples\DotNet\CS directory.

Posted in Multimedia Imaging | Tagged , , | Leave a comment

Capture, DVR and Stream with RTSP: 25 Projects in 25 Days

As part of the LEAD Technologies 25th anniversary, we are creating 25 projects in 25 days to celebrate LEAD’s depth of features and ease of use. Today’s project comes from Mohamed.

What it Does

This C# project will capture, DVR and stream videos over RTSP using LEADTOOLS Version 19.

Features Used

Development Progress Journal

My name is Mohamed and I’m going to create a program which will use our Multimedia toolkit to capture a live video stream, save it in the LEADTOOLS DVR file format, and then use our RTSPServer to stream the resulting DVR file while live capturing is still on.

The streaming can be started soon after capturing begins, so it will be near-live streaming if the user wants it that way.

In this project, I will use the LEADTOOLS Multimedia SDK and program with .NET C# programming language. The LEADTOOLS Multimedia SDK provides me with the ability to Play, Capture and Convert media files. The project’s process consists of the following parts:

  • Create capture control and enumerate Available Audio and Video devices.
  • Set the target format type of the Capture control to DVR so that video keeps getting added, while providing the ability to read from that recorded video without stopping capture.
  • Create RTSPServer and initialize the IP Address and port number for the RTSPServer.
  • Stream the resulting DVR file.

First, I will start with a new Windows Forms Application in Visual Studio 2010. In the form, I will add a Capture control, two ComboBoxes for the Audio and Video devices, several buttons for each operation needs user action.

I have now added the needed Capture control and other objects in the project. To work with Capture control, I will need to use LEADTOOLS CaptureCtrl Class:

Documentation: CaptureCtrl

The program will enumerate the available video and audio capture devices in a comboboxes. Also it has the ability for changing the properties of the selected devices.

Handling the capturing from devices and saving as DVR only took me a little less than an hour because our Multimedia SDK greatly simplifies dealing with Multimedia features. If I was going to do it using DirectShow without LEADTOOLS, I’d probably need several days to do a similar simple application.

Next I will add a function for getting the v4 IP address of the machine.

The total time is now about 4 hours. This included the form design, handling the IP address, choosing the devices and saving the result as LBL format (LEADTOOLS DVR) with MPEG-4 video and AAC Audio compression.

Now, I will add the RTSPSever code. Based on what I’ve done so far with the LEADTOOLS Multimedia SDK, I expect this control to be just as high level and require a very small amount of code, even though the work it accomplishes is quite substantial.

Documentation: Creating a RTSP Server

This part is now done and it took about half an hour to finish.

Next I will take a final look at the design to do some finishing touches…

This took about half an hour and I’m now satisfied with how the program looks and feels.

Lastly comes the testing part, for which I will try running the application on different machines and play the video on another machine. After an hour and a half, I think the program is solid and stable.

The total amount of time taken to develop, debug and test the application from scratch was less than 7 hours. Without LEADTOOLS Multimedia SDK, this application would not have been possible to finish within one day.

Download the Project

The source code for this sample project can be downloaded from here. To run the project, extract it to the C:\LEADTOOLS 19\Examples\DotNet\CS directory.

Posted in Multimedia Imaging | Tagged , , , , , , , , , | 3 Comments

HTML5 Image Gallery: 25 Projects in 25 Days

As part of the LEAD Technologies 25th anniversary, we are creating 25 projects in 25 days to celebrate LEAD’s depth of features and ease of use. Today’s project comes from Justin.

What it Does

This ASP.NET C# application will display a thumbnail image gallery using LEADTOOLS Version 19.

Features Used

Development Progress Journal

Hi, my name is Justin and I’m going to write a simple image gallery application in ASP.NET.  I’ve never created an ASP.NET application from scratch before.

I’ll create thumbnails for a directory of images in code-behind C#. Then, I’ll display them in an HTML5 viewer.

I’ll start with the back end. I’ll be generating image thumbnails with RasterImage.CreateThumbnail. I’ll just need to loop over images in a folder.

Documentation: RasterImage.CreateThumbnail

Done generating thumbnails. I’m going to make this a static WebMethod and call it on app startup. This took about 15 minutes. On to the front end…

I’ll just start with a basic viewer <div> in my markup and then clean up the UI later. For the gallery view, I’ll l be using an ImageViewerVerticalViewLayout:

Documentation: ImageViewerVerticalViewLayout

I’ve loaded all of the image thumbnails as individual ImageViewerItems. With ImageViewerVerticalViewLayout.Columns = 0, the gallery grid is automatically dynamic based on the window width. Sweet!

When I click on a thumbnail, I want to open the full resolution image that corresponds to the item clicked. To do so, I’ll add an ImageViewerSelectionMode to the viewer’s InteractiveModes collection.

I’ve added a handler for item selection. In each thumbnail’s ImageViewerItem, I add the URL to the full resolution image as the ImageViewerItem's tag, so switching to the full resolution images is simple.

When viewing a full resolution image, I switch to an ImageViewerSingleViewLayout. Easy!

Now to clean up the UI: Adding a header and footer, along with a back button to go back from the full resolution image. I’ll need some window calculation boilerplate because of this new footer. Grr.

All done. In all, this only took 5 hours to get a nice looking gallery going. With how finicky CSS can be, making such a dynamic UI from scratch would’ve taken much longer.

Download the Project

The source code for this sample project can be downloaded from here.

Posted in HTML5 | Tagged , , , , , , , , , , , | Leave a comment