G
guan2000
Unregistered / Unconfirmed
GUEST, unregistred user!
我这个程序是一个图片播放程序,主程序调用tmpictext控件.我列出了相关的语句.主程序开始播放后每隔5秒中调用getbitmap,把生成的showedpic用于显示.我这段代码在大多数计算机运行没问题,但是在个别新的电脑上运行会出问题.共有两台,一台是联想电脑,运行30分钟后会死机.试了好几次.另一台是dell电脑款式很新,运行20多分钟退出.我的程序曾经出现过内存不足,无法处理此命令的提示,然后退出的情况.但已经解决.下面的destory没有列出,因为在播放时不进行creat,destory.望高人指点,哪里出了问题.问题解决人民币伺候.嫌少可以加,说到做到.
unit UPicText;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, Element, StdCtrls, ExtCtrls,ComCtrls, Jpeg, strutils,
ShockwaveFlashObjects_TLB,activex, GIFCtrl, Animate;
type
TMPicText = class(TELement)
private
FBgColor: TColor;
FBgStyle: integer;
FBgPicFileName: string;
FBgPicture: Graphics.TBitmap;
FEffection: integer;
FShowedPic: Graphics.TBitmap;
FOriginalPic: TGraphic;
implementation
constructor TMPicText.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FBgColor := clBlack;
FBgStyle := 0;
FEffection := 1;
FShowedPic := Graphics.TBitmap.Create;
FGifDelay := 0;
FBgPicture := Graphics.TBitmap.Create;
end;
procedure TMPicText.GetBackGround;
var
bmp1,bmp: Graphics.TBitmap;
begin
bmp1 := Graphics.TBitmap.Create;
if FBgPicture=nil then
FBgPicture := Graphics.TBitmap.Create
else
FBgPicture.Assign(nil);
FBgPicture.Width := Width;
FBgPicture.Height := Height;
FBgPicture.Canvas.Brush.Color := FBgColor;
FBgPicture.Canvas.FillRect(Rect(0,0,Width,Height));
end;
function TMPicText.GetBitmap: Graphics.TBitmap;
var
bmp: Graphics.TBitmap;
begin
Result := nil;
ReadPicText;
bmp := Graphics.TBitmap.Create;
try
bmp.PixelFormat := pf16bit;
bmp.Assign(FOriginalPic);
GetBackGround;
FShowedPic.Assign(nil);
FShowedPic.Assign(FBgPicture);
SetBackGroundPictureMode(FEffection,bmp,Graphics.TBitmap(FShowedPic),Width,Height);
finally
bmp.Free;
end;
FBgPicture.Assign(nil);
FOriginalPic.Assign(nil);
result := FShowedPic;
end;
procedure TMPicText.ReadPicText;
var
bmp: Graphics.TBitmap;
jpg: TJpegImage;
I: integer;
begin
if FFileName <> '' then
begin
if FOriginalPic=nil then
FOriginalPic := Graphics.TBitmap.Create;
if FileExists(FFileName) then
FOriginalPic.LoadFromFile(FFileName);
end;
end;
procedure SetBackGroundPictureMode(iMode: integer;srcBmp,descBmp: TBitmap;Width,Height: integer);
var
x,y,w,h,iw,ih: integer;
sx,sy,sw,sh: integer;
rate: double;
tmpRect: TRect;
begin
case iMode of
1://拉伸
begin
x := 0;
y := 0;
w := descBmp.Width;
h := descBmp.Height;
descBmp.Canvas.Lock;
descBmp.Canvas.StretchDraw(Rect(x,y,x+w,y+h),srcBmp);
descBmp.Canvas.UnLock;
end;
end;
unit UPicText;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, Element, StdCtrls, ExtCtrls,ComCtrls, Jpeg, strutils,
ShockwaveFlashObjects_TLB,activex, GIFCtrl, Animate;
type
TMPicText = class(TELement)
private
FBgColor: TColor;
FBgStyle: integer;
FBgPicFileName: string;
FBgPicture: Graphics.TBitmap;
FEffection: integer;
FShowedPic: Graphics.TBitmap;
FOriginalPic: TGraphic;
implementation
constructor TMPicText.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FBgColor := clBlack;
FBgStyle := 0;
FEffection := 1;
FShowedPic := Graphics.TBitmap.Create;
FGifDelay := 0;
FBgPicture := Graphics.TBitmap.Create;
end;
procedure TMPicText.GetBackGround;
var
bmp1,bmp: Graphics.TBitmap;
begin
bmp1 := Graphics.TBitmap.Create;
if FBgPicture=nil then
FBgPicture := Graphics.TBitmap.Create
else
FBgPicture.Assign(nil);
FBgPicture.Width := Width;
FBgPicture.Height := Height;
FBgPicture.Canvas.Brush.Color := FBgColor;
FBgPicture.Canvas.FillRect(Rect(0,0,Width,Height));
end;
function TMPicText.GetBitmap: Graphics.TBitmap;
var
bmp: Graphics.TBitmap;
begin
Result := nil;
ReadPicText;
bmp := Graphics.TBitmap.Create;
try
bmp.PixelFormat := pf16bit;
bmp.Assign(FOriginalPic);
GetBackGround;
FShowedPic.Assign(nil);
FShowedPic.Assign(FBgPicture);
SetBackGroundPictureMode(FEffection,bmp,Graphics.TBitmap(FShowedPic),Width,Height);
finally
bmp.Free;
end;
FBgPicture.Assign(nil);
FOriginalPic.Assign(nil);
result := FShowedPic;
end;
procedure TMPicText.ReadPicText;
var
bmp: Graphics.TBitmap;
jpg: TJpegImage;
I: integer;
begin
if FFileName <> '' then
begin
if FOriginalPic=nil then
FOriginalPic := Graphics.TBitmap.Create;
if FileExists(FFileName) then
FOriginalPic.LoadFromFile(FFileName);
end;
end;
procedure SetBackGroundPictureMode(iMode: integer;srcBmp,descBmp: TBitmap;Width,Height: integer);
var
x,y,w,h,iw,ih: integer;
sx,sy,sw,sh: integer;
rate: double;
tmpRect: TRect;
begin
case iMode of
1://拉伸
begin
x := 0;
y := 0;
w := descBmp.Width;
h := descBmp.Height;
descBmp.Canvas.Lock;
descBmp.Canvas.StretchDraw(Rect(x,y,x+w,y+h),srcBmp);
descBmp.Canvas.UnLock;
end;
end;