Bulk load images and annotations
Posted: Mon May 11, 2009 1:50 pm
Hi Alex,
I've written some code that will allow users to select multiple images to upload and silently load the annotations from separate XMP files. It works partially, in that the images load and the annotations are added to the image. The problem I have is that for some reason the ThumbnailViewer only shows the annotations on the first image in the ThumbnailViewer (although if you select the other thumbnail images the annotations are visible in the ImageViewer). Here is my code, any ideas..?
NB. The assumption here is that IMAGE.TIF has a corresponding annotation file called IMAGE.XMP in the same directory.
I've tried calling Refresh() on the ThumbnailViewer after adding images to try and redraw the control but it didn't do any good. Is it anything to do with how I'm trying to programatically focus on the next image in the ThumbnailViewer? What is the best way to do this when loading multiple images.
Thanks.
I've written some code that will allow users to select multiple images to upload and silently load the annotations from separate XMP files. It works partially, in that the images load and the annotations are added to the image. The problem I have is that for some reason the ThumbnailViewer only shows the annotations on the first image in the ThumbnailViewer (although if you select the other thumbnail images the annotations are visible in the ImageViewer). Here is my code, any ideas..?
NB. The assumption here is that IMAGE.TIF has a corresponding annotation file called IMAGE.XMP in the same directory.
Code: Select all
private void LoadImagesFromFile() {
OpenFileDialog openImageDialog = GetOpenImageDialog();
openImageDialog.Multiselect = true;
if (openImageDialog.ShowDialog() == DialogResult.OK) {
foreach (string fileName in openImageDialog.FileNames) {
try {
//add image
thumbnailViewer1.Images.Add(fileName);
//focus on newly added image
thumbnailViewer1.FocusedIndex = thumbnailViewer1.Images.Count - 1;
if (acquireAnnotationsOnImageLoadToolStripMenuItem.Checked) {
//load annotations
LoadAnnotations(thumbnailViewer1.FocusedIndex, FilenameUtils.ChangeFileExtension(fileName, EXT_XMP));
}
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
}
}
private void LoadAnnotations(int imageIndex, string filePath) {
string xmpFile = FilenameUtils.ChangeFileExtension(filePath, EXT_XMP);
if (CheckImageSelected() && File.Exists(xmpFile)) {
int nextAnnoIndex = thumbnailViewer1.Annotations[imageIndex].Count;
//load annotations from file
XmlDocument doc = new XmlDocument();
doc.Load(xmpFile);
thumbnailViewer1.Annotations[imageIndex].Load(doc);
//update zOrder, adding number of annotations loaded
zOrder += numAnnotationsLoaded;
}
}
Thanks.