多线程处理图片,bmp不支持,png支持
2015-09-14 18:52
525 查看
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, jpeg, ExtCtrls, StdCtrls, pngimage, PngImageProcessor, Math, IGDIPlus, JaContainers; type TMyCalThread = class(TThread) public IsWorking: Boolean; FDestBmp: TPNGObject; protected procedure Execute; override; end; TForm1 = class(TForm) Image1: TImage; Image2: TImage; Image3: TImage; Image4: TImage; Image5: TImage; Timer1: TTimer; Button1: TButton; procedure FormPaint(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure Button1Click(Sender: TObject); procedure FormDestroy(Sender: TObject); public FCalThread: TMyCalThread; end; var Form1: TForm1; GSyn: TSyncObject; implementation {$R *.dfm} { TMyCalThread } procedure TMyCalThread.Execute; var LSrcBmp: TPNGObject; LTmpBmp: TPNGObject; begin inherited; LSrcBmp := TPNGObject.Create; LTmpBmp := TPNGObject.Create; FDestBmp := TPNGObject.Create; LSrcBmp.LoadFromFile('3.png'); // ! 此方法对bmp无效,因为bmp调用了窗口的东西,除非自己实现bmp的文件处理 while not Terminated do begin if IsWorking then begin SetPngImageSize(Random(300) + 200, Random(150) + 50, LTmpBmp); DoRoomPng(LSrcBmp, LTmpBmp); GSyn.Lock; try FDestBmp.Assign(LTmpBmp); finally GSyn.Unlock; end; IsWorking := False; end; Sleep(10); end; end; { TForm1 } procedure TForm1.Button1Click(Sender: TObject); begin Timer1.Enabled := True; end; procedure TForm1.FormCreate(Sender: TObject); begin GSyn := TSyncObject.Create; GSyn.ThreadSafe := True; FCalThread := TMyCalThread.Create(True); FCalThread.FreeOnTerminate := True; FCalThread.IsWorking := False; FCalThread.Resume; end; procedure TForm1.FormDestroy(Sender: TObject); begin //FreeAndNil(GSyn); end; procedure TForm1.FormPaint(Sender: TObject); begin if FCalThread.FDestBmp <> nil then begin GSyn.Lock; try Canvas.Draw(100, 100, FCalThread.FDestBmp); finally GSyn.Unlock; end; end; end; procedure TForm1.Timer1Timer(Sender: TObject); begin if not FCalThread.IsWorking then begin FCalThread.IsWorking := True; Invalidate; end; end; end.
相关文章推荐
- java-Transient关键字、Volatile关键字介绍和序列化、反序列化机制、单例类序列化
- 集成百度地图时报错、使用百度地图画两条颜色不一样的线
- jquery的tree table(树表)
- linux 中/proc 详解 http://blog.csdn.net/kevinx_xu/article/details/8178746
- Jq_选择器、效果函数
- 为什么只有在用Visual Studio启动程序时会抛出InvalidOperationException异常
- 跨平台客户端Socket 二 接口定义
- 【iOS】APP实现检测更新
- WinAPI: DrawTextEx - 多功能文本绘制 Delphi需要把&替换成&&才可以
- 一字节anti创建进程线程等回调
- Matlab基础
- Java中的常用类
- 进程间通信
- C++ Primer学习总结_1_开始
- APP推广入门之AppStore数据分析
- 让程序不在任务栏小按钮显示
- uva 11300 Spreading the Wealth 中位数应用
- hdu3729二分图匹配
- 背包的标准代码与注释
- 涂鸦板实现思路和步骤