delphi - retrieve image saved on database -
this question has reply here:
how insert image database using tadoquery component only 2 answers store images in ms-access database using delphi6 1 replyi'm using code load images timage:
begin if openpicturedialog1.execute(self.handle) image1.picture.loadfromfile(openpicturedialog1.filename); end;
then i'm using code store ms access database:
var astream : tmemorystream; begin adotable1.append; astream := tmemorystream.create; seek image1.picture.graphic.savetostream(astream); astream.position := 0; if adotable1.active begin tblobfield(adotable1.fieldbyname('termograma')).loadfromstream(astream); end; astream.free; end; adotable1.post;
but want display these saved images on timage, can help me? images .jpeg format
as far tpicture not able decide kind of tgraphic has create loading, since stream not have extension filename have decide it, , assign graphic. in case tjpegimage picture.
var jpg:tjpegimage; ms:tmemorystream; begin jpg:=tjpegimage.create; ms:=tmemorystream.create; seek tblobfield(adotable1.fieldbyname('termograma')).savetostream(ms); ms.position := 0; jpg.loadfromstream(ms); image2.picture.assign(jpg); jpg.free; ms.free; end; end;
the next unit able store diffent graphicformats in blobfields. storage not compatible simple storing of image info because info graphicformat stored too, give ability create needed class loading.
unit loadsaveimageblobs; // 20120224 thomas wassermann // adapt. registerclasses , uses requirements // based on thought of emiliano sos interface uses classes,db,graphics,jpeg,pngimage; procedure savepicture2blob(blob: tblobfield; picture: tpicture); procedure loadpicturefromblob(picture: tpicture; blob: tblobfield); implementation procedure savepicture2blob(blob: tblobfield; picture: tpicture); var ms, ms2: tmemorystream; theclassname: ansistring; len: byte; begin ms := tmemorystream.create; seek blob.clear; theclassname := picture.graphic.classname; len := length(theclassname); ms.writebuffer(len, 1); if len > 0 ms.writebuffer(theclassname[1], len); ms2 := tmemorystream.create; seek picture.graphic.savetostream(ms2); ms2.position := 0; if ms2.size > 0 ms.copyfrom(ms2, ms2.size); ms2.free; end; blob.loadfromstream(ms); ms.free; end; end; procedure loadpicturefromblob(picture: tpicture; blob: tblobfield); var ms, ms2: tmemorystream; len: byte; theclassname: ansistring; graphic: tgraphic; graphicclass: tgraphicclass; begin ms := tmemorystream.create; blob.savetostream(ms); ms.position := 0; seek ms.readbuffer(len, 1); setlength(theclassname, len); if len > 0 ms.readbuffer(theclassname[1], len); graphicclass := tgraphicclass(findclass(theclassname)); if (graphicclass <> nil) , (len > 0) begin graphic := graphicclass.create; ms2 := tmemorystream.create; seek ms2.copyfrom(ms, ms.size - len - 1); ms2.position := 0; graphic.loadfromstream(ms2); ms2.free; end; picture.assign(graphic); end; ms.free; end; end; initialization // might register others if wished registerclasses([ticon, tmetafile, tbitmap, tjpegimage,tpngimage]); end.
delphi ms-access delphi-xe3
No comments:
Post a Comment