Home > Back-end > How Sql to add images on the table?
How Sql to add images on the table?
Time:11-02
Photo: rdphoto (need to support flow deposit)
CodePudding user response:
This is my the source of the project: //save picture Procedure TfrmSetPrintFormat. SaveImage (); Var Stream: TMemoryStream; The begin If imgTicket. Picture. Width=0 then //no PIC The Exit; Stream:=TMemoryStream. Create;//create a memory stream Case intPictureType of 1: ImgTicket. Picture. Graphic. SaveToStream (Stream);//save the picture the memory stream 2: ImgTicket. Picture. Bitmap. SaveToStream (Stream).//save the picture the memory stream 0: ImgTicket. Picture. Bitmap. SaveToStream (Stream).//save the picture the memory stream end;
ImgTicket. Picture. Graphic. SaveToStream (Stream);//save the picture the memory stream QSet. Close; QSet. The Parameters. The Clear; QSet. SQL. The Clear; QSet. SQL. Add (' UPDATE PrintScheme SET Photo=: Photo of PhotoType='+ IntToStr (intPictureType) + 'WHERE ID=' + IntToStr (intSchemeContentID)); QSet. The Parameters. ParamByName (' photo.) LoadFromStream (Stream, ftBlob);//read save memory map QSet. ExecSQL; Stream. Free;//release the memory flow end; //load the picture Procedure TfrmSetPrintFormat. LoadImage; Var Stream: TMemoryStream; Jpg: TjpegImage; PNG: TPngImage; The begin If not OpenSQL (qSet, 'the SELECT Photo, PhotoType FROM PrintScheme WHERE ID=' + IntToStr (intSchemeContentID)) then The Exit; If qSet. Eof then The Exit; If not qSet. FieldByName (' Photo.) IsNull then The begin //read picture type IntPictureType:=qSet FieldByName (' PhotoType). AsInteger; //load the picture Stream:=TMemoryStream. Create; TBlobField (qSet FieldByName (' Photo ')). SaveToStream (Stream);//display into BlobField and save the memory stream Stream. Position:=0; Case intPictureType of 1: The begin Jpg:=TjpegImage. Create; Jpg. LoadFromStream (Stream);//load the picture ImgTicket. Picture. Graphic. Assign (Jpg); Jpg. Free; end; 2: The begin PNG:=TPngImage. Create; PNG. LoadFromStream (Stream);//load the picture ImgTicket. Picture. The Bitmap. The Assign (Png); PNG. Free; end; 0: ImgTicket. Picture. Bitmap. LoadFromStream (Stream). The else ImgTicket. Picture:=nil; end; Stream. Free; End The else The begin ImgTicket. Picture:=nil; end; end;