TImagelist不添加位图 [英] TImagelist not adding bitmap

查看:116
本文介绍了TImagelist不添加位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在末日...试图获得自定义图片列表,TImageList和TListView一起工作.原始问题:列表中没有显示动态添加的图片.缩小范围,问题出在TImagelist中.代码如下. ilMain是TImagelist(在其他地方定义).将位图添加到列表中,立即检索它,第一个绘制"工作正常,但sedond失败...我在这里错过了什么?

I'm at my whits end... trying to get a custom list of pictures, a TImageList and a TListView to work together. Original problem: No dynamically-added pictures are displayed in the list. Narrowed it down, problem is in the TImagelist. Code is below. ilMain is the TImagelist (defined elsewhere). Adding a bitmap to the list, immediatly retrieving it, first "Draw" works fine but the sedond fails... what am I missing here?

var i:integer;
  test:TSch;
  currentimage :TBitmap;
  stupid :TBitmap;

begin
  currentImage:=TBitmap.Create;
  stupid:=TBitmap.Create;
  ilMain.Clear;
//  currentImage.LoadFromFile('C:\Delphi\piccat\pics\MonaLisa.jpg');
  JPeg2Bmp('C:\Delphi\piccat\pics\MonaLisa.jpg',currentImage);

  form1.canvas.Draw(100,10,currentimage);
  ilMain.Add(currentimage,nil);
  ilMain.GetBitmap(0,stupid);
  form1.canvas.Draw(200,10,stupid);

对此做了一些进一步的测试;结果非常混乱和不一致.

Done some further testing on this one; results are very confusing and inconsistent.

结果实际上很大程度上取决于输入文件的大小(感谢该指针,kobik!);似乎所有小于256x256的内容都不会导入到图像列表中,而沿着X轴的较大图片(有时是?)分布在多个项目上.

Result are actually GREATLY dependant on the size of the input file (thanks for that pointer, kobik!); it seems everything smaller than 256x256 isn't imported into the imagelist, while bigger pictures ALONG THE X-AXIS are (sometimes??) spread over several items.

ilMain设置为256x256像素.

ilMain was set to 256x256 pixels.

以下是几种输入大小(X x Y,以像素为单位)的输出: 950x414 第一幅画显示整个图像,第二幅画在左上角为256x256像素.但是,使用3x 256x256像素填充了TImagelist的三项:可以从主图片切出"的三张图片,仍然是256x256像素.所有切掉的垂直或水平小于256x256的边缘都将丢失.

Here is the output for several input sizes (X x Y, in pixels): 950x414 First draw displays entire image, second take 256x256 pixels in the upper left corner. HOWEVER, THREE items of the TImagelist are populated, with 3x 256x256 pixels: the three pictures that can be "cut out" from the main picture and still be 256x256 pixels. All edges cut off which are smaller, either vertical or horizontal, than 256x256 are lost.

1600x1600 导入了六张图像;完整256x256块的第一行,可以从图片顶部剪切. tp右边的不完整块将被省略,所有Y-size 256以下的行也将被忽略.

1600x1600 Six images are imported; the first row of complete 256x256 blocks which can be cut from the top of the pic. The incomplete block on the tp right is omitted, and all rows below Y-size 256 as well.

1500x1000 与上一个相似;现在导入了五个项目.

1500x1000 Similar to previous one; five items imported now.

638x376 再次相似;现在只有两个项目适合".

638x376 Again similar; only two items "fit" now.

197x256(我的原始测试文件,如上所述) 没有导入任何项目(X尺寸小于TImaglist X尺寸吗?)

197x256 (my original test file, described in post above) NO ITEMS IMPORTED (X-size is smaller than TImaglist X-size?)

256x256 再次,未导入数据

256x256 AGAIN, NO DATA IMPORTED

257x257 仍然没有数据导入

257x257 STILL NO DATA IMPORTED

260x260 仍然没有数据导入

260x260 STILL NO DATA IMPORTED

300x300 仍然没有数据导入

300x300 STILL NO DATA IMPORTED

512x256 很奇怪一张图片已导入;但是会减小尺寸,因此原始图片的大约70%适合(新的)256 X尺寸.图片下方添加了一个黑条,以弥补由于缩小而造成的空间损失.

512x256 Very weird one. One pic is imported; BUT it is reduced in size, so approximately 70% of the original pic fits in the (new) 256 X size. A black bar is added below the pic to make up for the lost space due to this shrinking.

所以这是我现在停止测试的地方,想知道是否有人可以在这里透露一些信息...?

So this is where I stop testing for now, and wondering if anyone can shed some light here...?

设计部分移至新问题(请参见注释kobik中的请求,谢谢!)

Design part moved to new question (see request in comment kobik, thanks man!)

推荐答案

假设您的JPeg2Bmp是正确的,您的代码就可以工作(或至少需要工作).我猜@Dima的第二条评论是正确的.

Your code works (or at-least needs to work) assuming your JPeg2Bmp is correct. I guess @Dima's second comment is correct.

您尚未显示ilMain属性,如果使用默认属性,则会使用Width/Height=16获得图像列表.

You haven't showed the ilMain properties, and if you use the default you get an imagelist with Width/Height=16.

尝试忽略对form1.canvas.Draw(100,10,currentimage);的第一个调用,仅绘制form1.canvas.Draw(200,10,stupid);,您应该在位置200,10看到16x16图.

Try to omit the first call to form1.canvas.Draw(100,10,currentimage);, and draw only the form1.canvas.Draw(200,10,stupid); and You should see a 16x16 drawing at position 200,10.

TImagelist 无法加载任意图像大小.
您需要预定义其大小,并以合适的大小加载位图.即创建缩略图以适合图像列表尺寸.

TImagelist can't load arbitrary image sizes.
You need to pre-define it's size, and load the bitmaps with suitable sizes. i.e. create thumbnails to fit the imagelist dimensions.

还请注意(您可能知道),您仅需要绘制以响应WM_PAINT消息.例如在OnPaint表单事件中.

Note also that (you probably know that) You need to draw only in response to WM_PAINT Message. e.g. in the Form OnPaint event.

编辑:关于您的编辑,这是TImageList的工作方式.如果添加的位图大于图像列表的宽度,它将尝试将位图分成单独的位图以适合图像列表的大小.这是设计使然.

As regard to your edit, this is how TImageList works. if you add a bitmap that is larger than the imagelist width, it will attempt to break the bitmap into separate bitmaps to fit the imagelist size. this is by design.

请参阅有关 ImageList_Add的文档关于hbmImage参数:

See the documentation about ImageList_Add about the hbmImage parameter:

包含图像的位图的句柄.数字 从位图的宽度推断出图像的数量.

A handle to the bitmap that contains the image or images. The number of images is inferred from the width of the bitmap.

这篇关于TImagelist不添加位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