我想把任意大小的位图制作成固定大小的位图(比如说100*100的)并保存,请问该如何实现?多谢!!
解决方案 »
- SuperTitan001,come in
- delphi7使用SPCOMM的问题,在线急等。。。
- 提交这个页面的表单 http://www.mirdy.cn/add.asp?action=sfadd
- 自定义Grid组件
- 请问文件方面的问题.
- 我为DbgridEh的某列设置了picklist属性,为何不起作用?
- 谁用过waveinopen函数?帮忙调试一下!
- combobox 问题?
- 窗体显示问题
- 各位兄弟,谁知道"大富翁"的离线浏览器如何使用呀??
- TActionMainMenuBar使用求解。
- 选中listview中的一个item后,当鼠标点击该listview之外的地方时,如何让listview中的item取消选中?
创建像ACDSee那样的缩略图浏览器,这并不是一件简单的事。以下就是一个很原始的缩略图控件的源代码:uses jpegtype
tbi_thumb=class(tcustomcontrol)
fmypic : tjpegimage;
private
procedure getpic(value:tjpegimage);
public
procedure paint; override;
constructor create(aowner:tcomponent); override;
destructor destroy; override;
published
property pic:tjpegimage write getpic;
end;constructor tbi_thumb.create(aowner:tcomponent);
begin
inherited;
fmypic:=tjpegimage.create;
end;destructor tbi_thumb.destroy;
begin
inherited;
fmypic.free;
end;procedure tbi_thumb.getpic(value:tjpegimage);
begin
fmypic.scale:=jshalf;
fmypic.assign(value);
fmypic.dibneeded;
end;procedure tbi_thumb.paint;
var
arect : trect;
ratio : single;
begin
arect:=clientrect;
canvas.stretchdraw(arect,fmypic);
frame3d(canvas,arect,clblack,clwhite,2);
end;(这不是一个可视控件。)下面来实现新建一个Form,并在其上添加一个Directory List Box和一个Scrollbox,其中Scrollbox的宽度(Width)大约为430个象素。
当用户选定了一个新的目录,我们需要扫描这个目录,为其中每一个JPEG文件创建一个实例。为了加快这一过程的速度,可以将JPEG参数设为jpbestspeed。JPEG文件将被读入一个临时缓冲区,然后被赋值给一个新的缩略图对象的pic属性。在unit中添加一个新的变量:
var
buffer_jpeg:tjpegimage;下面的代码用来创建和释放buffer_jpeg变量:procedure TForm1.FormCreate(Sender: TObject);
begin
buffer_jpeg:=tjpegimage.create;
buffer_jpeg.Performance:=jpbestspeed;
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
buffer_jpeg.free;
while scrollbox1.ComponentCount>0 do
scrollbox1.components[0].free;
end;以下的代码在文件夹中检索JPEG文件并创建缩略图:procedure TForm1.DirectoryListBox1Change(Sender: TObject);
var
i,x,y : integer;
anewthumb : tbi_thumb;
foundlist : tstringlist;
sr : TSearchRec;begin
foundlist:=tstringlist.create; try
//检索JPEG文件
if FindFirst(directorylistbox1.Directory+'\*.jpg', faAnyFile, sr) = 0 then
begin
foundlist.add(sr.name);
while FindNext(sr) = 0 do
foundlist.add(sr.name);
FindClose(sr);
end; x:=0;
y:=0; //创建缩略图
for i:=0 to FoundList.count-1 do
begin
anewthumb:=tbi_thumb.create(self);
buffer_jpeg.loadfromfile(foundlist[i]);
with anewthumb do
begin
pic:=buffer_jpeg;
parent:=scrollbox1;
left:=x;
top:=y;
width:=120;
height:=90;
visible:=true;
inc(x,122);
if x>244 then
begin
x:=0;
inc(y,92);
end;
application.processmessages;
end;
end; finally
foundlist.free;
end;end;以上就是一个极简单的缩略图浏览器实现,你可以继续在里面添加需要的功能。