Author |
Topic |
|
Fábio Nascimento
Brazil
72 Posts |
Posted - May 31 2016 : 09:09:58
|
Hi,
I'm using LoadFromFileOnDemand to load my tiffs files into ImageEnMView because I have some files with many many pages.
But when I save the file with ImageEnMView.MIO.SaveToFileTIFF(ImageEnMView.MIO.Params[ImageEnMView.SelectedImage].FileName,False), something weird happens and some pages seens to be lost, see this picture please:
http://i.imgur.com/ilBJaHL.png
If I load the file using LoadFromFileTIFF instead it seens to save correctly, so I'm guessing it has something to do with the LoadFromFileOnDemand command instead.
What should I do to save the file correctly using LoadFromFileOnDemand to open them?
Thanks! |
|
w2m
USA
1990 Posts |
Posted - May 31 2016 : 09:50:01
|
LoadFromFileOnDemand does not immediately load all the frames. When using LoadFromFileOnDemand is used, individual frames will be delayed until they are required (i.e. frames are only loaded when they appear on-screen). The thumbnails are created as the component is scrolled. All thumbnails are not loaded until the component is scrolled to the end. So maybe to make sure all the images have been loaded before saving then try this:
iCount := IEGetFileFramesCount(AFilename);
for i := 0 to iCount do
ImageEnMView1.EnsureImageLoaded(i);
ImageEnMView1.MIO.SaveToFile(AFilename); If the content of the TImageEnMView is being loaded on demand (e.g. because you are using LoadFromFileOnDemand) then the image properties such as ImageWidth and ImageHeight, and I/O parameters will not be valid until the image has loaded. Calling EnsureImageLoaded will force an image to be loaded so you can access its properties. Naturally calling EnsureImageLoaded too often (e.g. for all images) would defeat the purpose of loading on demand and affect performance.
Bill Miller Adirondack Software & Graphics Email: w2m@hughes.net EBook: http://www.imageen.com/ebook/ Custom Commercial ImageEn Development |
|
|
Fábio Nascimento
Brazil
72 Posts |
Posted - May 31 2016 : 10:15:36
|
I don't do too much changes to the files, it's like 1% of the images that requires some kind of change.
I'll try that Bill, thanks! |
|
|
Fábio Nascimento
Brazil
72 Posts |
Posted - May 31 2016 : 11:09:43
|
Apparently if I run ImageEnMView1.EnsureImageLoaded(i) all the time before saving it works, but it's kinda slow when I have a lot of pages.
I hope there is another solution, but I'll use this one for now.
Thanks Bill, maybe Nigel can give me some other idea! |
|
|
w2m
USA
1990 Posts |
Posted - May 31 2016 : 12:14:30
|
You do not seem to understand that the images are not loaded until all the images are scrolled to make them visible, or EnsureImageLoaded is called for each thumbnail. With images with a large number of pages if you want speed then you have to accept the slowness when saving. Nigel may have an way to minimize this, but I suspect there is not another way to get around the problem.
You just can not have high speed along with loading all the frames with large files.
Bill Miller Adirondack Software & Graphics Email: w2m@hughes.net EBook: http://www.imageen.com/ebook/ Custom Commercial ImageEn Development |
|
|
Fábio Nascimento
Brazil
72 Posts |
Posted - May 31 2016 : 13:36:24
|
Hi Bill,
I do understand that, but I thought that running EnsureImageLoaded once should be enough, don't you agree?
But, in my tests, if I don't run EnsureImageLoaded all the time before saving, I end up getting these non valid pages.
I tried this:
1) Use LoadFromFileOnDemand to load them, it's fast for any number of pages 2) If the user needs to change anything, run EnsureImageLoaded before the first save only 3) If the user need to save again the same file, since I already ran EnsureImageLoaded it should fine, but no, even for 2 consecutive saves in a row, I have to call EnsureImageLoaded twice or I get the non valid pages
The step 3 says to me that I'm missing something, after a EnsureImageLoaded the frames should be loaded and ready to save no?
Of course I'm working on the same file without close the form or open another file in the middle of the process.
If load the file with LoadFromFile is enough, why run EnsureImageLoaded only once isn't?
Also the IEGetFileFramesCount on your code generates an error when deleting frames, so I used ImageEnMView.ImageCount; instead.
Fábio |
|
|
w2m
USA
1990 Posts |
Posted - May 31 2016 : 14:51:53
|
I am not sure if ImageEnMView.ImageCount shows the correct number of images when LoadFromFileOnDemand is used. I have no idea why you have to run EnsureImageLoaded more than once. Maybe Nigel will have some ideas.
Bill Miller Adirondack Software & Graphics Email: w2m@hughes.net EBook: http://www.imageen.com/ebook/ Custom Commercial ImageEn Development |
|
|
Fábio Nascimento
Brazil
72 Posts |
Posted - May 31 2016 : 16:12:32
|
Let's wait for Nigel then :D
Thanks anyways Bill, always very helpfull! |
|
|
xequte
38613 Posts |
Posted - May 31 2016 : 19:26:02
|
Hi
ImageEnMView.ImageCount is valid even when using LoadFromFileOnDemand.
Saving using TImageEnMView requires all frames to be loaded, so if you are only looking to update a few frames in a huge file then that is not the best method for you.
At present, this would require you to load a file into a TImageEnIO, update the IEBitmap and then replace it in the file, i.e. with ReplaceStreamTIFF:
http://www.imageen.com/help/TImageEnIO.ReplaceStreamTIFF.html
But there should be a method to update/replace a frame directly from TImageEMView. Let me investigate
Nigel Xequte Software www.xequte.com nigel@xequte.com |
|
|
Fábio Nascimento
Brazil
72 Posts |
Posted - Jun 01 2016 : 13:35:02
|
Thanks Nigel, I'll look into ReplaceStreamTIFF and wait for you!
Is there any sample/demo using ReplaceStreamTIFF? |
|
|
xequte
38613 Posts |
Posted - Jun 01 2016 : 23:58:53
|
Hi Fabio
I'm afraid there's not but see the example at:
http://www.imageen.com/help/TImageEnIO.ReplaceFileTIFF.html
So your code would be something like...
// Update the file for the selected frame of a multi-page TIFF in a TImageEnMView
IO := TImageEnIO.Create(nil);
IO.Params.TIFF_ImageIndex := ImageEnMView1.SelectedImage; // select page
IO.IEBitmap.Assign( ImageEnMView1.IEBitmap );
IO.ReplaceFileTIFF( ImageEnMView1.MIO.LastFilename );
IO.Free;
Nigel Xequte Software www.xequte.com nigel@xequte.com |
|
|
Fábio Nascimento
Brazil
72 Posts |
Posted - Jun 02 2016 : 08:08:15
|
Hi Nigel
But that's ReplaceFileTIFF, is is the same as ReplaceStreamTIFF?
On the ReplaceStreamTIFF there's no sample code, that's why I asked.
Which one is the right one? Or either?
Thanks |
|
|
Fábio Nascimento
Brazil
72 Posts |
Posted - Jun 02 2016 : 09:11:06
|
It worked with
var
IO: TImageEnIO;
begin
IO := TImageEnIO.Create(nil);
IO.Params.TIFF_ImageIndex := ImageEnMView.SelectedImage;
IO.IEBitmap.Assign(ImageEnMView.IEBitmap);
IO.ReplaceFileTIFF(ImageEnMView.MIO.Params[ImageEnMView.SelectedImage].FileName);
IO.Free;
But for large files, it's a bit slow too, is there a way to show the progress and is it the right way?
PS: I changed ImageEnMView1.MIO.LastFilename to ImageEnMView.MIO.Params[ImageEnMView.SelectedImage].FileName); IO.Free; because the first one raises file not found for me.
Fábio |
|
|
xequte
38613 Posts |
Posted - Jun 07 2016 : 00:25:08
|
Hi Fabio
ImageEnMView1.MIO.LastFilename is only filled if you load a file into the TImageEnMView. Your method is fine too.
You can use the OnProgress event of TImageEnIO to show progress (and OnFinishWork). Perhaps instead of a dynamic TImageEnIO, you add a TImageEnIO component to your form and handle the relevant events that way.
Nigel Xequte Software www.xequte.com nigel@xequte.com
|
|
|
Fábio Nascimento
Brazil
72 Posts |
Posted - Jun 07 2016 : 07:55:02
|
I'll try that Nigel, thanks. |
|
|
rswyman@docuxplorer.com
USA
156 Posts |
Posted - Jul 24 2016 : 07:27:06
|
Hi Nigel,
If InsertToFileTIFF and ReplaceFileTIFF are used to add and replace images what method is used to delete a page? |
|
|
xequte
38613 Posts |
|
rswyman@docuxplorer.com
USA
156 Posts |
Posted - Jul 25 2016 : 08:31:28
|
great thanks! |
|
|
|
Topic |
|