Recently in Crystal Toolkit Category

Yesterday, I placed version 1.0.0. of Crystal Image Toolkit on CodeProject with an expanded version of the tutorial.

If you’re visiting here from CodeProject, here is an index of articles I’ve written about misc features in the Crystal Image Toolkit:

  1. Factory For Crystal Collector.
  2. Header Groups for Image Thumbnail Grid View.
  3. Scaling Thumbnail Images with CrystalImageGridView.
  4. A brief explanation of the pan window for CrystalPictureShow.
  5. Screenshots of using CrystalMemoryCollector with CrystalPictureShow to create a wait dialog.

The articles may refer to earlier versions of the toolkit, please ignore and use the latest version.  The samples included in the toolkit will give you a better idea of how to use the various features mentioned in the articles.

Part one of a series of tutorials explaining how to use the Crystal Image Toolkit.  In this example, I will show you how to quickly add an image thumbnail control to your Windows Form application.

First of all, download the latest Crystal Image Toolkit from my downloads page.  Compile the code using the solution that I provided. 

Designer toolbox

Create a new Windows Forms application in Visual Studio. In the Visual Studio toolbox, add a new tab called Crystal Image Toolkit (to separate it from Crystal Reports) and add the controls found in CrystalToolkit.dll.

step 1 - drop CrystalImageGridView on Form

Select the control called “CrystalImageGridView”.  This is the control that displays the thumbnail images.  Drag this control onto your new Form.

step 2 - set properties

Now go to the Properties window, with “crystalImageGridView1” selected.  Change the Dock property to Fill.  Change the Orientation property to Vertical.

Control after set properties

After you set the properties, the image grid control should look like the above picture.  The blue borders simply give you an idea of what the image items will look like in the selected state.  The broken image bitmap is just a placeholder.  At runtime, your images will be placed inside this blue rectangle.  Yes, you can change many other properties, including the border color, background color, and so on.  But for now, let’s accept the defaults.

Let’s write a little bit of code.  Go to the events tab and double click on the Load event of the Form.  Now that you are in Form1.cs, let’s add this field:

   1: /// <summary>

   2: /// CrystalCollector object, assists in retrieving image files in a specified folder.

   3: /// </summary>

   4: private CrystalCollector _theCollector = null;


The CrystalCollector object is the controller in this framework. 

The collector works with the CrystalImageGridView and the CrystalImageGridModel.  It finds image files set in the ImageLocation property, creates objects to mirror those files as CrystalImageItem objects, and places those within the model.  The collector spawns a background thread to start thumbnailing the image items; this thread sends events to the view to tell it when an image thumbnail is available.  That is what happens behind the scenes, but here in this simple example, you only need to add this method for your Form:

   1: private void InitCollector()

   2: {

   3:     _theCollector =

   4:         CrystalCollectorFactory.DefaultFactory.CreateCollector(CrystalCollectorType.CrystalFileCollector);

   5:  

   6:     // Add the CrystalImageGridView object to the collector.

   7:     // The collector will work with the view to draw the images.

   8:     _theCollector.SetupView(crystalImageGridView1);

   9:  

  10:     // Optional:

  11:     // Set an initial folder to collect images.

  12:     // If no folder is set, collector starts at MyPictures in WinXP or Pictures folder in Vista

  13:     //CrystalCollectorFactory.DefaultFactory.InitCollectorSource("c:\\myImages", _theCollector);

  14:  

  15:     // Tell CrystalFileCollector to collect the images in the ImageLocation folder.

  16:     _theCollector.CollectImages();

  17: }

  18:  

  19: private void Form1_Load(object sender, EventArgs e)

  20: {

  21:     InitCollector();

  22: }

  23:  

  24: protected override void OnFormClosing(FormClosingEventArgs e)

  25: {

  26:     if (_theCollector != null)

  27:     {

  28:         _theCollector.StopCollection();

  29:     }

  30:     base.OnFormClosing(e);

  31: }


InitCollector creates the collector object using a factory.  The type it chooses is a file-based collector.  You could just create a new CrystalFileCollector yourself, but it is better to use the Factory.  This can be used to track down objects getting created/destroyed later.

