Image1.LoadFromFile(ExtractFilePath(Application.ExeName)+'\图片名');

解决方案 »

  1.   

    blazingfire(烈焰) 
    我的也是这样写的。我改变了图片后,再重新执行这个句子时。原来的图片还在。不知如何重画一次。
      

  2.   

    procedure TMainFrm.DrawStretched;//拉伸
    var
      CR: TRect;
    begin
      GetWindowRect(ClientHandle, CR);
      StretchBlt(FDrawDC, 0, 0, CR.Right, CR.Bottom,
                 imgMain.Picture.Bitmap.Canvas.Handle, 0, 0,
                 imgMain.Picture.Width, imgMain.Picture.Height, SRCCOPY);
    end;procedure TMainFrm.DrawCentered;//局中
    var
      CR: TRect;
    begin
      GetWindowRect(ClientHandle, CR);
      with imgMain do
        BitBlt(FDrawDC, ((CR.Right - CR.Left) - Picture.Width) div 2,
                        ((CR.Bottom - CR.Top) - Picture.Height) div 2,
                        Picture.Graphic.Width, Picture.Graphic.Height,
                        Picture.Bitmap.Canvas.Handle, 0, 0, SRCCOPY);
    end;procedure TMainFrm.DrawTiled;//平铺
    var
      Row, Col: Integer;
      CR, IR: TRect;
      NumRows, NumCols: INteger;begin
      GetWindowRect(ClientHandle, CR);
      IR := imgMain.ClientRect;
      NumRows := CR.Bottom div IR.Bottom;
      NumCols := CR.Right div IR.Right;
      with imgMain do
        for Row :=0 to NumRows+1 do
          for Col :=0 to NumCols+1 do
            BitBlt(FDrawDC, Col*Picture.Width, Row*Picture.Height,
                            Picture.Width, Picture.Height,
                            Picture.Bitmap.Canvas.Handle, 0, 0, SRCCOPY);
    end;procedure TMainFrm.ClientWndProc(var Message: TMessage);
    begin
      case Message.Msg of
      WM_EraseBKGnd:
        begin
          CallWindowProc(FoldClientProc, ClientHandle, Message.Msg,
                         Message.WParam, Message.LParam);
          FDrawDC := TWMEraseBKGnd(Message).DC;
          DrawStretched;  //拉伸
          //DrawCentered;   //居中
          //DrawTiled;      //平铺
          Message.Result := 1;
        end;
      WM_VSCROLL, WM_HSCROLL:
        begin
          Message.Result := CallWindowProc(FOldClientProc, CLientHandle,
                                      Message.Msg, Message.WParam, Message.LParam);
          InvalidateRect(ClientHandle, nil, True);
        end;
      else
        Message.Result := CallWindowProc(FOldClientProc, CLientHandle,
                                      Message.Msg, Message.WParam, Message.LParam);
      end;
    end;procedure TMainFrm.FormCreate(Sender: TObject);
    begin
      FNewClientProc := MakeObjectInstance(ClientWndProc);
      FOldClientProc := Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC));
      SetWindowLong(ClientHandle,GWL_WNDPROC,LongInt(FNewClientProc));
    end;重新装入新图片时,运行FormCreate中的代码
      

  3.   

    clear
    loadfromfile()
    refrish;