Load, change and save image to the same file in Image Viewer

Questions, comments and suggestions concerning VintaSoft Imaging .NET SDK.

Moderator: Alex

Alex
Site Admin
Posts: 2303
Joined: Thu Jul 10, 2008 2:21 pm

Re: Load, change and save image to the same file in Image Viewer

Post by Alex »

Hello Daniel,
i'm running into the same problem, using the image collection of an ImageViewer-control:
...
Could you send us a small working project which demonstrates your problem? If yes, please send your project to support@vintasoft.com.

Best regards, Alexander
DanielLW
Posts: 22
Joined: Tue Sep 01, 2015 2:42 pm

Re: Load, change and save image to the same file in Image Viewer

Post by DanielLW »

Hello Alex,

i've recognized that the problem occurs only, if there is a thumbnailviewer attached to the ImageViewer (property "MasterViewer").

You can easily reproduce it by creating a form with an ImageViewer and ThumbnailViewer-control added to it, and then executing my code.

I've tried to de-attach the thumbnailviewer before saving, setting the "MasterViewer"-property to NULL, but this does not help. It seems if the image-collection has been changed once, the ThumbnailViewer holds some reference to it. I've also tried to call "ClearAndDisposeItems" on the image-collection of the ThumbnailViewer, but no success either.
Is there any other way to completely disconnect the ThumbnailViewer from the ImageViewer temporary?

Best regards,
Daniel
Yuri
Posts: 64
Joined: Wed Jul 23, 2008 2:47 pm

Re: Load, change and save image to the same file in Image Viewer

Post by Yuri »

Hello Daniel,

Your code looks correct, however the simultaneous image decoding (asynchronously in viewer) with encoding of the same image causes a mutual locking.

It isn't a good practice because, theoretically, there might take place any changes in image collection: removing images, insert etc. and this may cause a failure in decoding.

What is your task?

You can at first rotate the image, save changes and then open the file in viewer:

Code: Select all

ImageCollection images = new ImageCollection();
images.Add(@"c:\test\test.tif", false);

images[0].Rotate(90);

Vintasoft.Imaging.Codecs.Encoders.TiffEncoder teTest = 
    new Vintasoft.Imaging.Codecs.Encoders.TiffEncoder();

teTest.SaveAndSwitchSource = true;

images.SaveSync(@"c:\test\test.tif", teTest);

this.imageViewer1.Images.AddRange(images.ToArray());

Or another way is to copy the file into memory:

Code: Select all

Vintasoft.Imaging.Codecs.Encoders.TiffEncoder teTest;

MemoryStream ms = new MemoryStream(File.ReadAllBytes(@"c:\test\test.tif"));
this.imageViewer1.Images.Add(ms, true);

this.imageViewer1.Images[0].Rotate(90);


teTest = new Vintasoft.Imaging.Codecs.Encoders.TiffEncoder();

teTest.SaveAndSwitchSource = true;

this.imageViewer1.Images.SaveSync(@"c:\test\test.tif", teTest); 

--
Kind regards, Yuri
DanielLW
Posts: 22
Joined: Tue Sep 01, 2015 2:42 pm

Re: Load, change and save image to the same file in Image Viewer

Post by DanielLW »

Hello Yuri,

thank you for your answer and code suggestions. I will have a look into it.
Yuri wrote: What is your task?
Simple, build a picture viewer with thumbnail-view, where the user can rotate the currently viewed page and save it back to the file.
Yuri
Posts: 64
Joined: Wed Jul 23, 2008 2:47 pm

Re: Load, change and save image to the same file in Image Viewer

Post by Yuri »

Hello Daniel,

Why can't you modify and use our Imaging Demo? It does what you need.

--
Regards, Yuri
Post Reply