YH80A_GetPicture为c++写的动态链接库dll中的函数var
pBuf: DWORD;
Length: integer; FileHandle: Integer;
begin
YH80A_GetPicture(0,1,@pBuf,@Length);//成功执行
image1.picture.bitmap:=@pBuf ???
或
FileHandle := FileCreate('c:\pp.bmp');
FileWrite(FileHandle, pBuf, SizeOf(pBuf)); ???
pBuf: DWORD;
Length: integer; FileHandle: Integer;
begin
YH80A_GetPicture(0,1,@pBuf,@Length);//成功执行
image1.picture.bitmap:=@pBuf ???
或
FileHandle := FileCreate('c:\pp.bmp');
FileWrite(FileHandle, pBuf, SizeOf(pBuf)); ???
请问能讲详细点吗?
pBuf 是DWORD类型,不知怎么操作?
得到的pBuf是不是裸数据?如果是的话。
那么通过如下操作,可建立位图。
var
bmp: TBitmap;
i, j: integer;
p: pByteArray;
begin
bmp := TBitmap.Create;
bmp.width := ...
bmp.hight := ...
for i := 0 to bmp.height-1 do begin
p := bmp.ScanLine[i];
for j := 0 to bmp.width-1 do begin
end;
p[]
end;
bmp.Free;
bmp := nil;
end;
var
bmp: TBitmap;
i, j: integer;
p: pByteArray;
begin
bmp := TBitmap.Create;
bmp.width := ...
bmp.hight := ...
for i := 0 to bmp.height-1 do begin
p := bmp.ScanLine[i];
for j := 0 to bmp.width-1 do begin
p[j] := pBuf[j];
end;
end;
bmp.Free;
bmp := nil;
end;
运行后=22151168, 如果定义成array, 就会得到无数的类似22151168的数...
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,JPEG;type
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
hWndC: THandle;implementation
const WM_CAP_START = WM_USER;
const WM_CAP_STOP = WM_CAP_START + 68;
const WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10;
const WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11;
const WM_CAP_SAVEDIB = WM_CAP_START + 25;
const WM_CAP_GRAB_FRAME = WM_CAP_START + 60;
const WM_CAP_SEQUENCE = WM_CAP_START + 62;
const WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20;
const WM_CAP_SEQUENCE_NOFILE =WM_CAP_START+ 63;
const WM_CAP_SET_OVERLAY =WM_CAP_START+ 51;
const WM_CAP_SET_PREVIEW =WM_CAP_START+ 50 ;
const WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START +6;
const WM_CAP_SET_CALLBACK_ERROR=WM_CAP_START +2;
const WM_CAP_SET_CALLBACK_STATUSA= WM_CAP_START +3;
const WM_CAP_SET_CALLBACK_FRAME= WM_CAP_START +5;
const WM_CAP_SET_SCALE=WM_CAP_START+ 53 ;
const WM_CAP_SET_PREVIEWRATE=WM_CAP_START+ 52;
{$R *.dfm}function capCreateCaptureWindowA(lpszWindowName : PCHAR; dwStyle : longint; x : integer;
y : integer;nWidth : integer;nHeight : integer;ParentWin : HWND;
nId : integer): HWND;
STDCALL EXTERNAL 'AVICAP32.DLL'; {
function Bmp2Jpg(Bmp: TBitmap; Quality: Integer = 100): TJpegImage;
begin
Result := nil;
if Assigned(Bmp)
then begin
Result := TJpegImage.Create;
Result.Assign(Bmp); //Its all folks...
Result.CompressionQuality := Quality;
Result.JPEGNeeded; //Key method...
Result.Compress;
end;
end;
function Jpg2Bmp(Jpg: TJpegImage): TBitmap;
begin
Result := nil;
if Assigned(Jpg)
then begin
Result := TBitmap.Create;
Jpg.DIBNeeded; //Key method...
Result.Assign(Jpg); //Its all folks...
end;
end;
}
{
注意:JPEGNeeded过程转换并存储图像数据到内部的JPEG数据。
我们无法直接存取JPEG 内部数据,因为D5并没有提供jpeg.pas单元的源码。
但是可以通过JPEGNeeded和DIBNeeded过程来操作它。
}
procedure TForm1.Button1Click(Sender: TObject);
begin
hWndC := capCreateCaptureWindowA('My Own Capture Window',WS_CHILD or WS_VISIBLE ,Panel1.Left,Panel1.Top,Panel1.Width,Panel1.Height,Form1.Handle,0);hWndC := capCreateCaptureWindowA('My Own Capture Window',WS_CHILD or WS_VISIBLE ,Panel1.Left,Panel1.Top,Panel1.Width,Panel1.Height,Form1.Handle,0);
if hWndC <> 0 then
begin
SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);
SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0);
SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0);
SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0);
SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0);
SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0);
SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0);
SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0);
end;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
if hWndC <> 0 then begin
SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0);
hWndC := 0;
end;
end;procedure TForm1.Button3Click(Sender: TObject);
begin
if hWndC <> 0 then begin
SendMessage(hWndC,WM_CAP_SAVEDIB,0,longint(pchar('c:\\001\test.BMP')));
end;
end;
//BMP2JPG
procedure TForm1.Button4Click(Sender: TObject);
var
MyJPEG : TJPEGImage;
MyBMP : TBitmap;
begin
MyBMP := TBitmap.Create;
with MyBMP do
try
LoadFromFile('c:\\001\test.BMP'); //你的图片位置
MyJPEG := TJPEGImage.Create;
with MyJPEG do begin
Assign(MyBMP);
CompressionQuality:=100; //压缩比例
Compress;
SaveToFile('c:\\001\test01.JPG');//保存路径……
Free;
end;
finally
Free;
end;
end;end.