Once the collector has been created, we call SetupView, passing in the CrystalImageGridView object that we dropped onto the Form.  This must be done before we gather any images.  The collector creates a CrystalImageGridModel object and links up the view to it.  The model must know about certain view properties, which affects how the image items will be displayed.

CollectImages is called at the end, which tells the collector to look at the ImageLocation and start gathering data about the images found there.  In this case, we did not set the ImageLocation—the default is set to your Pictures folder (on Vista) or MyPictures folder (in WinXP).  If you want to initialize another ImageLocation, use the code I commented out above the call to CollectImages.

Form1_Load calls InitCollector.  But there’s also the override to OnFormClosing, which calls the StopCollector method on the collector object.  This call will stop any background threads going on to thumbnail the images.

Simple form with thumbnail image control

When you press F5 and run, you should see the thumbnails for whatever images are in your Pictures folder.  Hopefully, they will be images of friends, family, and pets instead of comic book images!  Play around with this form—you should see that the control responds to resizing events, making the number of image items per row grow or shrink the form.  You can do ctrl-click and shift-click on image items for multiple selection as well.

Thumbnail image location

Where are these thumbnail images stored?  The CrystalThumbnailer object, which does the work of creating them, has a property called ThumbnailLocationRoot.  By default, it is your AppData folder, under the name of your Company and Product name.  The collector creates a sub folder here, based on the hash number of the original location.  It stores the thumbnails here—the largest thumbnail size it needs to display.  In these simple demos, the thumbnails will exist permanently.  I’ve decided the behavior to retain or erase them is application dependent and left the choice up to you.

This is obviously a very simple example, but I have included many sample Form applications in the toolkit.

SimpleImageGridDemo shows a slightly more complex version of this application, by allowing you to open any folder and view the thumbnail images.

PictureShowDemo

PictureShowControllerDemo shows you how to create a more realistic picture viewing application.  A split container is used to hold the CrystalImageGridView in Horizontal orientation on the bottom pane.  The top pane contains the CrystalPictureShow control, which is used to display images, magnify them, and present slideshows.  There’s also a panning window that appears whenever the image is displayed in a non-fit mode.

Crystal Image Toolkit 1.0.0 is ready to download.

Enhancements:

Factory object:  CrystalCollectorFactory was added to allow you to create the correct collector objects based on file or folder input.  Using this factory will help keep track of when objects are created.  See this post for details.

CrystalCollector: added StopCollector as a pure virtual method.  StopCollector stops the collection operation initiated by CollectImages.


CrystalCollector:  SortCrystalList with CrystalSortType.DisplayName will now sort the image items with case insensitivity.  This sort option uses DisplayNameLower property in CrystalImageItem.


CrystalImageItem:  Added ImageCorrupted property.  True means image is corrupt and cannot be displayed, false means it is safe to display.


CrystalImageItem:  Added DisplayNameLower property.  Takes the DisplayName string and does a ToLower call.


CrystalImageItem, CrystalCollector, and CrystalImageGridModel all implement IDisposable.  This objects hold references to Image objects, which can now be disposed of more efficiently.


Event notification: All events are now broadcast using the EventNotifier class.  This utility walks through the invocation list of a multi-cast delegate and checks to see if InvokeRequired is true before calling the delegate.

Code Cleanup:

Exception Handling Refactoring: Previously, the Crystal  Image Toolkit was eating all exceptions.  This was a bad practice and actually hid threading errors that were occurring in the forms and controls that were using the toolkit.  Now those exception handlers have all been removed, except for one in CrystalFileCollector:  LoadImage.  The exception here is caught when an image is corrupt and cannot be loaded from the disk.  In that case, ImageCorrupted in CrystalImageItem is set to true, see below.


CrystalCollector: AddView method was removed.  I had intended to support multiple views, but I need to wrap up this toolkit for the time being and move on to other projects.  Only 1 view is supported.  AddView has been changed to SetupView.  The internal list of views has been removed.

 

Download: Crystal Image Toolkit 1.0.0.  Totally free, open-source, C# .NET Framework 2.0 for Windows Forms, works with both Visual Studio 2005 and 2008.

Factory for CrystalCollector

| | Comments (0)

Factory Diagram for Crystal Collector objects.

