Image Viewing Not Reliable in COM

Discussions about document viewing.
Post Reply
stanlyn
Posts: 25
Joined: Wed Mar 05, 2014 8:29 pm

Image Viewing Not Reliable in COM

Post by stanlyn » Sun Mar 16, 2014 7:48 am

Hi,

Its been several days since I asked a related question and still no reply or solution... Using COM in VFP9sp2 the viewing of the images is not reliable. It works and doesn't work when it wants to. I've included 2 screen shots showing it working and not working. Also in the screenshot is the image being shown in paint and both are shown OK, whereas one images shows the gdViewer as all black... Also here is the code that is in the grid's AfterRowColChange event.

Thisform.GdViewer1.CloseDocument()
Thisform.GdViewer1.Clear()

If File(Alltrim(images.orig_path), 1)
oGdPictureImaging.ReleaseGdPictureImage(ImageID)
ImageID = oGdPictureImaging.CreateGdPictureImageFromFile(images.orig_path)

*oGdPictureImaging.TiffSelectPage(ImageID, i)
*thisform.GdViewer1.ZoomMode = 2 && FitAll
Thisform.GdViewer1.DisplayFromGdPictureImage(ImageID)
ELSE
oGdPictureImaging.ReleaseGdPictureImage(ImageID)
ImageID = 0
Thisform.GdViewer1.DisplayFromGdPictureImage(ImageID)
Endif

Thisform.Refresh


Thanks, Stanley
Attachments
Picture0006.png
Picture0005.png

SamiKharma
Posts: 352
Joined: Tue Sep 27, 2011 11:47 am

Re: Image Viewing Not Reliable in COM

Post by SamiKharma » Sun Mar 16, 2014 10:50 am

Hi,

The problem is in your code:
ELSE
oGdPictureImaging.ReleaseGdPictureImage(ImageID)
ImageID = 0
Thisform.GdViewer1.DisplayFromGdPictureImage(ImageID)
Endif

You are displaying an empty image.
Also you are not adhering to good practices:
1. You need to check if the image creation was successful by checking that the image identifier is not equal to 0.
2. You need to check that the display was successful by checking the GdPictureStatus returned from the display function.

Also, we cannot test your code, nor can we see the image you are complaining about.

Best,
Sami

stanlyn
Posts: 25
Joined: Wed Mar 05, 2014 8:29 pm

Re: Image Viewing Not Reliable in COM

Post by stanlyn » Sun Mar 16, 2014 10:59 pm

Sami,

Did you even look at the screen shots? One of the screenshots clearly shows an image failing in gdViewer and succeeding in Windows paint, while the other screenshot clearly shows it succeeding in both gdViewer and Paint.


>> you are not adhering to good practices

I'd love to..., except here it doesn't make any difference, as I'm getting the same unreliable behavior that stated this thread. Here is the complete code that includes the "best practices" code:

With Thisform as form
If File(Alltrim(images.orig_path), 1)
*oGdPictureImaging.ReleaseGdPictureImage(ImageID)
ImageID = oGdPictureImaging.CreateGdPictureImageFromFile(images.orig_path)
If ImageID = 0
.GdViewer1.CloseDocument()
.GdViewer1.Clear()
Messagebox("Error loading image:" + Str(oGdPictureImaging.GetStat()),0,"Error Loading File")
Else
If oGdPictureImaging.GetStat() = 0 &&GdPictureStatus.OK
*oGdPictureImaging.TiffSelectPage(ImageID, i)
*thisform.GdViewer1.ZoomMode = 2 && FitAll
.GdViewer1.DisplayFromGdPictureImage(ImageID)
Else
Endif
Endif
Else
oGdPictureImaging.ReleaseGdPictureImage(ImageID)
.GdViewer1.CloseDocument()
.GdViewer1.Clear()
Endif
.Refresh
Endwith

This reveals a messagebox stating an File Loading error with a status of 1 on some of the files, while the other files displays as expected.

What does status 1 mean? Where is it documented? Also I figured out that one of the possible GetStat() return values is OK which translates to numeric 0. Where is this documented? (the name to numeric translation)

Now, if someone would provide help on what the status codes are in both name and numeric values, then I could of more help. Also note that the failing image displays fine in Paint, which is what the screenshots above visualizes.


>> You are displaying an empty image.
No I'm not. Issuing "oGdPictureImaging.ReleaseGdPictureImage(ImageID)" immediately before issuing "ImageID = oGdPictureImaging.CreateGdPictureImageFromFile(images.orig_path)" was an attempt to release everything before loading in the new image that ultimately fails, just in case it was an memory issue causing the problem. And if the code (as you suggest) was displaying an empty image, then all images would fail. Not the case here, as many images behave as expected and many do not, hence this thread and the title unreliable.


>> 1. You need to check if the image creation was successful by checking that the image identifier is not equal to 0.
>> 2. You need to check that the display was successful by checking the GdPictureStatus returned from the display function.

I'm doing this as you can see in the code above I'm also sending you 2 of the files that gdViewer is having issues with for your testing.
What do I do to fix this?

Thanks, Stanley
Attachments
_204322.jpg
Succeeds
_2c07114.jpg
Fails
_2c07181.jpg
Fails

stanlyn
Posts: 25
Joined: Wed Mar 05, 2014 8:29 pm

