我需要将数据库中的图像显示到listview组件中。我尝试过这样的事情,但没有成功。
示例:
var
bmp: TBitmap;
blob :TBLOBField;
begin
bmp := TBitmap.Create;
blob := TBlobField.Create(nil);
//get image from blob column
//image is type bmp
blob := //here i set bmp image from db;
bmp.Assign(blob);
//ListView1 viewstyle is vsReport
ListView1.LargeImages.Add(bmp,nil); //there is Runtime error access violation at address
end;
我做错了什么?
答案 0 :(得分:3)
对于访问冲突,最合理的解释是您没有为LargeImages
分配任何内容,因此它是nil
。将图像列表拖放到表单上,然后将LargeImages
设置为引用该图像列表。这将解决您的访问冲突。
您肯定会发现图像列表要求所有图像具有相同的尺寸。这意味着您在列表视图中显示的每个图像也必须具有相同的尺寸。在添加到图像列表之前,您可能需要调整原始图像的大小以匹配该公共维度。