⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unitformbrowse.pas

📁 图象处理的一些相关内容 不是很难的,实现简单,希望对大家有帮助
💻 PAS
📖 第 1 页 / 共 3 页
字号:
//
end;








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


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

    ImageFileList.SetIndex(item.Index);

    StatusBar1.Panels[0].Text:='当前文件夹共有图片:'+inttostr(ImageFileList.GetFileCount)+'张';

    FileDateTime:=FileDateToDateTime(fileage(ImageFileList.GetCurFullFileName));
    DateTimeToString(strFileDateTime,'yyyy-mm-dd hh:nn:ss',FileDateTime);
    StatusBar1.Panels[1].Text:=strFileDateTime;


    StatusBar1.Panels[2].Text:=ImageFileList.GetCurFileName;
    ShowPreImageFit(ImageFileList.GetCurFullFileName);
  end
  else
  begin
    SSPImageFileList.SetIndex(item.Index);

    ShowPreImageFit(listview1.Selected.Caption);


  end;


 // ShowImageFit(ImageFileList.GetCurFullFileName,Image1,Panel1);
end;

procedure TFormBrowse.About1Click(Sender: TObject);
begin
  FormFlash.Show;
//  showmessage('DIY ACDSss 作者:姜亮'+#13+'jiangliang@163.com  2002.03');
end;

procedure TFormBrowse.ListView1DblClick(Sender: TObject);
var
  ImageFileName:string;
begin
  if listview1.SelCount=0 then exit;


  //如果不是读取的包文件
  if (not IsReadStructureStorageFileMode) then
  begin
    ImageFileName:=ImageFileList.GetCurFullFileName;

    if IsJpgFile(ImageFileName) then
    begin
      JpgToBmp(ImageFileName,PreViewJpg,OriginalBmp);
      FormView.image1.Picture.Bitmap:=OriginalBmp;

    end
    else
    FormView.image1.Picture.LoadFromFile(ImageFileName);

    //form2.WindowState:=wsMaximized;
    FormView.Height:=screen.Height;
    FormView.Width:=screen.Width;

  {
    form2.Image1.AutoSize:=true;
    form2.Image1.Stretch:=true;

    form2.Panel1.Height:=form2.Image1.Height;
    form2.Panel1.Width:=form2.Image1.width;
    form2.Panel1.Top:=(form2.ScrollBox1.Height-form2.Panel1.Height) div 2;
    form2.Panel1.Left:=(form2.ScrollBox1.Width-form2.Panel1.Width) div 2;
  }

    FormView.ShowImageFit(true,1);
    FormView.Image1.Top:=0;
    FormView.Image1.Left:=0;

    FormView.show;
    self.Hide;
  end
  else
  begin
    ShowLargeImageFromStructureStorageFile(SSPImageFileList.GetSSPFileName,ListView1.Selected.Caption,FormView.Image1);
    //FormView.show;

    FormView.Height:=screen.Height;
    FormView.Width:=screen.Width;

    FormView.ShowImageFit(true,1);
    FormView.Image1.Top:=0;
    FormView.Image1.Left:=0;

    FormView.show;
    self.Hide;


  end;
end;



//此过程把ImageFileList中的图片文件缩放后加载到ImageList1中,并在
//ListView1中显示
procedure TFormBrowse.RefreshImage;
var
  i:integer;
  ImageFileName:string;
  ThumbBmpLeft:integer;
  ThumbBmpTop:integer;
  ThumbBmpHeight:integer;
  ThumbBmpWidth:integer;


  TemFileNameStringList:TStringlist;
  IsErrorImage:boolean;
