您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> Delphi >> 用Listview实现缩略图为什么总有问题(附程序源码)

用Listview实现缩略图为什么总有问题(附程序源码)

来源:网络整理     时间:2016/7/4 15:21:06     关键词:

关于网友提出的“ 用Listview实现缩略图为什么总有问题(附程序源码)”问题疑问,本网通过在网上对“ 用Listview实现缩略图为什么总有问题(附程序源码)”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: 用Listview实现缩略图为什么总有问题(附程序源码)
描述:

不知道为什么用listview显示缩略图总有问题,请大家帮忙看下下载地址里的工程源码,告诉我到底哪里出问题了,谢谢了
下载地址:
http://cnc.fs1.bay.cech.com.cn/download/23232781/adbrave/633767034992187500/55764ab7cca3ead81c8a55485739ba67/%E5%9B%BE%E7%89%87%E7%BC%A9%E7%95%A5%E5%9B%BE%E6%B5%8F%E8%A7%88.rar


解决方案1:

为了让缩略图在中间显示,改用下面的代码:
procedure ScaleToBitmap(ASrc, ADest: TBitmap);
var
  w, h, newW, newH, row, col, offsetW, offsetH: Integer;
  sw, sh, scale: Single;
  src, dest: PRGBTriple;
begin
  w := ASrc.Width;
  h := ASrc.Height;
  sw := w / 80;
  sh := h / 80;
  scale := Max(sw, sh);
  newW := Trunc(ASrc.Width / scale);
  newH := Trunc(ASrc.Height / scale);
  offsetW := (ADest.Width - newW) div 2;
  offsetH := (ADest.Height - newH) div 2;
  for row := 0 to newH - 1 do
  begin
    src := ASrc.ScanLine[Trunc(row * scale)];
    dest := PRGBTriple(Integer(ADest.ScanLine[offsetH + row]) + offsetW * SizeOf(TRGBTriple));
    for col := 0 to newW - 1 do
    begin
      dest^ := PRGBTriple(Integer(src) + SizeOf(TRGBTriple) * Trunc(col * scale))^;
      Inc(dest);
    end;
  end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
  TheBitmap, DestBitmap:TBitmap ;
  TheJpeg:TJPEGImage;
  aa:tlistitem;
  i:integer;
begin
  ImageList1.Clear;
  for i:=1 to 5 do
  begin
  TheJpeg := TJPEGImage.Create;
  TheJpeg.LoadFromFile('.\Images\'+inttostr(i)+'.jpg');
  TheBitmap := TBitmap.Create ;
  TheBitmap.Assign(TheJpeg);
  TheBitmap.PixelFormat := pf24Bit;
  DestBitmap := TBitmap.Create;
  DestBitmap.Width := 80;
  DestBitmap.Height := 80;
  DestBitmap.PixelFormat := pf24Bit;
  ScaleToBitmap(TheBitmap, DestBitmap);
  ImageList1.Width:=80;
  ImageList1.Height:=80;
  ImageList1.Add(DestBitmap, nil) ;
  aa:=listview1.Items.Add;
  aa.Caption:=inttostr(i)+'.jpg';
  aa.ImageIndex :=ImageList1.Count -1;
  FreeAndNil(DestBitmap);
  FreeAndNil(TheBitmap) ;
  FreeAndNil(TheJpeg);
  end;
end;


以上介绍了“ 用Listview实现缩略图为什么总有问题(附程序源码)”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/2273627.html

相关图片

相关文章