C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[72200] [답변] DB의 Blob타입 사이즈
정성훈.해미 [sage5nor] 4073 읽음    2014-12-29 14:59
확실한 답변은 아닙니다.
이럴수도 있으니 확인 해 보세요


저장, 읽기 코드는 문제없습니다만

읽어올 때 나는 에러를 보니
실제로  DB에 저장된 이미지 파일이 잘못되어서 나타난 듯합니다.

저장하는 부분이 코드상 문제가 없지만
DB의 해당 필드가 수용할 수 있는 최대크기보다 큰 데이터가 들어가면
에러가 나든지 데이터가 짤려서 들어갑니다.

오류 메시지: Portable Network Graphics" image is invalid because the decoder found an unexpected end of the file
는 DB에 저장될 때 데이터가 짤려서 저장되었기 때문에 발생하는 것 같습니다.

DB에서 Blob타입으로 정의된 wrkimage필드의 크기를 확인해 보세요.


그리고 혹시 모르니
코드에서 ADOQuery3를 Open하는 부분이 잘 못되었는지도

올려주신 소스에는 ADOQuery3->Open() 부분이 없네요..^^*




궁금이 님이 쓰신 글 :
: 답변 감사합니다. 주말은 잘 보내셨나요?
: 답변 주신대로 수정해보았지만 저장은 오류가 없는데 읽어오는 부분에서 동일한 오류가 발생하네요
: 정말 답답하네요 주변에 붙잡고 물어볼 사람도 없고 갑갑하네요
: 제가 한번에 알아듣고 처리 할수 있었으면 좋았을텐데 귀찮게 해드리는거 같아 미안합니다.
: 수정한 코드 확인부탁합니다. 감사합니다.
: //DB저장
: TPngImage* png1 = new TPngImage();
: TMemoryStream *stream1 = new TMemoryStream();
: Edit4->Text=ExtractFileName(OpenPictureDialog1->FileName);
: str=ExtractFileExt(Edit4->Text.Trim());
: if(str.UpperCase() == "PNG")
: {
:     png1->LoadFromFile(OpenPictureDialog1->FileName);
:     Image1->Picture->Assign(png1);
:         png1->SaveToStream(stream1);
: }
: ADOQuery1->Close();
: ADOQuery1->SQL->Clear();
: sql="insert into board1image(wrknum,filename,wrkimage,insid,insdate) values(";
: sql+="'"+wrknum.Trim()+"',";
: sql+="'"+filename.Trim()+"',";
: sql+=":DATA,";
: sql+="'"+WrkID.Trim()+"',";
: sql+="getdate())";
: ADOQuery1->SQL->Add(sql);
: ADOQuery1->Parameters->ParamByName("DATA")->LoadFromStream(stream1,ftBlob);
: ADOQuery1->ExecSQL();
: //DB읽어오기
: TMemoryStream *stream1 = new TMemoryStream();
: stream1 = (TMemoryStream*)ADOQuery3->CreateBlobStream(ADOQuery3->FieldByName("wrkimage"), bmRead);
: ItemName=ADOQuery3->FieldByName("filename")->AsString.Trim();
: str=ExtractFileExt(ItemName.Trim());
: if(str.UpperCase() == "PNG")
: {
:     TPngImage *png = new TPngImage;
:     png->LoadFromStream(stream1); //<-오류발생하는 부분
: 오류메세지:This "Portable Network Graphics" image is invalid because the decoder found an unexpected end of the file.
:     Image1->Picture->Assign(png);
:     delete png;
: }
:
:
: bugfree 님이 쓰신 글 :
: : DB 저장
: : TPngImage *png = new TPngImage;
: : TMemoryStream *stream = new TMemoryStream;
: :
: : if (파일익스텐션 == png)
: : {
: :      png->LoadFromFile ("test.png");
: :      png->SaveToStream (stream);
: :      Image1->Picture->Assign (png);
: : }
: : ......
: : ADOQuery1->Parameters->ParamByName ("DATA")->LoadFromStream (stream);
: :
: : 받아오는건 참고해서 하세요
: :
: :
: : 궁금이 님이 쓰신 글 :
: : : 먼저 답변 감사합니다.
: : : 제가 답변을 너무 늦게 봐서 이제서야 글을 올립니다.
: : :
: : : 지적해주신되로 저장 모듈을 바꾸어봤습니다.
: : : graphicEX 대신 pngimage 사용했습니다.
: : : 제가 맞게 수정했는지는 잘 모르겠습니다 ㅜ,.ㅜ
: : :
: : : 제가 기초가 부족하고 이미지 처리는 처음 다뤄보는거라 너무 어렵네요
: : : 그래서 그런지 역시나 오류가 발생하네요
: : : 제가 코딩을 보시고 문제점이나 고쳐야 할 사항이 있으면 지적 부탁합니다.
: : :
: : : 오류메세지 First chance exception at $76C2C42D. Exception class EPngUnexpectedEnd with message
: : : 'This "Portable Network Graphics" image is invalid because the decoder found an unexpected end of the file.'. Process EvaBoard.exe (436)
: : :
: : : //DB저장
: : : TPngImage* png1 = new TPngImage();
: : : TMemoryStream *ImageBuffer = new TMemoryStream();
: : : ImageBuffer->LoadFromFile(OpenPictureDialog1->FileName);
: : : png1->LoadFromStream(ImageBuffer);
: : : Image1->Picture->Bitmap->Assign(png1);
: : : delete ImageBuffer;
: : :
: : : TMemoryStream *stream1 = new TMemoryStream();
: : : if(str.UpperCase() == "PNG")
: : : {
: : :     png1->SaveToStream(stream1);
: : : }
: : : else if(str.UpperCase() == "JPG" || str.UpperCase() == "JPEG")
: : : {
: : :     Image1->Picture->Graphic->SaveToStream(stream1);
: : : }
: : : ADOQuery1->Close();
: : : ADOQuery1->SQL->Clear();
: : : sql="insert into board1image(wrknum,filename,wrkimage,insid,insdate) values(";
: : : sql+="'"+wrknum.Trim()+"',";
: : : sql+="'"+filename.Trim()+"',";
: : : sql+=":DATA,";
: : : sql+="'"+WrkID.Trim()+"',";
: : : sql+="getdate())";
: : : ADOQuery1->SQL->Add(sql);
: : : ADOQuery1->Parameters->ParamByName("DATA")->LoadFromStream(stream1,ftBlob);
: : : ADOQuery1->ExecSQL();
: : : //DB읽어오기
: : : TBlobStream *stream1;
: : :
: : : stream1 = (TBlobStream*)ADOQuery3->CreateBlobStream(ADOQuery3->FieldByName("wrkimage"), bmRead);
: : : ItemName=ADOQuery3->FieldByName("filename")->AsString.Trim();
: : : str=ExtractFileExt(ItemName.Trim());
: : : FileName1->Caption=ADOQuery3->FieldByName("filename")->AsString.Trim();
: : : if(str.UpperCase() == "PNG")
: : : {
: : :     TPngImage *png = new TPngImage;
: : :     png->LoadFromStream(stream1);//<-오류발생하는부분
: : :     Image1->Picture->Bitmap->Assign(png);
: : :     delete png;
: : : }
: : : else if(str.UpperCase() == "JPG" || str.UpperCase() == "JPEG")
: : : {
: : :     TJPEGImage *Jpeg = new TJPEGImage;
: : :     Jpeg->LoadFromStream(stream1);
: : :     Image1->Picture->Graphic=Jpeg;
: : :     delete Jpeg;
: : : }
: : :
: : :
: : :
: : : bugfree 님이 쓰신 글 :
: : : : 궁금이 님이 쓰신 글 :
: : : : : 버전: 빌더2010
: : : : : DB:MS-SQL2000
: : : : :
: : : : : 이미지를 DB에 저장했다가 불러오는 모듈을 개발중입니다.
: : : : : 기존에 단순 관리업무 모듈만 개발하다가 이미지 처리를 할려니 매우 방황하고 있습니다.
: : : : :
: : : : : 일단 포럼을 검색해보고 GraphicEx를 설치했습니다.
: : : : : 이미지 저장은 잘되는거 같습니다.
: : : : :
: : : : : 하지만 읽어와서 TImage에 표시하고 싶은데 잘 되지가 않네요.
: : : : : JPG는 잘되는거 같은데 PNG파일이 문제네요.
: : : : :
: : : : : 먼저 제가 사용한 코드를 적어보겠습니다.
: : : : : 잘못 된 부분이 있으면 지적 부탁합니다.
: : : : :
: : : : : 많은분들의 도움 부탁드립니다.
: : : : :
: : : : : #include <jpeg.hpp>
: : : : : #include <GraphicEx.hpp>
: : : : :
: : : : : //-이미지불러오기
: : : : : AnsiString str;
: : : : : Edit4->Text=ExtractFileName(OpenPictureDialog1->FileName);
: : : : : str=ExtractFileExt(Edit4->Text.Trim());
: : : : : if(str.UpperCase() == "PNG")
: : : : : {
: : : : :     TMemoryStream *ImageBuffer = new TMemoryStream();
: : : : :     ImageBuffer->LoadFromFile(OpenPictureDialog1->FileName);
: : : : :     TPNGGraphic* png = new TPNGGraphic();
: : : : :     png->LoadFromStream(ImageBuffer);
: : : : :     Image1->Picture->Bitmap->Assign(png);
: : : : :     delete png;
: : : : : }
: : : : : else
: : : : : {
: : : : :     Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName);
: : : : : }
: : : : : //-DB저장
: : : : : TMemoryStream *stream1 = new TMemoryStream();
: : : : : Image1->Picture->Graphic->SaveToStream(stream1);
: : : : : ADOQuery1->Close();
: : : : : ADOQuery1->SQL->Clear();
: : : : : sql="insert into board1image(wrknum,filename,wrkimage,insid,insdate) values(";
: : : : : sql+="'"+wrknum.Trim()+"',";
: : : : : sql+="'"+filename.Trim()+"',";
: : : : : sql+=":DATA,";
: : : : : sql+="'"+WrkID.Trim()+"',";
: : : : : sql+="getdate())";
: : : : : ADOQuery1->SQL->Add(sql);
: : : : : ADOQuery1->Parameters->ParamByName("DATA")->LoadFromStream(stream1,ftBlob);
: : : : : ADOQuery1->ExecSQL();
: : : : : //-DB불러오기
: : : : : TBlobStream *stream1;
: : : : : stream1 = (TBlobStream*)ADOQuery3->CreateBlobStream(ADOQuery3->FieldByName("wrkimage"), bmRead);
: : : : : FileName=ADOQuery3->FieldByName("filename")->AsString.Trim();
: : : : : str=ExtractFileExt(FileName.Trim());
: : : : : if(str.UpperCase() == "PNG")
: : : : : {
: : : : :     TPNGGraphic* png = new TPNGGraphic();
: : : : :     png->LoadFromStream(stream1);// <------오류발생하는 부분
: : : : :         //오류메세지"Cannot load image.Invalid or unexpected PNG image format."
: : : : :     Image1->Picture->Bitmap->Assign(png);
: : : : :     delete png;
: : : : : }
: : : : : else if(str.UpperCase() == "JPG" || str.UpperCase() == "JPEG")
: : : : : {
: : : : :     TJPEGImage *Jpeg = new TJPEGImage;
: : : : :     Jpeg->LoadFromStream(stream1);
: : : : :     Image1->Picture->Graphic=Jpeg;
: : : : :     delete Jpeg;
: : : : : }
: : : : :
: : : : :
: : : : png가 안니고 bmp로 저장되고 있어서 그래요
: : : : GraphicEx는 필요 없고요
: : : : TPngImage 이용하면 됩니다

+ -

관련 글 리스트
72180 [질문]PNG 이미지 DB에서 불러오기 궁금이 4452 2014/12/24
72188     Re:[질문]PNG 이미지 DB에서 불러오기 bugfree 4145 2014/12/25
72192         Re:Re:[질문]PNG 이미지 DB에서 불러오기 궁금이 3895 2014/12/26
72198             Re:Re:Re:[질문]PNG 이미지 DB에서 불러오기 bugfree 4558 2014/12/27
72199                 Re:Re:Re:Re:[질문]PNG 이미지 DB에서 불러오기 궁금이 4020 2014/12/29
72200                     [답변] DB의 Blob타입 사이즈 정성훈.해미 4073 2014/12/29
72201                         Re:[답변] DB의 Blob타입 사이즈 궁금이 4343 2014/12/29
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.