begin

  IsRefreshImageFinshi:=false;

  IsReadStructureStorageFileMode:=false;

  IsErrorImage:=false;


  screen.Cursor:=crHourGlass;
  ProgressBar1.Max:=ImageFileList.GetFileCount;
  ProgressBar1.Visible:=true;
  TemFileNameStringList:=TStringlist.Create;
  TemFileNameStringList.Clear;
  try
    listview1.Clear;
    imagelist1.Clear;
    listview1.Items.BeginUpdate;

    //FileCount:=ImageFileList.GetFileCount-1;
    for i:=0 to ImageFileList.GetFileCount-1 do
    begin
      ImageFileList.SetIndex(i);
      ImageFileName:=ImageFileList.GetCurFullFileName;
      TemFileNameStringList.Add(ImageFileName);
      //a:=TemFileNameStringList.Count;

      if IsJpgFile(ImageFileName) then
      try
        jpgtobmp(ImageFileList.GetCurFullFileName,ThumbJpg,OriginalBmp);

        if OriginalBmp.Height>=OriginalBmp.Width then
        begin
          ThumbBmpWidth:=64*OriginalBmp.Width div OriginalBmp.Height;
          ThumbBmpLeft:=(64-ThumbBmpWidth ) div 2;

          ThumbBmp.Canvas.Brush.Color :=clBtnFace;
          ThumbBmp.Canvas.FillRect(ThumbBmp.Canvas.ClipRect);

          DrawPanel(ThumbBmp.Canvas,0,0,79,79,RaisedPanel);
          DrawPanel(ThumbBmp.Canvas,7+ThumbBmpLeft,7,ThumbBmpWidth+1,64,LoweredPanel);
          ThumbBmp.Canvas.StretchDraw(Rect(8+ThumbBmpLeft,8,8+ThumbBmpLeft+ThumbBmpWidth,71),OriginalBmp);

          imagelist1.Add(ThumbBmp,nil);
        end
        else
        begin
          ThumbBmpHeight:=64*OriginalBmp.Height div OriginalBmp.Width;
          ThumbBmpTop:=(64-ThumbBmpHeight ) div 2;

          ThumbBmp.Canvas.Brush.Color :=clBtnFace;
          ThumbBmp.Canvas.FillRect(ThumbBmp.Canvas.ClipRect);

          DrawPanel(ThumbBmp.Canvas,0,0,79,79,RaisedPanel);
          DrawPanel(ThumbBmp.Canvas,7,7+ThumbBmpTop,64,ThumbBmpHeight+1,LoweredPanel);
          ThumbBmp.Canvas.StretchDraw(Rect(8,8+ThumbBmpTop,71,8+ThumbBmpTop+ThumbBmpHeight),OriginalBmp);
          imagelist1.Add(ThumbBmp,nil);
        end;

        with ListView1.Items.Add  do
        begin
          ImageIndex:=imagelist1.Count-1;
          caption:=ImageFileList.GetCurFileName;
        end;

      except
        MessageDlg('读取文件:'+ImageFileList.GetCurFullFileName+'时发生错误!'+#13
         +'该文件不是标准格式的文件,或者该文件已经被损坏!',mtError,[mbYes],0);
        //TemFileNameStringList.Add(inttostr(i));
        //TemFileNameStringList.Append('s');
        IsErrorImage:=true;
        TemFileNameStringList.Delete(TemFileNameStringList.Count-1);
        //break;
      end
      else
        try
          OriginalBmp.LoadFromFile(ImageFileList.GetCurFullFileName);
          if OriginalBmp.Height>=OriginalBmp.Width then
          begin
            ThumbBmpWidth:=64*OriginalBmp.Width div OriginalBmp.Height;
            ThumbBmpLeft:=(64-ThumbBmpWidth ) div 2;

            ThumbBmp.Canvas.Brush.Color :=clBtnFace;
            ThumbBmp.Canvas.FillRect(ThumbBmp.Canvas.ClipRect);

            DrawPanel(ThumbBmp.Canvas,0,0,79,79,RaisedPanel);
            DrawPanel(ThumbBmp.Canvas,7+ThumbBmpLeft,7,ThumbBmpWidth+1,64,LoweredPanel);
            ThumbBmp.Canvas.StretchDraw(Rect(8+ThumbBmpLeft,8,8+ThumbBmpLeft+ThumbBmpWidth,71),OriginalBmp);

            imagelist1.Add(ThumbBmp,nil);
          end
          else
          begin
            ThumbBmpHeight:=64*OriginalBmp.Height div OriginalBmp.Width;
            ThumbBmpTop:=(64-ThumbBmpHeight ) div 2;

            ThumbBmp.Canvas.Brush.Color :=clBtnFace;
            ThumbBmp.Canvas.FillRect(ThumbBmp.Canvas.ClipRect);

            DrawPanel(ThumbBmp.Canvas,0,0,79,79,RaisedPanel);
            DrawPanel(ThumbBmp.Canvas,7,7+ThumbBmpTop,64,ThumbBmpHeight+1,LoweredPanel);
            ThumbBmp.Canvas.StretchDraw(Rect(8,8+ThumbBmpTop,71,8+ThumbBmpTop+ThumbBmpHeight),OriginalBmp);
            imagelist1.Add(ThumbBmp,nil);
          end;

          with ListView1.Items.Add  do
          begin
            ImageIndex:=imagelist1.Count-1;
            caption:=ImageFileList.GetCurFileName;
          end;

        except
          MessageDlg('读取文件:'+ImageFileList.GetCurFullFileName+'时发生错误!'+#13
           +'该文件不是标准格式的文件,或者该文件已经被损坏!',mtError,[mbYes],0);
          //ImageFileList.Delete(i);
          //dec(FileCount);
          IsErrorImage:=true;
          TemFileNameStringList.Delete(TemFileNameStringList.Count-1);
          //TemFileNameStringList.Append('asdf');

          //TemFileNameStringList.Append(inttostr(i));

          //break;
        end;
        ProgressBar1.Position:=i;
        application.ProcessMessages;

    end;    //end for loop!
  finally
    listview1.Items.EndUpdate;
    ProgressBar1.Visible:=false;
    //for i:=0 to TemFileNameStringList.Count-1 do
    //  ImageFileList.Delete(strtoint(TemFileNameStringList[i]));
    if IsErrorImage then
      ImageFileList.CopyStrListFile(TemFileNameStringList);
  end;
  TemFileNameStringList.Free;


  try
    listview2.Clear;
    listview2.Items.BeginUpdate;
    ProgressBar1.Visible:=true;
    ProgressBar1.Max:=OtherFileList.Count;
    for i:=0 to OtherFileList.Count-1 do
    begin
      case  OtherFileList.Strings[i][1] of
        '0':     //文件夹
          begin
            with ListView2.Items.Add  do
            begin
              ImageIndex:=0;
              caption:=ExtractFileName(OtherFileList.Strings[i]);
            end;
          end;
        '1':     //文本文件
         begin
            with ListView2.Items.Add  do
            begin
              ImageIndex:=1;
              caption:=ExtractFileName(OtherFileList.Strings[i]);
            end;
         end;
        '2':      //html文件
         begin
           with ListView2.Items.Add  do
            begin
              ImageIndex:=2;
              caption:=ExtractFileName(OtherFileList.Strings[i]);
            end;
         end;

        '3':      //.pas文件
         begin
           with ListView2.Items.Add  do
            begin
              ImageIndex:=3;
              caption:=ExtractFileName(OtherFileList.Strings[i]);
            end;
         end;
        '4':      //.exe文件
         begin
           with ListView2.Items.Add  do
            begin
              ImageIndex:=4;
              caption:=ExtractFileName(OtherFileList.Strings[i]);
            end;
         end;
        '5':      //.dll文件
         begin
           with ListView2.Items.Add  do
            begin
              ImageIndex:=5;
              caption:=ExtractFileName(OtherFileList.Strings[i]);
            end;
         end;

        '6':      //.ssp文件 ,也即打包文件
         begin
           with ListView2.Items.Add  do
            begin
              ImageIndex:=6;
              caption:=ExtractFileName(OtherFileList.Strings[i]);
            end;
         end;





      end; //end case
      ProgressBar1.Position:=i;
    end;  //end for loop
  finally
    ProgressBar1.Visible:=false;
    listview2.Items.EndUpdate;
  end;

  screen.Cursor:= crDefault;
  IsRefreshImageFinshi:=true;

