delphi中DLL储存读取图片

delphi中DLL储存读取图片

unit Unit1;


interface


uses

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

  Dialogs, ExtCtrls,

  JPEG; //用来读取jpg图片


type

  TForm1 = class(TForm)

    Image1: TImage;

    procedure FormCreate(Sender: TObject);

    procedure FormDestroy(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;


var

  Form1: TForm1;

   FBestHate: TBitMap;  //用来储存所读取的图片


implementation


{$R *.dfm}


//自定义函数---从资源文件中调入图片

procedure LoadBmpFromRes(Instance: THandle; GraphicID: string; Bmp: TBitMap);

var

  RS: TResourceStream;

  Jpg: TJpegImage;

begin

  RS := TResourceStream.Create(Instance, GraphicID, RT_RCDATA);

  try

    Jpg := TJpegImage.Create;

    try

      Jpg.LoadFromStream(RS);

      Bmp.Assign(Jpg);

    finally

      Jpg.Free;

    end;

  finally

    RS.Free;

  end;

end;




procedure TForm1.FormCreate(Sender: TObject);

var

  DllHandle: THandle;

begin

  FBestHate := TBitMap.Create;

  DllHandle := LoadLibrary('picdll.dll');

  if DllHandle > 0 then

     LoadBmpFromRes(DllHandle, 'p1', FBestHate);

  //Image1.Picture.Bitmap:=FBestHate;

  Image1.Picture.Bitmap.Assign(FBestHate);

  FreeLibrary(DllHandle);  //FreeLibrary释放资源

end;



procedure TForm1.FormDestroy(Sender: TObject);

begin

 FBestHate.Free;

end;


end.


------

{$R 'pic.res' 'pic.rc'}


rc:


FrameFirst RCDATA FrameFirst.jpg

RES1001 RCDATA Loop0.bmp


----------------------------------------------------------------------------


相关推荐

[!--temp.pl--]