Author |
Topic |
ChrmnMAO
USA
19 Posts |
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
|
|
xequte
38602 Posts |
Posted - May 29 2014 : 20:18:46
|
Hi Martin
I can't see anything wrong with this and nothing comes to mind as the cause. As a test try loading the blob field from the file saved in FDebugMode, rather than directly from the stream. Does the issue still occur?
Nigel Xequte Software www.xequte.com nigel@xequte.com
|
|
|
ChrmnMAO
USA
19 Posts |
Posted - Jun 02 2014 : 10:19:26
|
Thanks Nigel,
I did as you suggested, and loaded the file saved from the blob field in debug mode. Loading from the file behaves the same as loading from the blob field.
In my previous post, I had said that the debug files written during the loading process had 0 bytes. This is not correct. They are actually the same size as the debug file saved during the save process. Double clicking on the one saved when loading however generates an error saying the TIF files have been corrupted. The file saved during saving opens fine with a double click. I am led more and more to the idea that something, either in saving or loading the image is corrupting the TIF, though I can't see how.
Also, it seems that TIFs scanned at a lower (200 or less) DPI sometimes work as expected (i.e., they can be saved and recalled with out a problem). This is not universally true however.
Any other ideas or feedback would be most appreciated!
Thanks,
Martin |
|
|
xequte
38602 Posts |
Posted - Jun 02 2014 : 21:25:32
|
Hi Martin
Firstly, try to narrow down where it is failing, either loading or saving (or, ye gads, both). I.e. use some other method (e.g. a database utility) to extract the image from the blob and test whether it is valid.
Assuming it is something in the loading from the database, then try using a different (non-ImageEn) method to extract the database data and check that it is valid. It sounds like the image is not related to ImageEn but something to do with database or possibly a memory issue.
Nigel Xequte Software www.xequte.com nigel@xequte.com
|
|
|
xequte
38602 Posts |
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
|
|
|
masrnet2006
Saudi Arabia
59 Posts |
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; |
|
|
masrnet2006
Saudi Arabia
59 Posts |
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
Saudi Arabia
59 Posts |
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); |
|
|
ChrmnMAO
USA
19 Posts |
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 |
|
|
ChrmnMAO
USA
19 Posts |
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
USA
19 Posts |
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');
|
|
|
masrnet2006
Saudi Arabia
59 Posts |
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; |
|
|
masrnet2006
Saudi Arabia
59 Posts |
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; |
|
|
ChrmnMAO
USA
19 Posts |
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
Saudi Arabia
59 Posts |
Posted - Jun 11 2014 : 00:26:18
|
send me what do you want in app. |
|
|
ChrmnMAO
USA
19 Posts |
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 |
|
|
xequte
38602 Posts |
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
USA
19 Posts |
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
38602 Posts |
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
USA
19 Posts |
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
38602 Posts |
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
|
|
|
Topic |
|