먼저 테이블의 datatype를 Image로 해야겠죠.
bmp만 저장되고? memorystream으로 저장하고 읽을때 꼬리없애야합니다.
msaccess와 저장만 다르고 읽기는 같습니다.
//저장
<!--
procedure TRegSign_F.btnSaveClick(Sender: TObject);
var
oBmp : TBitmap;
MS : TMemoryStream;
begin
oBmp := TBitMap.Create;
MS := TMemoryStream.Create;
MS.Position := 0;
oBmp.Assign(imgSign.Picture.Bitmap);
oBmp.SaveToStream(MS);
with qryTemp do
begin
Active := False;
SQL.Text := 'update staff set apsign=:apsign where id =' + inttostr(gv_staff_id);
ParamByName('apsign').LoadFromStream(MS,ftBlob);
Execute;
end;
oBmp.Free;
end;
//읽기
with qryTemp do
begin
close;
SQL.Text := 'select * from staff where id =' + inttostr(gv_staff_id);
open;
end;
if qryTemp.FieldByName('apsign').IsBlob then
imgSign.Picture.Assign(qryTemp.FieldByName('apsign'));
참고로 bitmap 파일은 사이즈가 더 크기때문에 jpeg로 하는게 효율성이 잇다고 봅니다.
var
BitImage : TBitmap;
JpegImage : TJPEGImage;
MS: TMemoryStream;
begin
with Query_TEMP do
begin
//========================================================= Insert
Close;
SQL.Clear;
SQL.Add('INSERT INTO CCA0051T (EMPECD, SIMAGE, CRTEMP, CRTTIM, UPDEMP, UPDTIM )');
SQL.Add('VALUES (:EMPECD, :SIMAGE, :CRTEMP, :CRTTIM, :UPDEMP, :UPDTIM)');
ParamByName( 'EMPECD' ).AsString := dxMemData_MainMEMBER.AsString + ' ';
if Image_Open.Picture.Graphic is TBitmap then
begin //===================================================== BMP SAVE
BitImage := TBitmap.Create;
MS := TMemoryStream.Create;
MS.Position := 0;
if Image_Open.Picture.Graphic = nil then
begin
ParamByName( 'SIMAGE' ).Assign( Image_Open.Picture.Bitmap );
end else begin
BitImage.Assign( Image_Open.Picture.Bitmap );
BitImage.SaveToStream( MS );
ParamByName( 'SIMAGE' ).LoadFromStream( MS, ftBlob );
end;
BitImage.Destroy;
end else begin //=========================================== JPEG SAVE
JpegImage := TJPEGImage.Create;
MS := TMemoryStream.Create;
MS.Position := 0;
if Image_Open.Picture.Graphic = nil then
begin
ParamByName( 'SIMAGE' ).Assign( Image_Open.Picture.Bitmap );
end else begin
JPEGImage.Assign( Image_Open.Picture.Graphic );
JPEGImage.SaveToStream( MS );
ParamByName( 'SIMAGE' ).LoadFromStream( MS, ftBlob );
end;
JPEGImage.Destroy;
end;
ParamByName( 'CRTEMP' ).AsString := gs_UseEmpCd;
ParamByName( 'CRTTIM' ).AsString := FormatDateTime( 'YYYYMMDDHHMM', now );
ParamByName( 'UPDEMP' ).AsString := gs_UseEmpCd;
ParamByName( 'UPDTIM' ).AsString := FormatDateTime( 'YYYYMMDDHHMM', now );
ExecSQL;
MS.Destroy;
end;