»áÔ±£º ÃÜÂ룺 ¡¡Ãâ·Ñ×¢²á | Íü¼ÇÃÜÂë | »áÔ±µÇ¼ ÍøÒ³¹¦ÄÜ£º ¼ÓÈëÊÕ²Ø ÉèΪÊ×Ò³ ÍøÕ¾ËÑË÷  
 °²È«¼¼Êõ¼¼ÊõÎĵµ
  ¡¤ °²È«ÅäÖÆ
  ¡¤ ¹¤¾ß½éÉÜ
  ¡¤ ºÚ¿Í½Ìѧ
  ¡¤ ·À»ðǽ
  ¡¤ Â©¶´·ÖÎö
  ¡¤ ÆƽâרÌâ
  ¡¤ ºÚ¿Í±à³Ì
  ¡¤ ÈëÇÖ¼ì²â
 °²È«¼¼ÊõÂÛ̳
  ¡¤ °²È«ÅäÖÆ
  ¡¤ ¹¤¾ß½éÉÜ
  ¡¤ ·À»ðǽ
  ¡¤ ºÚ¿ÍÈëÇÖ
  ¡¤ Â©¶´¼ì²â
  ¡¤ Æƽⷽ·¨
  ¡¤ É±¶¾×¨Çø
 °²È«¼¼Êõ¹¤¾ßÏÂÔØ
  ¡¤ É¨Ã蹤¾ß
  ¡¤ ¹¥»÷³ÌÐò
  ¡¤ ºóÃÅľÂí
  ¡¤ ¾Ü¾ø·þÎñ
  ¡¤ ¿ÚÁîÆƽâ
  ¡¤ ´úÀí³ÌÐò
  ¡¤ ·À»ðǽ
  ¡¤ ¼ÓÃܽâÃÜ
  ¡¤ ÈëÇÖ¼ì²â
  ¡¤ ¹¥·ÀÑÝʾ
¼¼ÊõÎĵµ > Delphi
DELPHI´æÈ¡JPEGÎļþµ½SQL ServerÊý¾Ý¿â
·¢±íÈÕÆÚ£º2003-07-23 00:00:00×÷Õߣº¸ ³ö´¦£º  

½üÈÕ±ÊÕßÊéдһ¸öСÐ͵ÄѧÉú¹ÜÀíϵͳʱ£¬ÐèÒªÓõ½ADO¿Ø¼þ´æÈ¡SQL ServerÊý¾Ý¿âͼƬ£¬²é¿´×ÊÁÏ·¢ÏÖ»ù±¾¶¼ÊÇÕë¶ÔBMPÎļþ½øÐвÙ×÷(¾ÞÔöÊý¾Ý¿â´óС)£¬µ«·¢ÏÖÁË¡ïeagletian¡ï¸ßÊÖ·­ÒëµÄADOÓ¢Îļ¼ÊõÎĵµ£¬ÀïÃæÉæ¼°µ½ÁËÊý¾Ý¿â´æÈ¡JPEGÎļþµÄ¹Ø¼ü¼¼Êõ£¬ÔÚwin98+sql server×ÀÃæ°æÖвâÊÔͨ¹ý£¬ÔËÐÐÁ¼ºÃ£¬ÏÖÓÚÔ´Â빫¿ªÈçÏ£º

unit Unit1;

interface

uses

 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

 ExtCtrls, DBCtrls, Grids, DBGrids, Db, ADODB,jpeg, StdCtrls,dbtables;

  {Ò»¶¨ÒªUSES JPEGµ¥Ôª,ʹÄÜ´æ´¢JPGÎļþ¸ñʽ}

type

 TForm1 = class(TForm)

  DataSource1: TDataSource;

  ADOQuery1: TADOQuery;

  DBGrid1: TDBGrid;

  DBNavigator1: TDBNavigator;

  Image1: TImage;

  savebutton: TButton;

  showbutton: TButton;

  OpenDialog1: TOpenDialog;

  ADOQuery1id: TIntegerField;

  ADOQuery1pic: TBlobField;

  procedure savebuttonClick(Sender: TObject);

  procedure showbuttonClick(Sender: TObject);

  procedure DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);

 private

  { Private declarations }

 public

  { Public declarations }

 end;

