📄 wil.pas
字号:
end;
function TWMImages.FGetImageBitmap (index: integer): TBitmap;
begin
if LibType <> ltLoadBmp then exit;
Result := GetCachedBitmap (index);
{if index in [0..BmpList.Count-1] then begin
Result := TBitmap (BmpList[index]);
end else
Result := nil;}
end;
procedure TWMImages.FSetDxDraw (fdd: TDxDraw);
begin
FDxDraw := fdd;
end;
// *** DirectDrawSurface Functions
procedure TWMImages.LoadDxImage (position: integer; pdximg: PTDxImage);
var
imginfo: TWMImageInfo;
ddsd: DDSURFACEDESC;
SBits, PSrc, DBits: PByte;
n, slen, dlen: integer;
begin
Stream.Seek (position, 0);
Stream.Read (imginfo, sizeof(TWMImageInfo)-4);
if UseDIBSurface then begin //DIB荤侩 滚弊 乐澜
try
lsDib.Clear;
lsDib.Width := imginfo.Width;
lsDib.Height := imginfo.Height;
except
end;
lsDib.ColorTable := MainPalette;
lsDib.UpdatePalette;
DBits := lsDib.PBits;
Stream.Read (DBits^, imginfo.Width * imgInfo.Height);
pdximg.px := imginfo.px;
pdximg.py := imginfo.py;
pdximg.surface := TDirectDrawSurface.Create (FDDraw);
pdximg.surface.SystemMemory := TRUE;
pdximg.surface.SetSize (imginfo.Width, imginfo.Height);
pdximg.surface.Canvas.Draw (0, 0, lsDib);
pdximg.surface.Canvas.Release;
pdximg.surface.TransparentColor := 0;
end else begin //钱 胶农赴俊辑父 荤侩
slen := WidthBytes(imginfo.Width);
GetMem (PSrc, slen * imgInfo.Height);
SBits := PSrc;
Stream.Read (PSrc^, slen * imgInfo.Height);
try
pdximg.surface := TDirectDrawSurface.Create (FDDraw);
pdximg.surface.SystemMemory := TRUE;
pdximg.surface.SetSize (slen, imginfo.Height);
//pdximg.surface.Palette := MainSurfacePalette;
pdximg.px := imginfo.px;
pdximg.py := imginfo.py;
ddsd.dwSize := SizeOf(ddsd);
pdximg.surface.Lock (TRect(nil^), ddsd);
DBits := ddsd.lpSurface;
for n:=imginfo.Height-1 downto 0 do begin
SBits := PByte (Integer(PSrc) + slen * n);
Move(SBits^, DBits^, slen);
Inc (integer(DBits), ddsd.lPitch);
end;
pdximg.surface.TransparentColor := 0;
finally
pdximg.surface.UnLock ();
FreeMem (PSrc);
end;
end;
end;
procedure TWMImages.LoadBmpImage (position: integer; pbmpimg: PTBmpImage);
var
imginfo: TWMImageInfo;
ddsd: DDSURFACEDESC;
DBits: PByte;
n, slen, dlen: integer;
begin
Stream.Seek (position, 0);
Stream.Read (imginfo, sizeof(TWMImageInfo)-4);
lsDib.Width := imginfo.Width;
lsDib.Height := imginfo.Height;
lsDib.ColorTable := MainPalette;
lsDib.UpdatePalette;
DBits := lsDib.PBits;
Stream.Read (DBits^, imginfo.Width * imgInfo.Height);
pbmpimg.bmp := TBitmap.Create;
pbmpimg.bmp.Width := lsDib.Width;
pbmpimg.bmp.Height := lsDib.Height;
pbmpimg.bmp.Canvas.Draw (0, 0, lsDib);
lsDib.Clear;
end;
procedure TWMImages.ClearCache;
var
i: integer;
begin
for i:=0 to ImageCount-1 do begin
if ImgArr[i].Surface <> nil then begin
ImgArr[i].Surface.Free;
ImgArr[i].Surface := nil;
end;
end;
end;
function TWMImages.GetImage (index: integer; var px, py: integer): TDirectDrawSurface;
begin
if (index >= 0) and (index < ImageCount) then begin
px := ImgArr[index].px;
py := ImgArr[index].py;
Result := ImgArr[index].surface;
end else
Result := nil;
end;
{--------------- BMP functions ----------------}
//释放5秒后还未使用的图片
procedure TWMImages.FreeOldBmps;
var
i, n, ntime, curtime, limit: integer;
begin
n := -1;
ntime := 0;
for i:=0 to ImageCount-1 do begin
curtime := GetTickCount;
if BmpArr[i].Bmp <> nil then begin
if curtime - BmpArr[i].LatestTime > 5 * 1000 then begin
BmpArr[i].Bmp.Free;
BmpArr[i].Bmp := nil;
end else begin
if curtime - BmpArr[i].LatestTime > ntime then begin
ntime := curtime - BmpArr[i].LatestTime;
n := i;
end;
end;
end;
end;
end;
//释放指定索引的图片
procedure TWMImages.FreeBitmap (index: integer);
begin
if (index >= 0) and (index < ImageCount) then begin
if BmpArr[index].Bmp <> nil then begin
BmpArr[index].Bmp.FreeImage;
BmpArr[index].Bmp.Free;
BmpArr[index].Bmp := nil;
end;
end;
end;
//释放1分钟后未使用的图片
procedure TWMImages.FreeOldMemorys;
var
i, n, ntime, curtime, limit: integer;
begin
n := -1;
ntime := 0;
curtime := GetTickCount;
for i:=0 to ImageCount-1 do begin
if ImgArr[i].Surface <> nil then begin
if curtime - ImgArr[i].LatestTime > 5 * 60 * 1000 then begin
ImgArr[i].Surface.Free;
ImgArr[i].Surface := nil;
end;
end;
end;
end;
//返回指定图片号的图面
function TWMImages.GetCachedSurface (index: integer): TDirectDrawSurface;
var
position: integer;
begin
Result := nil;
try
if (index < 0) or (index >= ImageCount) then exit;
if GetTickCount - memchecktime > 10000 then begin
memchecktime := GetTickCount;
FreeOldMemorys;
end;
if ImgArr[index].Surface = nil then begin //若指定图片已经释放,则重新装载.
if index < IndexList.Count then begin
position := Integer(IndexList[index]);
LoadDxImage (position, @ImgArr[index]);
ImgArr[index].LatestTime := GetTickCount;
Result := ImgArr[index].Surface;
end;
end else begin
ImgArr[index].LatestTime := GetTickCount;
Result := ImgArr[index].Surface;
end;
except
end;
end;
function TWMImages.GetCachedImage (index: integer; var px, py: integer): TDirectDrawSurface;
var
position: integer;
begin
Result := nil;
try
if (index < 0) or (index >= ImageCount) then exit;
if GetTickCount - memchecktime > 10000 then begin
memchecktime := GetTickCount;
FreeOldMemorys;
end;
if ImgArr[index].Surface = nil then begin //重新装载
if index < IndexList.Count then begin
position := Integer(IndexList[index]);
LoadDxImage (position, @ImgArr[index]);
ImgArr[index].LatestTime := GetTickCount;
px := ImgArr[index].px;
py := ImgArr[index].py;
Result := ImgArr[index].Surface;
end;
end else begin
ImgArr[index].LatestTime := GetTickCount;
px := ImgArr[index].px;
py := ImgArr[index].py;
Result := ImgArr[index].Surface;
end;
except
end;
end;
function TWMImages.GetCachedBitmap (index: integer): TBitmap;
var
position: integer;
begin
Result := nil;
if (index < 0) or (index >= ImageCount) then exit;
if BmpArr[index].Bmp = nil then begin
if index < IndexList.Count then begin
position := Integer(IndexList[index]);
LoadBmpImage (position, @BmpArr[index]);
BmpArr[index].LatestTime := GetTickCount;
Result := BmpArr[index].Bmp;
FreeOldBmps;
end;
end else begin
BmpArr[index].LatestTime := GetTickCount;
Result := BmpArr[index].Bmp;
end;
end;
//按缩放比率画出执行序号的图片
procedure TWMImages.DrawZoom (paper: TCanvas; x, y, index: integer; zoom: Real);
var
rc: TRect;
bmp: TBitmap;
begin
if LibType <> ltLoadBmp then exit;
bmp := Bitmaps[index];
if bmp <> nil then begin
rc.Left := x;
rc.Top := y;
rc.Right := x + Round (bmp.Width * zoom);
rc.Bottom := y + Round (bmp.Height * zoom);
if (rc.Right > rc.Left) and (rc.Bottom > rc.Top) then begin
paper.StretchDraw (rc, Bmp);
FreeBitmap (index);
end;
end;
end;
//
procedure TWMImages.DrawZoomEx (paper: TCanvas; x, y, index: integer; zoom: Real; leftzero: Boolean);
var
rc: TRect;
bmp, bmp2: TBitmap;
begin
if LibType <> ltLoadBmp then exit;
bmp := Bitmaps[index];
if bmp <> nil then begin
Bmp2 := TBitmap.Create;
Bmp2.Width := Round (Bmp.Width * zoom);
Bmp2.Height := Round (Bmp.Height * zoom);
rc.Left := x;
rc.Top := y;
rc.Right := x + Round (bmp.Width * zoom);
rc.Bottom := y + Round (bmp.Height * zoom);
if (rc.Right > rc.Left) and (rc.Bottom > rc.Top) then begin
Bmp2.Canvas.StretchDraw (Rect(0, 0, Bmp2.Width, Bmp2.Height), Bmp);
if leftzero then begin
SpliteBitmap (paper.Handle, X, Y, Bmp2, $0)
end else begin
SpliteBitmap (paper.Handle, X, Y-Bmp2.Height, Bmp2, $0);
end;
end;
FreeBitmap (index);
bmp2.Free;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -