Q&A

  • [re] [질문]DB에 저장된 이미지를 불러오질 못합니다.
제가 코드를 모두 다 확인할 수는 없구요...

첨부파일은 John Herbster이 만든 BLOB에 JPEG이미지 넣는 예제인데 분석하셔서 무엇이 다른가 찾아보세요...

>안녕하십니까? 전봉수 입니다.
>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;
2  COMMENTS
  • Profile
    전봉수 2009.04.26 06:59
    최용일님 소스와 답변 감사 합니다.
    실행을 해보니 VarArrayOf <- 여기서 에러가 납니다. 그리고
    다른코드는 비스한것 같습니다.
    그리고 질문한 코드는 전부 델마당에서 검색로
  • Profile
    최용일 2009.04.26 07:53
    uses절에 variants유닛을 추가해서 컴파일해보세요.