var

 Form1: TForm1;

implementation

{$R *.DFM}

function JpegStartsInBlob(PicField:TBlobField):integer;

  var

  ghy: TADOBlobstream;

  buffer:Word;

  hx: string;

  begin

  Result := -1;

  ghy := TADOBlobstream.Create(PicField, bmRead);

  try

   while (Result = -1) and (ghy.Position + 1 < ghy.Size) do

   begin

   ghy.ReadBuffer(buffer, 1);

   hx:=IntToHex(buffer, 2);

   if hx = ¡¯FF¡¯ then begin

    ghy.ReadBuffer(buffer, 1);

    hx:=IntToHex(buffer, 2);

   if hx = ¡¯D8¡¯ then Result := ghy.Position - 2

    else if hx = ¡¯FF¡¯ then

       ghy.Position := ghy.Position-1;

   end; //if

   end; //while

   finally

   ghy.Free

   end; //try

  end;

procedure TForm1.savebuttonClick(Sender: TObject);

var

picstream:tadoblobstream;

begin

adoquery1.edit;

picstream:=tadoblobstream.Create(tblobfield(adoquery1.fields[1]),bmWrite);

if form1.opendialog1.execute then

begin

picstream.LoadFromFile(opendialog1.filename);

picstream.Position:=0;

adoquery1.edit;

tblobfield(adoquery1.Fields[1]).loadfromstream(picstream);

adoquery1.post;

end;

end;

procedure TForm1.showbuttonClick(Sender: TObject);

var

ghy:TADOBlobstream;

pic:tjpegimage;

begin

ghy := TADOBlobstream.Create(Adoquery1pic, bmRead);

try

 ghy.Seek(JpegStartsInBlob(Adoquery1pic),soFromBeginning);

 Pic:=TJpegImage.Create;

 try

  Pic.LoadFromStream(ghy);

  Image1.Picture.Graphic:=Pic;

 finally

  Pic.Free;

 end;

finally

ghy.Free

end;

end;

procedure TForm1.DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);

begin

if button in [nbFirst, nbPrior, nbNext, nbLast] then showbutton.Click;

end;

end.

Èç¹ûÊý¾Ý¿âÖÐÒª´æ´¢µÄÊÇBMPÎļþ£¬ÔòÔÚprocedure TForm1.showbuttonClick(Sender: TObject);¹ý³ÌÖдúÂë¸ü¸ÄÈçϼ´¿É´æ´¢ÏÔʾBMPÎļþ¸ñʽµÄ²Ù×÷¡£

procedure TForm1.showbuttonClick(Sender: TObject);

var

ghy:TADOBlobstream;

pic:tbitmap;

begin

ghy := TADOBlobstream.Create(Adoquery1pic, bmRead);

try

{ ghy.Seek(JpegStartsInBlob(Adoquery1pic),soFromBeginning);}

 Pic:=Tbitmap.Create;

 try

  Pic.LoadFromStream(ghy);

  Image1.Picture.Graphic:=Pic;

 finally

  Pic.Free;

 end;

finally

ghy.Free

end;

end;

¡¡¡¡µ½´ËÓÃDELPHI´æÈ¡JPEGÎļþµ½SQL ServerÊý¾Ý¿âÖеľßÌå²Ù×÷ÒѾ­ÐðÊöÍê±Ï¡£

ÎÒµÄÍøÕ¾£º

http://delphijl.99898.com

QQ:123168091

¡¾·µ»Ø¶¥²¿¡¿ ¡¾´òÓ¡±¾Ò³¡¿ ¡¾¹Ø±Õ´°¿Ú¡¿

¹ØÓÚÎÒÃÇ / ¸øÎÒÁôÑÔ / °æȨ¾Ù±¨ / Òâ¼û½¨Òé / ÍøÕ¾±à³ÌQQȺ   
Copyright ©2003- 2024 Lihuasoft.net webmaster(at)lihuasoft.net ¼ÓÔØʱ¼ä 0.00181