We would like to view the images, using only the `IMAGE` field in DOCIMAGES table. What steps are needed to process/decode the DOCIMAGES content?
We have tried many unsuccessful solutions to the “Compressed bitmap of the full-sized/thumbnail version of the image”. Most of them involve variations of
* convert the large hexidecimal string to pairs of hexidecimal characters (each element represents a byte)
* decompress the byte array somehow (eg, https://stat.ethz.ch/R-manual/R-devel/library/base/html/memCompress.html)
* save to a *.bmp file.
Can someone please point us to a more precise definition of the `IMAGE` field? (Beyond the documentation's description: "A compressed bitmap of the full-sized image.") Can someone describe the specific steps how to convert the values from the table into viewable file? Thank you, Will
Found and adapted this from online. Will extract all the IMAGE fields from DOCIMAGES and save them to d:\temp (adjust as needed) as a .bmp file. I will warn you that I had trouble viewing these images until I used SnagIt Editor. I ran this in Oracle SQL Developer against the EMR eval database.
Declare
l_file utl_file.file_type;
l_buffer RAW(32767);
l_amount PLS_INTEGER := 32767;
l_pos PLS_INTEGER := 1;
l_blob_len PLS_INTEGER;
begin
for X in (select * from DOCIMAGES) loop
l_file := UTL_FILE.fopen('d:\TEMP', 'blob'||X.TITLE||'.bmp', 'wb', 32767);
l_blob_len := DBMS_LOB.getlength(X.IMAGE);
IF l_blob_len < 32767 then
dbms_output.put_line(systimestamp||' BLOB < 32767 bytes');
DBMS_LOB.read(X.IMAGE, l_blob_len, l_pos, l_buffer);
UTL_FILE.put_raw(l_file, l_buffer, TRUE);
dbms_output.put_line(systimestamp||' done');
ELSE
dbms_output.put_line(systimestamp||' BLOB >= 32767 bytes len '||l_blob_len);
WHILE l_pos < l_blob_len LOOP
DBMS_LOB.read(X.IMAGE, l_amount, l_pos, l_buffer);
UTL_FILE.put_raw(l_file, l_buffer, TRUE);
l_pos := l_pos + l_amount;
END LOOP;
dbms_output.put_line(systimestamp||' done');
END IF;
l_pos := 1;
l_amount := 32767;
utl_file.fclose(l_file);
end loop;
end;
And this process also worked - creates a zip file. Unzip and change the file extension on the ldr files to bmp. Same thing, could view in SnagIt Editor. You get both the thumbnail and the image this way.
http://www.thatjeffsmith.com/archive/2014/05/exporting-multiple-blobs-with-oracle-sql-developer/
Thank you, DavidShower, that worked well. I think I see how this differs from our attempts in R. Hopefully I'll finish that version and post it here, in case someone can use it later.