I’ve implemented a factory for all the CrystalCollector-based objects in the upcoming release of the Crystal Toolkit.  Using the factory helps keep track of objects getting created and deleted.  I’ve also implemented IDispose in CrystalCollector and CrystalImageGridModel.  These objects keep a reference to Image objects that need to be released when the Crystal objects are no longer needed.  CrystalLogger, which works with log4net, reports when CrystalCollectors are created in the factory and released in the Dispose methods.

The next version of the Crystal Toolkit will be 1.0, at last.

Crystal Image Toolkit 0.82 is ready to download.

Minor Enhancements:

CrystalImageItem: Added DisplayName property.

This property will be used by CrystalImageGridView when it draws the text for the image item.  The DisplayName is separate and distinct from the ImageName.  ImageName for CrystalFileCollector is the name of the image file "image.png" whereas DisplayName could be "image1".

If DisplayName is not set, it will default to the value in ImageName.

CrystalImageItem: SplitImagePath now sets DisplayName as well as ImageName, ImageLocation.

CrystalImageItem: ToString() method uses DisplayName instead of ImageName.

CrystalImageGridModel, added new methods to help skip CrystalGroupItem objects...

  1. FirstNonHeaderIndex:
        Finds the index of the first item in the model that is not a CrystalGroupItem.
  2. LastNonHeaderIndex:
        Finds the index of the last item in the model that is not a CrystalGroupItem.
  3. PrevNonHeaderIndex:
        Finds the index of the previous item in the model that is not a CrystalGroupItem.
  4. NextNonHeaderIndex:
        Finds the index of the next item in the model that is not a CrystalGroupItem.

CrystalImageGridView: ShowThumbnails property added.

Set this property to false if you do not want anything displayed in the image grid view.  Only the gradient background will be shown. Setting the property back to true displays the thumbnail images.

CrystalImageGridView: DrawImageTitle now uses CrystalImageItem's DisplayName property for the title text.

CrystalComicShowController: unpack-wait dialog now positioned within the main form.

CrystalComicShowControllerDemo: Enhanced to convert images in CBR/CBZ files to a size compatible for viewing on the Sony PSP.  Fixed crashing bugs and sorting bugs from previous release.

Bug Fixes:

CrystalFileCollector: Images that have the hidden file attribute are now skipped when CollectImages is executed.

CrystalFileCollector, CrystalMemoryZipCollector, CrystalRarCollector:
Initial sorting of list was incorrect.  The sorting of the list must be done before the list/group item is added to the model.

CrystalImageGridView, CrystalPictureShow, CrystalPictureShowController:
Critical bug fixes where the controls tried to display or scroll to image item objects that were actually CrystalGroupItem objects.  The above methods are used to avoid them when necessary.

CrystalPictureShowController: Bug fix in DisplayImage.  Operations on the main GUI thread (_imageForm) synchronized with an Invoke and code inside MethodInvoker.

CrystalThumbnailer: Store method creates thumbnail folder if it does not exist.

CrystalThumbnailer: GetThumbnailName method bug fix, forward slashes '/' converted to '\'.  This was found in zip/rar files.

Code Cleanup:

CrystalImageItem: protected fields now change to private.
To access these values in child classes, you have to use the Properties encapsulating these fields.

CrystalTools: Class is now static (and therefore, sealed). 

Redundant Exception handlers were removed in various classes. 

NOTE: Exception handling will be revised in a near-future release.
Currently the toolkit is eating the exceptions and logging them; they obviously need to be thrown back to other objects in many cases.

Download: Crystal Image Toolkit 0.82.  Totally free, open-source, C# .NET Framework 2.0 for Windows Forms, works with both Visual Studio 2005 and 2008.

Crystal Image Toolkit 0.81 is ready to download.

New Feature: Header group items are now part of CrystalCollector, CrystalImageGridModel, and CrystalImageGridView.  You can now assign a group of thumbnail images to a collapsible header.  To illustrate this, here’s a screenshot from the demo application “HeaderGroupItemDemo” which is included in the project:

HeaderGroupItem1

There are four header groups visible that you can see here (FF, Hulk, Iron Man, Spider-Man).  Each contains a set of thumbnails.  The arrow icon indicates the expanded state; you can replace this icon in the framework as I am just using a free icon here.  Likewise you can replace the folder icon to represent something unique about this group of images if you wish.  But what’s important to note here is that the header group can be collapsed/expanded by clicking on it:

