rencarnacion Posted December 9, 2013 Posted December 9, 2013 Hello, I need some help with dbimage Field and the problem is when I try to show a jpg in a dbimage I got the Following Error "Bitmap image is not valid." I'm using bmp I'm just Using Jpg. It's mean that Unigui Can display BMP ? Thanks for you help Delphi XE2 Unigui 0.93 Quote
AlbertoVesx Posted December 9, 2013 Posted December 9, 2013 Zilav shared this "You are writing for a web browser. Just drop an image file somewhere and link to it with <img src=...> tag, thats all. Browser knows about image formats way more than you.That ShowImage procedure is the worst piece of code for web. So much mess for doing so little.It's only usefulness is when app needs to work with both web and VCL the same way. If it is not your aim, don't do that. Don't forget to add some random value at the end of url like "image.jpg?3554356756756" so the image won't be loaded from browser's cache the next time it is refreshed." procedure TMainForm.SetImageUrl(BlobFld: TField; UniImage: TUniImage; fileName: String);var Tmp,TmpFile:String;begin Tmp:= 'Tmp_' +UnitName +IntToStr(BlobFld.DataSet.RecNo) +fileName; TmpFile:= UniServerModule.LocalCachePath +Tmp; if (not FileExists(PChar(TmpFile))) then TBlobField(BlobFld).SaveToFile(PChar(TmpFile)); try UniImage.Url:= ''; UniImage.Refresh; UniImage.Url:= UniServerModule.LocalCacheURL +Tmp; except end;end; Quote
ganzqgy Posted December 10, 2013 Posted December 10, 2013 //读取数据库图片数据procedure TuDBGridFrame.UniDBGrid1CellClick(Column: TUniDBGridColumn);// UniGUIAbstractClassesvar jpegimage: tjpegimage; bmpimage: TBitMap; BlobStream: TStream; Buffer: WORD;begin with ADOTable1 do begin if (not fieldbyname('photo').IsNull) then // 字段无内容 begin BlobStream := CreateBlobStream(fieldbyname('photo'), bmRead); BlobStream.Position := 0; BlobStream.ReadBuffer(Buffer, 2); // 读取文件前2个字节 BlobStream.Position := 0; if Buffer = $4D42 then// $4D42'BMP'$D8FF'JPEG'$4947 'GIF'$050A'PCX'$5089 'PNG'$4238'PSD'$A659'RAS'$DA01'SGI'$4949'TIFF' begin bmpimage := TBitMap.Create; try bmpimage.LoadFromStream(BlobStream); UniImage1.Picture.bitmap.Assign(bmpimage); UniImage1.Visible := true; finally bmpimage.Free; BlobStream.Free; end; end; if Buffer = $D8FF then // 如果前两个字节是以D8FF[JPG] begin jpegimage := tjpegimage.Create; try jpegimage.LoadFromStream(BlobStream); UniImage1.Picture.Assign(jpegimage); UniImage1.Visible := true; finally jpegimage.Free; BlobStream.Free; end; end; end else UniImage1.Visible := False; end;end; Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.