var
  tmpBitmap:TBitmap ;
  MyRect, MyOther: TRect;
begin
   if SSleft in Shift then
   tmpBitmap:=TBitmap.Create();
   tmpBitmap.Width:=ImgPic.Picture.Width;
   tmpBitmap.Height:=ImgPic.Picture.Height;
  MyRect := Rect(0,0,ImgZoom.Width ,ImgZoom.Height);  MyOther:= Rect(X-ImgZoom.Width div 4,Y-ImgZoom.Height div 4,X+ImgZoom.Width div 4,Y+ImgZoom.Height div 4);
  tmpBitmap.Canvas.CopyRect(MyRect,ImgPic.Picture.Bitmap.Canvas,MyOther);
  ImgZoom.Picture.Graphic := tmpBitmap;
  ImgZoom.Left:=X-ImgZoom.Width div 2 ;
  ImgZoom.Top:=Y-ImgZoom.Height div 2;
  if (x>=ImgPic.Width)or(Y>=ImgPic.Height) then
begin
    ImgZoom.Visible:=false;
   end else begin
   ImgZoom.Visible:=true;
end;
ImgZoom.Refresh;
tmpBitmap.Free;
end;编译时候tmpBitmap.Width:=ImgPic.Picture.Width;通不过,请高手帮助!!!!!

解决方案 »

  1.   

    ImgPic是不是一個img控件?
    如果是,那它的Picture確定有圖片?如果沒圖片,當然錯誤了,不存在圖片對象
      

  2.   

    如果ImgPic是image组件
    你的程序应该没有问题
      

  3.   

    ImgPic是image组件,ImgPic有图片,编译时候提示[Warning] Unit1.pas(94): Variable 'tmpBitmap' might not have been initialized
      

  4.   

    Warning不是錯誤,是警告而已,提示你,'tmpBitmap' 有可能沒有初始化,如果沒初始化那會出錯。
    按照你代碼,沒錯,不會有問題了
      

  5.   

    请问kenshinggg你的QQ号或者Email多少?
      

  6.   

    呵呵!我吧程序发给你,帮我看一下了!我比较着急!要不给你发 Email,可以吗?
      

  7.   

    Email:[email protected]
    現在上班呢,估計不能幫你看,晚上下班才幫你看看吧,如果你急到現在就要解決,那沒辦法幫你啊
      

  8.   

    你少了begin end看看你的
      if SSleft in Shift then 
      tmpBitmap:=TBitmap.Create(); 
      tmpBitmap.Width:=ImgPic.Picture.Width; 
    这三句。
      

  9.   

    如果不符合条件,对一个没有创建的TBitmap对象操作,必然出错误。
      

  10.   


      if SSleft in Shift then 
      begin
        tmpBitmap:=TBitmap.Create(); 
        tmpBitmap.Width:=ImgPic.Picture.Width; 
      ...
      

  11.   

    关键现在的问题是鼠标左键点击ImgPic时候,图片不显示了 ! 不知道什么原因,可能还是
    procedure TForm1.ImgPicMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);begin
      tmpBitmap:=TBitmap.Create();
      ImgZoom.Visible:=true;
    tmpBitmap.Width:=Imgpic.Picture.Width;tmpBitmap.Height:=ImgPic.Picture.Height;MyRect := Rect(0,0,ImgZoom.Width ,ImgZoom.Height);MyOther:= Rect(X-ImgZoom.Width div 4,Y-ImgZoom.Height div 4,X+ImgZoom.Width div 4,Y+ImgZoom.Height div 4);
    tmpBitmap.Canvas.CopyRect(MyRect,ImgPic.Picture.Bitmap.Canvas,MyOther);
    ImgZoom.Picture.Graphic:= tmpBitmap;ImgZoom.Left:=X-ImgZoom.Width div 2 ;
    ImgZoom.Top:=Y- ImgZoom.Height div 2;
    if (x>=ImgPic.Width)or(Y>=ImgPic.Height) then
    begin
        ImgZoom.Visible:=false;
       end else begin
       ImgZoom.Visible:=true;end;
     end;
    有问题
      

  12.   

    不好意思!是我的错!就是放大镜程序,编译时候没有提示,就是单击鼠标左键时候,ImgPic中的图片没有了