HeaderGroupItemCollapsed

Here I’ve collapsed two of the header items and left the other ones open.  You can see I have CrystalImageItem objects selected in each of the header groups.

In the C# code, Header groups translates to a CrystalGroupItem object containing a List of CrystalImageItem objects.  Each object now has a Parent property so it knows the group that it belongs to.  The biggest change in the collector is that now every GridModel has at least one root header. In the default mode, for backward compatibility, the header item is not displayed (ShowHeaders is set to false in CrystalImageGridView). This may cause problems in older applications that use CrystalImageGridView and try to navigate to item 0 in the GridModel.  You will need to do a test, such as: "if (theImage is CrystalGroupItem)".  See InitInitialImageImp in CrystalPictureShowController.cs for how to deal with this situation.

CrystalCollector now has an additional abstract method that requires you to CollectImages on a CrystalGroupItem object.  CrystalFileCollector implements this method and creates a default root header for simplicity.  But if you want to explicitly create CrystalGroupItem objects and add them to the collector, you do it like this:

   1: CrystalGroupItem groupItem = new CrystalGroupItem();

   2: groupItem.ImageName = "Fantastic Four";

   3: groupItem.ImageLocation = "..\\..\\SampleImages\\Fantastic Four";

   4: // Optional: set a unique image icon for this group header item in the image grid.

   5: //groupItem.FullImage = my Image icon;

   6: _theCollector.CollectImages(groupItem);


This is a bit of an early release of the header group feature.  In the future, I will add additional style bits for the header text font, add a border state around the header item, perhaps add mouse over events for it.

There are several bug fixes to the toolkit, which is why I wanted to release it now, even though this feature is a bit early.  To see all the bug fixes, please read the release notes in the zip file.

Download: Crystal Image Toolkit 0.81.  Totally free, open-source, C# .NET Framework 2.0 for Windows Forms.

Crystal Image Toolkit 0.80 is ready to download

New Features:

  • CrystalImageGridView now has ZoomFactor: allows scaling of thumbnail images!
    See ZoomImageGrid demo and Crystal Picture Show Controller demo.
  • CrystalPictureTracker: Pan Window that works with CrystalPictureShow.
    See Crystal Picture Show Controller demo.
  • CrystalPictureShow: Hand cursors that allow the user to drag zoomed images around.
  • CrystalImageGridView now has a new rounded rect border style.  Check out the groovy red borders in the Picture Show Controller demo.
  • Crystal Toolkit now integrates log4net.  See CrystalLogger object.
    You can get even more debug logging by declaring CRYSTAL_DEBUG in project properties/build.

And now it's demo time, with Marvel comics pictures, of course:

CrystalImageGridView using ZoomFactor to scale thumbnails

CrystalImageGridView: ZoomFactor applied to zoom to a larger thumbnail image.  See my earlier article that explains how to set this up.  Changes were made to CrystalPictureShowController to add a second trackbar object to control thumbnail zooming. 

CrystalPictureTracker working with CrystalPictureBox

CrystalPictureTracker: Panning (controlling CrystalPictureBox) in separate window.  Tracker window appears when image is larger than client area.  You can close it, make it appear again by clicking on the Pan Window button.

Red rounded borders

CrystalImageGridView: Rounded borders on selected images.  There is now a property called BorderState that allows you to switch between these rounded borders and the old square frame.  Also, notice that in the split view mode, the CrystalPictureShowController hides the thumbnail trackbar and toolstrip objects auto-magically.   Thumbnail sizes in the split mode are fixed, whereas in the vertical orientation (with a sheet of thumbnails) they can be scaled.

This release comes in a ZIP file. Simply unzip the contents to your hard drive, navigate to the root Attilan folder, and double click on CrystalDemo.sln. This solution file contains the Crystal Toolkit plus demo programs. Just build the solution (which compiles the CrystalToolkit library first) and run the demo programs to see how they work. You can run the demo programs without building the source by clicking on "StartDemo.bat" in the root Attilan folder or CrystalDemoLauncher.exe in Attilan\bin.

Download: Crystal Image Toolkit 0.80.  Totally free, open-source, C# .NET Framework 2.0 for Windows Forms. 

1 2 Next