end;

//image1在APanel1中居中显示图片文件ImageFileName
procedure TFormBrowse.ShowPreImageFit(const ImageFileName: string);
begin
  Image1.Visible:=false;
  if not IsReadStructureStorageFileMode then
  begin
    if IsJpgFile(ImageFileName) then
    begin
      JpgToBmp(ImageFileName,PreViewJpg,PreViewBmp);
      Image1.Picture.Bitmap:=PreViewBmp;
    end
    else
    Image1.Picture.LoadFromFile(ImageFileName);
  end
  else
    ShowLargeImageFromStructureStorageFile(SSPImageFileList.GetSSPFileName,ImageFileName,Image1);



  if  (not IsReadStructureStorageFileMode) or (not IsJpgFile(ImageFileName)) then
  begin
    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;
        Image1.Top:=(Panel1.Height-Image1.Height) div 2;
        Image1.Left:=(Panel1.Width-Image1.Width) div 2;
      end
      else
      begin
        Image1.Width:=Panel1.Width;
        Image1.Height:=Image1.Width*Image1.Picture.Bitmap.Height div Image1.Picture.Bitmap.Width;
        Image1.Top:=(Panel1.Height-Image1.Height) div 2;
        Image1.Left:=(Panel1.Width-Image1.Width) div 2;
      end;
    end
    else
    begin
      Image1.AutoSize:=false;
      Image1.Stretch:=true;
      if Image1.Picture.Bitmap.Height>=Image1.Picture.Bitmap.Width then
      begin
        Image1.Height:=Panel1.Height;
        Image1.Width:=Image1.Height*Image1.Picture.Bitmap.Width div Image1.Picture.Bitmap.Height;
        Image1.Top:=(Panel1.Height-Image1.Height) div 2;
        Image1.Left:=(Panel1.Width-Image1.Width) div 2;
      end
      else
      begin
        Image1.Width:=Panel1.Height;
        Image1.Height:=Image1.Width*Image1.Picture.Bitmap.Height div Image1.Picture.Bitmap.Width;
        Image1.Top:=(Panel1.Height-Image1.Height) div 2;
        Image1.Left:=(Panel1.Width-Image1.Width) div 2;
      end
    end;
  end
  else
  begin

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







  end;

  Image1.Visible:=true;
end;
procedure TFormBrowse.Exit1Click(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TFormBrowse.ShellTreeView1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
{
  不能截获空格键!!!!!!
  大概是因为ShellTreeView的热键跟踪
  级别太底吧。

  if key=VK_Space then
  begin

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -