ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Streaming scanner-acquired images to database

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
ChrmnMAO Posted - May 29 2014 : 13:05:19
I am having difficulties with saving multi-page TIFF images acquired from a scanner to my SQL Server database.

Saving an image acquired from a scanner to the database seems to work as expected. There are no errors, and there is binary data in the correct field in the record in the database. However, recalling it for display in TImageEnView and TImageEnMView controls results in the display of a zero-page, empty image. This has been tested with three different scanner models (and perhaps more) from Epson, HP and Xerox, with the same behavior.

Saving and recalling an image acquired from a file (rather than an image acquired from a scanner) saves and recalls correctly.

The following code is executed to save the image to the database whether acquired from a scanner or acquired by opening a file:

strm := TMemoryStream.Create;
imgMView.MIO.SaveToStreamTIFF(strm);
strm.Position := 0;
if FDebugMode then begin
strm.SaveToFile(IncludeTrailingBackslash(path) +
DebugImg_Save.tif');
strm.Position := 0;
end;
TBlobField(FImageDataSet.FieldByName(ImageFieldName)).LoadFromStream(strm);
FImageDataSet.Post;
FImageDataSet.ApplyUpdates(-1);

I am saving the image to a file immediately before saving it to the database (for debug purposes). This file always contains the expected image with no problems. I write out a similar file whenever the image is loaded back from the database, and it is always an empty 0k file. And, to be clear, these problems only pertain to cases where the image is acquired from a scanner.

Does anybody have any ideas on this? Are there characteristics of scanner-acquired images that require special handling? I am pretty stumped.

Thanks in advance,

Martin


20   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Aug 05 2014 : 19:21:23
Hi

Glad to hear you have found a solution.



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
ChrmnMAO Posted - Aug 05 2014 : 13:57:45
I am happy to say that I have found the cause of this behavior, and that the cause had to do with a dbExpress error, not an error in the ImageEn components, as I had theorized. Based on what I have read, this may only be an issue in the XE2 release.

The bug is that assigning a value of -1, which is supposed to mean no limit, does not work properly in the MaxBlobSize parameter in the TSQLConnection component and/or dbxconnections.ini file. Assigning the value of -1 to this parameter actually limits the blob size to 1Mb. Data is preserved in the first 1Mb of the data, but nulled for the remaining data (i.e., all data past the 1Mb threshold). Setting the MaxBlobSize to a specific value (I used 50000000 for 50Mbs) seems to allow all data to be saved and recalled.

An article that describes the problem as well as the solution:

http://stackoverflow.com/questions/12225450/tsqlquery-only-streams-first-1mb-of-data-correctly-for-large-strings

The following is a link to the Quality Central report:

http://qc.embarcadero.com/wc/qcmain.aspx?d=108475

Best Regards,

Martin
ChrmnMAO Posted - Jul 22 2014 : 09:34:49
Thanks Nigel,

I will package up the test project I have been working with, along with SQL Server table definition, and a sample file, so that you can take a look at it.

Also, I am open to hosting a GoToMeeting session if it would be helpful.

Thanks,

Martin
xequte Posted - Jul 19 2014 : 08:14:53
Hi Martin

Please send us a very simple test project that reproduces the issue.



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
ChrmnMAO Posted - Jul 14 2014 : 07:50:27
Hi Nigel,

Thanks for your reply. Unfortunately I cannot agree that this is an issue of DBMS setting, as the same problem does NOT occur when I stream from a file, save and refresh without involving the ImageEn component. This is demonstrated in the sample project I created, and whose partial source code I previously posted. Additionally, in the information I emailed you last week, there are indications that some of the tags are being changed when the TIFF file is being loaded into and read from the ImageEn component, and I have to believe this is related in some way to the problem.

I am still willing to provide any information I can to help resolve this issue, and I still consider this to be an open issue.

Thanks,

Martin
xequte Posted - Jul 11 2014 : 07:54:15
Hi

I have discussed this issue with my colleague in some depth, and it is our conclusion that this issue is not related to ImageEn. Once an image is in ImageEn (whether loaded, acquired, etc) it should not have any effect on what occurs when it is saved.

Our expectation is that the issue is in the DBMS (or possibly, ODBC connection) settings (translating/encoding etc…). You can confirm this by seeing if the problem goes away when you test the same code with another DBMS.

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
ChrmnMAO Posted - Jul 08 2014 : 13:55:08
Unfortunately, I got the same results. The files saved in steps 1-4 (ie1.tif, ie2.tif, ie3.tif, and ie4.tif) are all ok. File ie5.tif (saved in the last step), is corrupt. The code I used is shown below:

var
strm: TStream;

procedure SaveImage(Step: string);
var
filepath: array [0..MAX_PATH] of char;
path: string;
begin
SHGetFolderPath(0,CSIDL_LOCAL_APPDATA,0,SHGFP_TYPE_CURRENT,@filepath[0]);
path := filepath;
path := IncludeTrailingBackslash(path) + 'ProVantage\Totem\Imaging\';
TBlobField(ClientDataSet1.FieldByName('inv_image')).
SaveToFile(path+Step+'.tif');
end;

begin
ClientDataSet1.Open;
ClientDataSet1.Edit;
strm := ClientDataSet1.CreateBlobStream(ClientDataSet1.
FieldByName('inv_image'), bmRead);
try
ImageEnMView1.MIO.LoadFromStreamTIFF(strm);
ImageEnMView1.SelectedImage := 0;
ImageEnView1.Assign(ImageEnMView1.Bitmap);
finally
strm.Free;
end;

strm := ClientDataSet1.CreateBlobStream(
ClientDataSet1.FieldByName('inv_image'), bmWrite);
try
ImageEnMView1.MIO.SaveToStreamTIFF(strm);
finally
strm.Free;
end;

SaveImage('IE1');

SaveImage('IE2');

ClientDataSet1.Post;
SaveImage('IE3');

ClientDataSet1.ApplyUpdates(-1);
SaveImage('IE4');

ClientDataSet1.Refresh;
SaveImage('IE5');

ClientDataSet1.Close;
end;
xequte Posted - Jul 08 2014 : 09:16:04
Can you test using:

      stream := FImageDataSet.CreateBlobStream(FImageDataSet.FieldByName(ImageFieldName), bmWrite);
      try
        imgMView.MIO.SaveToStreamTIFF(stream);
      finally
        stream.Free();
      end;


And loading via:

    stream := FImageDataSet.CreateBlobStream(FImageDataSet.FieldByName(ImageFieldName), bmRead);
  try
    imgMView.MIO.LoadFromStreamTIFF(stream);
  finally
    stream.Free();
  end;



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
ChrmnMAO Posted - Jul 01 2014 : 08:37:56
Masrnet2006, I'm not quite sure what you are asking.

Anybody have any ideas as to why I am getting image corruption when a file is streamed into and out of the TImageEnMView component (but not when TImageEnMView is not used)?

Please see earlier posts for details. I can provide a sample file to go with the sample code if that would help.

This is becoming a critical issue at a client site, so I need to have resolution soon.

Thanks,

Martin
masrnet2006 Posted - Jun 11 2014 : 00:26:18
send me what do you want in app.
ChrmnMAO Posted - Jun 10 2014 : 11:25:54
I have created two test cases. The first opens a TIFF file, saves it to a stream, loads the image from the stream into a dataset field, posts, applies updates, and refreshes the dataset. I am saving the image to a file after every step. Relevant code follows:

FFileStream := TFileStream.Create(fileNm, fmOpenRead);
FFileStream.Seek(0,soFromBeginning);
FMemStream := TMemoryStream.Create;
FMemStream.LoadFromStream(FFileStream);
FMemStream.Postion := 0;
SaveImage('1');
ClientDataSet1.Open;
ClientDataSet1.Edit;
TBlobField(ClientDataSet1.FieldByName('inv_image')).LoadFromStream(FMemStream);
SaveImage('2');
ClientDataSet1.Post;
SaveImage('3');
ClientDataSet1.ApplyUpdates(-1);
SaveImage('4');
ClientDataSet1.Refresh;
SaveImage('5');
ClientDataSet1.Close;

The calls to SaveImage saves a file with the contents of the TBlobField, using TBlobField.SaveToFile. In all cases in the above, file 1 is empty and files 2-5 open normally after this code is executed.

In the second case, I went through similar steps. I open a TIFF file, saves it to a stream, load the stream into an TImageEnMView component, stream the image from the TImageEnMView component, load the image from the stream into a dataset field, post, apply updates, and refresh the dataset. This is the same as case 1, with the addition of streaming the image in and out of the TImageEnMView component. As before, I am saving the image to a file after every step. Relevant code follows:

FFileStream := TFileStream.Create(fileNm, fmOpenRead);
FFileStream.Seek(0,soFromBeginning);
FMemStream := TMemoryStream.Create;
FMemStream.LoadFromStream(FFileStream);
FMemStream.Postion := 0;
ImageEnMView1.Clear;
ImageEnMView1.MIO.LoadFromStreamTIFF(FMemStream);
ImageEnMView1.SelectedImage := 0;
ImageEnView1.Assign(ImageEnMView1.Bitmap);
strm := TMemoryStream.Create;
ImageEnMView1.MIO.SaveToStreamTIFF(strm,false);
SaveImage('IE1');
ClientDataSet1.Open;
ClientDataSet1.Edit;
TBlobField(ClientDataSet1.FieldByName('inv_image')).LoadFromStream(strm);
SaveImage('IE2');
ClientDataSet1.Post;
SaveImage('IE3');
ClientDataSet1.ApplyUpdates(-1);
SaveImage('IE4');
ClientDataSet1.Refresh;
SaveImage('IE5');
ClientDataSet1.Close;
strm.Free;
strm := nil;

Image files saved in step 1 is empty, those saved in steps 2-4 all open correctly. The file saved in step 5 (after the Refresh), gives an error that the file is corrupt when I try and open it.

The only difference between these two code snippets is the use of the TImageEnMView component in the second case. To me this indicates that something is happening to the image when it loaded into or read out of TImageEnMView, but I can't quite fathom why the corrupt file only occurs when I have saved the image to the dataset and refreshed.

If an example of the file would be helpful, I will gladly provide it so that others can experiment with it.
masrnet2006 Posted - Jun 08 2014 : 23:44:36
cycleConnection; // connect http if close

with TServerMethods_haClient.Create(RDM.SQLConnection.DBXConnection, false) do
begin
sStr := ha_DownLoad_SteamImage(Size,ha_imgloc);

STR := RDM.ha_GetStreamFileName(sStr, dir_save, Quality); // client function call

end;
masrnet2006 Posted - Jun 08 2014 : 23:31:02
the working save image to db is not good#1548;is very slow and others#1548; But you can save on the path #1548; if you work datasanp you can save stream on the database and save the path with app server and update db the image ='null,
if you want show the image you can download on the path;
ChrmnMAO Posted - Jun 06 2014 : 09:34:16
In the code below, you can see that I save additional image files at regular intervals to better ascertain when the image corruption is occurring. The files saved after the Post, and the file saved after the ApplyUpdates can be opened and viewed with no problem. Beginning with the files saved after Refresh, the files cannot be opened - there is a message that the file is corrupted.

It definitely seems to be the case that the file is corrupted as it is stored in the database - it is fine immefiately before, and corrupted immediately after is is refreshed from the database.

FImageDataSet.Post;

TBlobField(FImageDataSet.FieldByName(ImageFieldName)).
SaveToFile(IncludeTrailingBackslash(path) + 'DebugImg_AfterPost.tif');

FImageDataSet.ApplyUpdates(-1);

TBlobField(FImageDataSet.FieldByName(ImageFieldName)).
SaveToFile(IncludeTrailingBackslash(path)
'DebugImg_AfterApplyUpdates.tif');

seq := FImageDataSet.FieldByName('seq').AsInteger;

FImageDataSet.Refresh;

TBlobField(FImageDataSet.FieldByName(ImageFieldName)).
SaveToFile(IncludeTrailingBackslash(path) + 'DebugImg_AfterRefresh.tif');

FImageDataSet.Locate('seq',seq,[]);

TBlobField(FImageDataSet.FieldByName(ImageFieldName)).
SaveToFile(IncludeTrailingBackslash(path) + 'DebugImg_AfterLocate.tif');
ChrmnMAO Posted - Jun 05 2014 : 14:14:39
Thanks Masrnet2006,

I will compare your suggestions to my existing code and see where I can make changes.

Martin
ChrmnMAO Posted - Jun 05 2014 : 14:11:48
Thanks Nigel. To Confirm:

Scan document --> Stream to database --> FAIL
Scan document --> Stream to file --> Stream to database --> FAIL
Open older image file --> Stream to database --> SUCCESS
Open older image file --> Stream to file --> Stream to database --> SUCCESS
Open image file from just scanned document --> Stream to database --> FAIL

It seems to be that any image scanned some time ago can be displayed, saved and redisplayed without a problem. If an image is acquired via the ImageEn scanner logic, it displays correctly when first loaded, but does not save or redisplay correctly. If a file is scanned using the scanner manufacturer's interface, and saved, that file too displays correctly but does not save or redisplay correctly.

Not sure what this means...

Thanks,

Martin
masrnet2006 Posted - Jun 05 2014 : 01:10:07
load image from database and save in file and delete in dataBase
-----------
ms := TMemoryStream.Create;

TBlobField(server_SQLDataSet_Update.FieldByName('ADOCIMG')).SaveToStream(ms);

ms.Position := 0;
if ext = '.JPG' then
begin

imageenview.IO.LoadFromStream(ms);
// ImageEnView.IO.SaveToFile(ChangeFileExt(ha_imgloc, ext ));
imageenview.IO.SaveToFile(ChangeFileExt(ha_imgloc, '.JPG'));
end
else
ms.SaveToFile


ms.Free;

--------------
Client_strSQL := 'update ' + imageTableName +
' set ADOCIMG =' + '''' + '''' + ',STRDAT=' + '2014' + ' where arcsrl= ' + arcsrl_new; // +'''' + '''' ====== '' only


ha_strExecSQL(Client_strSQL);
masrnet2006 Posted - Jun 05 2014 : 00:56:08
function TRDM.ha_InsertQuery(Query: TClientDataSet; APAGECount: integer): string;
var
i: integer;
ms: TMemoryStream;
begin
with Query do // MainTable_Update
begin
insert;
TBlobField(Query.FieldByName('ADOCIMG')).LoadFromStream(ImageEnMView_Main_ms);
Post;
end;
end;
masrnet2006 Posted - Jun 05 2014 : 00:53:29
ImageEnVect.IO.Params.JPEG_Quality := Quality;
ImageEnMView_Main_ms := TMemoryStream.Create;
// ImageEnVect.IO.SaveToStream(ImageEnMView_Main_ms);
ImageEnVect.IO.SaveToStreamJpeg(ImageEnMView_Main_ms);
ImageEnMView_Main_ms.Position := 0;

str_Count := RDM.ha_InsertQuery(RDM.MainTable_Update, APAGESRL);
ImageEnMView_Main_ms.Free;
xequte Posted - Jun 02 2014 : 21:30:22
Actually in reviewing your first message, it seems to indicate that the failure is during the saving [to database] process (as loading from the database is too disconnected from the scanner interaction.

Please confirm:
SCAN -> Stream to Database = FAIL
FILE -> Load to Database = OK
SCAN -> Stream to File -> Load to Database (from File) = FAIL???

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com