Re: Image Viewing Not Reliable in COM

Post by stanlyn » Mon Mar 17, 2014 12:30 am

More info...

I can reliably reproduce this behavior by;

Closing VFPsp2,
I restart VFP and load form,
Starting a loop where it loops thru/shows images for records 10 thru 15 and loop backwards from 15 thru 10 and back and forth this way. All is ok until about the 50th view where it stops showing the images with a status of 1, and only a few images will show past that point. Remember we are viewing the same images multiple times, and then bang, they quit showing. To get it to work again, I have to restart VFP, not close and reload the form. This behavior is consistent on both Win8-64 and XPsp3.

Initially, I thought the images were not being released from memory before loading the next. That was why I had the release statement before the new load.

Any thoughts, as at this point this confirms the images are good and permissions are ok which I already knew.

Thanks, Stanley

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Image Viewing Not Reliable in COM

Post by Loïc » Mon Mar 17, 2014 7:49 pm

Hello,

I think you have a memory leak caused by a non released image. This would explain why you are getting an empty image starting the n displaying process.

We can help you to debug the code if you replicate the problem in a small standalone application that you can share with us throught http://support.orpalis.com
What does status 1 mean? Where is it documented? Also I figured out that one of the possible GetStat() return values is OK which translates to numeric 0. Where is this documented? (the name to numeric translation)
I already replied to this question in another of your posts in the help-desk:
do you know that you have a very useful object browser available in vfp? By using it you will be able to obtain any enumeration members value available in the GdPicture COM edition.

How to use it:
tools / object browser
click the open type libray button (most top-left)
brows...
select GdPicture.NET.10.tlb file available in the redist folder
With best regards,

Loïc Carrère

stanlyn
Posts: 25
Joined: Wed Mar 05, 2014 8:29 pm

Re: Image Viewing Not Reliable in COM

Post by stanlyn » Tue Mar 18, 2014 8:08 am

Thanks Loic,

The constants reference is what I was looking for...

Could you output the 2000+ list with their values to a flat text file that I can use to create a VFP header file. So far, my testing with a header file that contains a list like this does work. Don't worry about the #DEFINE part, its the other 2000+ lines I'm trying to avoid their data entry. The VFP object browser does not have any printing capability, otherwise I'd output it myself. I also tried ocring screenshots, but the dpi is too low for good ocr results. I send you a copy of the completed header file.

*-- GdPictureOutputIntent
#DEFINE GdPictureOutputIntent_IntentBlackWhite 0
#DEFINE GdPictureOutputIntent_IntentColor 2
#DEFINE GdPictureOutputIntent_IntentGrayscale 1
#DEFINE GdPictureOutputIntent_IntentPalletized 3
#DEFINE GdPictureOutputIntent_IntentUnknown -1


*-- gdPictureStatus
#DEFINE GdPictureStatus_Aborted 9
#DEFINE GdPictureStatus_AccessDenied 12
#DEFINE GdPictureStatus_BadTwainState 32
#DEFINE GdPictureStatus_Barcode1DReaderPluginNotLoaded 1100
#DEFINE GdPictureStatus_Barcode1DReaderUnknownError 1101
#DEFINE GdPictureStatus_BarcodeBarcodeLengthMustBe12 1019
#DEFINE GdPictureStatus_BarcodeBarcodeLengthMustBe2 1023
#DEFINE GdPictureStatus_BarcodeBarcodeLengthMustBe5 1024
#DEFINE GdPictureStatus_BarcodeBarcodeLengthMustBe5or6or9or11 1018
#DEFINE GdPictureStatus_BarcodeBarcodeLengthMustBe8or12 1020

Thanks,
Stanley

stanlyn
Posts: 25
Joined: Wed Mar 05, 2014 8:29 pm

Re: Image Viewing Not Reliable in COM

Post by stanlyn » Wed Mar 19, 2014 8:02 am

Hi Loic,
I think you have a memory leak caused by a non released image. This would explain why you are getting an empty image starting the n displaying process.
More testing has revealed that the issue has something to do with the speed of loading the images and not a memory leak. In a loop where my code does this;

1. select next record in the image table,
2. display that image,
3. repeat steps 1 and 2 until we get to the end of table.

I've discovered if I put any kind of a wait/sleep mechanism of at least 35 milliseconds between steps 2 and the restart of step 1 the problem goes away. And, if I remove the wait mechanism it quits displaying after about 50 images.

Also, the images are not local to the machine, instead they are on the local gigabit network. Also note that both test machines are I7s on ssd drives, and of course you know how fast VFP is... Therefore to reproduce this behavior, you will need a fast environment. Also note the images are not stored in the table, only file paths.

You should be able to easily duplicate this behavior, and as I said earlier, this behavior is consistent on both WinXP and Win8-64.

Thanks, Stanley

SamiKharma
Posts: 352
Joined: Tue Sep 27, 2011 11:47 am

Re: Image Viewing Not Reliable in COM

Post by SamiKharma » Sun Apr 13, 2014 11:29 am

Hi,

We absolutely need a stand alone app in order to be able to reproduce the problem. That being said, again, we are quite certain it is a memory not being released issue. Please check that you do in fact release all unused resources. If you cannot, or you still face the problem, please reproduce the problem in a stand alone app aimed at just that and send it to us.

Best regards,
Sami

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest