打印本文 打印本文 关闭窗口 关闭窗口
用Delphi实现缩略图查看
作者:武汉SEO闵涛  文章来源:敏韬网  点击数3596  更新时间:2009/4/23 18:38:54  文章录入:mintao  责任编辑:mintao
nvas:TCanvas;Left,Top,Width,Height:integer;PanelType:integer);
var
  Right,Bottom:integer;
  LeftTopColor,RightBottomColor:TColor;
begin
  //凸起的panel
  if PanelType=RaisedPanel  then
  begin
    LeftTopColor:=clwhite;
    RightBottomColor:=clgray;
  end
  else //凹下去的panel
  begin
    LeftTopColor:=clgray;
    RightBottomColor:=clwhite;
  end;
      Right:=Left+width;
      Bottom:=Top+Height;

      Canvas.Pen.Width:=1;
      Canvas.Pen.Color:=LeftTopColor;

      Canvas.MoveTo(Right,Top);
      Canvas.lineTo(Left,Top);

      Canvas.LineTo(Left,bottom);

      Canvas.Pen.Color:=RightBottomColor;

      Canvas.lineTo(Right,Bottom);
      Canvas.lineTo(Right,Top);
end;
 8.接下来我们在ListView1的OnSelectItem事件里添加代码:

procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem;
  Selected: Boolean);
begin
  //当ShellTreeView1目录改变时 会激发此事件,
  if listview1.SelCount=0 then exit;

  //当窗体释放时也会激发此事件
  //ImageFileList.GetFileCount=0 后再 ImageFileList.SetIndex(item.Index);
  //会引起异常
  if ImageFileList.GetFileCount=0 then  exit;

  ImageFileList.SetIndex(item.Index);
  ShowPreImageFit(ImageFileList.GetCurFullFileName);
end;

9.其中过程ShowImageFit的代码比较罗嗦,如下所示:

//image1在Panel1中居中显示图片文件ImageFileName

procedure TForm1.ShowPreImageFit(const ImageFileName: string);
begin
  Image1.Visible:=false;
  if IsJpgFile(ImageFileName) then
  begin
    JpgToBmp(ImageFileName,PreViewJpg,PreViewBmp);
    Image1.Picture.Bitmap:=PreViewBmp;
  end
  else
  Image1.Picture.LoadFromFile(ImageFileName);

  if (Image1.Picture.Bitmap.Height<=Panel1.Height) and (image1.Picture.Bitmap.Width<=Panel1.Width) then
  begin
    Image1.AutoSize:=true;
    Image1.Stretch:=true;
    Image1.Left:=(Panel1.Width-image1.Width) div 2;
    Image1.Top:=(Panel1.Height-image1.Height) div 2;
  end
  else if Panel1.Height>=Panel1.Width then
  begin
    Image1.AutoSize:=false;
    Image1.Stretch:=true;
    if image1.Picture.Bitmap.Height>=image1.Picture.Bitmap.Width then
    begin
      image1.Height:=Panel1.Width;
      Image1.Width:=Image1.Height*Image1.Picture.Bitmap.Width div Image1.Picture.Bitmap.Height;
     &

上一页  [1] [2] [3] [4] [5] [6]  下一页

打印本文 打印本文 关闭窗口 关闭窗口