안녕하십니까? 전봉수 입니다.
DB에 이미지 저장 불러오기 질답과 질문을 수십차래하여 아래 소스를
만들어 저장은 잘 되는것 같은데요 수정(불러오기)를 하면 코드를 중심
으로 다른 코드나 일자는 제대로 불러오는데 이미지는 안보입니다니다.
저장할때 이미지가 저장이 안되는것인지 불러오는 소스 코팅이 잘못
되었는지 막연합니다. 이미지는 도장을 jpg로 스켄하여 사내 네트워크
상에서 업무일지 결재용으로 사용하려고 합니다.
프로그램을 다 만들어서 사용은 하고 있는데 현재는 프린트를 하여 사용
하고 있습니다.
운영체제 wIN_xp 델파이6.0 인터프리즈 DB는 파라독스를 사용하고
있습니다.
// 이미지 불러오기
// 을측 작성자
procedure TMupmuForm.Btn_IdClick(Sender: TObject);
begin
IF OpenPictureDialog1.Execute then
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
imgflag := True;
end;
// 을측 검토
procedure TMupmuForm.Btn_IkClick(Sender: TObject);
begin
IF OpenPictureDialog1.Execute then
Image2.Picture.LoadFromFile(OpenPictureDialog1.FileName);
imgflag := True;
end;
//을측 승인
procedure TMupmuForm.Btn_IsClick(Sender: TObject);
begin
IF OpenPictureDialog1.Execute then
Image3.Picture.LoadFromFile(OpenPictureDialog1.FileName);
imgflag := True;
end;
// 갑측검토
procedure TMupmuForm.Btn_KdClick(Sender: TObject);
begin
IF OpenPictureDialog1.Execute then
Image4.Picture.LoadFromFile(OpenPictureDialog1.FileName);
imgflag := True;
end;
// 갑측 승인
procedure TMupmuForm.Btn_KsClick(Sender: TObject);
begin
IF OpenPictureDialog1.Execute then
Image5.Picture.LoadFromFile(OpenPictureDialog1.FileName);
imgflag := True;
end;
// 작성(추가)
procedure TMupmuForm.Sp_AppClick(Sender: TObject);
begin
Table1.Insert ;
Image1.Picture := nil;
Image2.Picture := nil;
Image3.Picture := nil;
Image4.Picture := nil;
Image5.Picture := nil;
//setbtnenable;
end;
// 결재(수정)
procedure TMupmuForm.sp_UpClick(Sender: TObject);
begin
Table1.Edit;
Image1.Picture := nil;
Image2.Picture := nil;
Image3.Picture := nil;
Image4.Picture := nil;
Image5.Picture := nil;
//setbtnenable;
end;
// 이미지 저장
procedure TMupmuForm.sp_SaveClick(Sender: TObject);
var
s : TStream;
j : TJPEGImage;
begin
if not Table1.Active then
Table1.Open;
try
with Table1 do
begin
FieldByName('Icode').AsString := ED_Icode.Text;
FieldByName('Idate').AsString := ED_PIMdate.Text;
FieldByName('Scode').AsString := ED_PIScode.Text;
FieldByName('Hcode').AsString := ED_PIHcode.Text;
// 이미지 저장(삽입)
IF image1.picture.Graphic <> nil Then
Begin
s := table1.createblobstream(table1.fieldbyname('Idimg'), bmwrite) ;
j := TJPEGImage.Create;
try
if imgflag then
begin
//image1.picture.assign(j) ;
j.LoadFromFile(OpenPictureDialog1.FileName);
TJPEGImage(j).SaveToStream(s);
Table1.post;
//setbtnenable;
end;
finally
imgflag := False;
s.Free;
j.Free;
end;
End
Else
IF image2.picture.Graphic <> nil Then
Begin
s := table1.createblobstream(table1.fieldbyname('Ikimg'), bmwrite) ;
j := TJPEGImage.Create;
try
if imgflag then
begin
//image2.picture.assign(j) ;
j.LoadFromFile(OpenPictureDialog1.FileName);
TJPEGImage(j).SaveToStream(s);
Table1.post;
//setbtnenable;
end;
finally
imgflag := False;
s.Free;
j.Free;
end;
End
Else
IF image3.picture.Graphic <> nil Then
Begin
s := table1.createblobstream(table1.fieldbyname('Isimg'), bmwrite) ;
j := TJPEGImage.Create;
try
if imgflag then
begin
//image3.picture.assign(j) ;
j.LoadFromFile(OpenPictureDialog1.FileName);
TJPEGImage(j).SaveToStream(s);
Table1.post;
//setbtnenable;
end;
finally
imgflag := False;
s.Free;
j.Free;
end;
End
Else
IF image4.picture.Graphic <> nil Then
Begin
s := table1.createblobstream(table1.fieldbyname('Kdimg'), bmwrite) ;
j := TJPEGImage.Create;
try
if imgflag then
begin
//image4.picture.assign(j) ;
j.LoadFromFile(OpenPictureDialog1.FileName);
TJPEGImage(j).SaveToStream(s);
Table1.post;
//setbtnenable;
end;
finally
imgflag := False;
s.Free;
j.Free;
end;
End
Else
IF image5.picture.Graphic <> nil Then
Begin
s := table1.createblobstream(table1.fieldbyname('Ksimg'), bmwrite) ;
j := TJPEGImage.Create;
try
if imgflag then
begin
//image5.picture.assign(j) ;
j.LoadFromFile(OpenPictureDialog1.FileName);
TJPEGImage(j).SaveToStream(s);
Table1.post;
//setbtnenable;
end;
finally
imgflag := False;
s.Free;
j.Free;
end;
End
End;
Except
ShowMessage('이미지 입력(저장)을 확인해 주세요');
Table1.Delete;
Table1.first;
exit;
end;
ShowMessage('이미지 입력 저장완료');
Table1.first;//프로시져로서 위 텍스트의 내용이 지워지게 합니다.
end;
// DB저장 이미지 확인(불러오기)
procedure TMupmuForm.Sp_EditClick(Sender: TObject);
var
s : TStream;
j : TJPEGImage;
begin
sp_UpClick(Sender);
if not Table1.Active then
Table1.Open;
try
with Table1 do
begin
if FindKey([ED_Icode.Text]) then
begin
FieldByName('Icode').AsString := ED_Icode.Text;
FieldByName('Idate').AsString := ED_PIMdate.Text;
FieldByName('Scode').AsString := ED_PIScode.Text;
FieldByName('Hcode').AsString := ED_PIHcode.Text;
// 이미지 불러오기
IF image1.picture.Graphic <> nil Then
Begin
if Table1.State = dsbrowse then
begin
s := Table1.CreateBlobStream(Table1.FieldByName('Idimg'),bmread);
j := TJPEGImage.Create;
try
j.LoadFromStream(s);
Image1.Picture.Assign(j);
finally
s.Free;
j.Free;
end;
end;
End
Else
IF image2.picture.Graphic <> nil Then
Begin
if Table1.State = dsbrowse then
begin
s := Table1.CreateBlobStream(Table1.FieldByName('Ikimg'),bmread);
j := TJPEGImage.Create;
try
j.LoadFromStream(s);
Image2.Picture.Assign(j);
finally
s.Free;
j.Free;
end;
end;
End
Else
IF image3.picture.Graphic <> nil Then
Begin
if Table1.State = dsbrowse then
begin
s := Table1.CreateBlobStream(Table1.FieldByName('Isimg'),bmread);
j := TJPEGImage.Create;
try
j.LoadFromStream(s);
Image3.Picture.Assign(j);
finally
s.Free;
j.Free;
end;
end;
End
Else
IF image4.picture.Graphic <> nil Then
Begin
if Table1.State = dsbrowse then
begin
s := Table1.CreateBlobStream(Table1.FieldByName('Kdimg'),bmread);
j := TJPEGImage.Create;
try
j.LoadFromStream(s);
Image4.Picture.Assign(j);
finally
s.Free;
j.Free;
end;
end;
End
Else
IF image5.picture.Graphic <> nil Then
Begin
if Table1.State = dsbrowse then
begin
s := Table1.CreateBlobStream(Table1.FieldByName('Ksimg'),bmread);
j := TJPEGImage.Create;
try
j.LoadFromStream(s);
Image5.Picture.Assign(j);
finally
s.Free;
j.Free;
end;
end;
End;
End;
End;
Except
ShowMessage('이미지 (확인)불러오기를 확인해 주세요');
Table1.Delete;
Table1.first;
exit;
end;
ShowMessage('이미지 확인(불러오기)완료');
Table1.first;//프로시져로서 위 텍스트의 내용이 지워지게 합니다.
end;
아래는 DB로 부터 그림을 읽어오기 부분 입니다.
--------------------------------------------------------------------------------------------
with aqryBLRM_USERD1 do
begin
Screen.Cursor := crSQLWait;
if(Active) then Close;
SQL.Clear;
SQL.Text :=
' SELECT * FROM BLRM_USERD1 '+#13+
' WHERE USERD1_NO = 0'+ txtUSER_NO.Text +' ';
Open;
cmbGRCLASS.Properties.ReadOnly := False;
i := FieldByName('USERD1_CLASS').AsInteger;
cmbGRCLASS.ItemIndex := i;
cmbGRCLASS.Properties.ReadOnly := True;
//-----
MemoryStream := TMemoryStream.Create;
if(i = 0) then // BitMap
begin
BMapImg := TBitMap.Create;
aqryBLRM_USERD1USERD1_STAMPIMG.SaveToStream(MemoryStream);
MemoryStream.Position := 0;
BMapImg.LoadFromStream(MemoryStream);
imgUSERD1_STAMPIMG.Picture.Assign(BMapImg);
BMapImg.Free;
end;
if(i = 1) then // JPEG
begin
JPegImg := TJPegImage.Create;
aqryBLRM_USERD1USERD1_STAMPIMG.SaveToStream(MemoryStream);
MemoryStream.Position := 0;
JPegImg.LoadFromStream(MemoryStream);
imgUSERD1_STAMPIMG.Picture.Assign(JPegImg);
JPegImg.Free;
end;
if(i = 2) then // GIF
begin
GIFImg := TGIFImage.Create;
aqryBLRM_USERD1USERD1_STAMPIMG.SaveToStream(MemoryStream);
MemoryStream.Position := 0;
GIFImg.LoadFromStream(MemoryStream);
imgUSERD1_STAMPIMG.Picture.Assign(GIFImg);
GIFImg.Free;
end;
MemoryStream.Free;
Screen.Cursor := crDefault;
end;
--------------------------------------------------------------------------------------------
아래는 그림이미지를 저장하는 부분 입니다.
Screen.Cursor := crSQLWait;
with aqryBLRM_USERD1 do
begin
if(Active) then Close;
SQL.Clear;
SQL.Text :=
' DELETE FROM BLRM_USERD1 '+#13+
' WHERE USERD1_NO = 0'+ txtUSER_NO.Text +' ';
ExecSQL;
//-----
if(imgUSERD1_STAMPIMG.Picture.Graphic <> nil) then // 이미지 데이터가 존재하는 경우에만..,
begin
if(Active) then Close;
SQL.Clear;
SQL.Text :=
' INSERT INTO BLRM_USERD1 ( '+#13+
' USERD1_NO, '+#13+
' USERD1_CLASS, '+#13+
' USERD1_STAMPIMG ) VALUES ( '+#13+
' 0'+ txtUSER_NO.Text +', '+#13+
' 0'+ IntToStr(cmbGRCLASS.ItemIndex) +', '+#13+
' :USERD1_STAMPIMG ) '+#13;
MemoryStream := TMemoryStream.Create;
imgUSERD1_STAMPIMG.Picture.Graphic.SaveToStream(MemoryStream);
Parameters[0].LoadFromStream(MemoryStream, ftBlob);
MemoryStream.Free;
ExecSQL;
end;
end;
Screen.Cursor := crDefault;