Form1.Brush.Bitmap:=Image1.Picture.Bitmap;
上面的对.bmp文件有效,但对.jpg文件无效。如何使.jpg文件平铺于窗口中?

解决方案 »

  1.   

    procedure TForm1.FormCreate(Sender: TObject);
    begin
      bitmap:=tbitmap.Create;
      bitmap.LoadFromFile('ppmm.bmp');
    end;
    procedure TForm1.FormPaint(Sender: TObject);
    var
      x,y,w,h:longint;
    begin
      with bitmap do
      begin
        w:=width;
        h:=height;
      end;
      y:=0;
      while y<height do
      begin
        x:=0;
        while x<width do
        begin
          canvas.Draw(x,y,bitmap);
          inc(x,w);
        end;
        inc(y,h);
      end;
    end;
      

  2.   

    呵呵,反正都是图啊。将别的格式转换成bmp的不就完了。
      

  3.   

    zdcnow(磁效应):还是不行啊,那段代码对.bmp有效,对.jpg则不行。TO ALL:我是要平铺而不是拉伸。
      

  4.   

    var
        BMP: TBitmap;
        JPEG: TJPEGImage;//首先将jpg格式的图片转换成BMP格式的,然后就可以实现你的功能了
    if (RightStr(OpenPictureDialog1.FileName,4)) = '.jpg')then
    begin
        JPEG := TJPEGImage.Create;
        JPEG.LoadFromFile(OpenPictureDialog1.FileName);
        BMP.Assign(JPEG);
        JPEG.Free;
    end;
      

  5.   

    procedure TForm1.FormPaint(Sender: TObject);
    var
      x,y,w,h:longint;
      Pic:TPicture;
    begin
      pic:=TPicture.Create;
      Pic.LoadFromFile('c:\fall06.jpg');
      with pic do
      begin
        w:=width;
        h:=height;
      end;
      y:=0;
      while y<height do
      begin
        x:=0;
        while x<width do
        begin
          canvas.StretchDraw(Rect(x,y,x+w,y+h),pic.Graphic);
          inc(x,w);
        end;
        inc(y,h);
      end;
         Pic.Free;
    end;
    在Onresize 事件中也要添加该代码!
    ok!
      

  6.   

    搞定了:将canvas.Draw(x,y,bitmap);改成canvas.Draw(x,y,Graphic);BTW:如何在Panel上画图?它没有canvas
      

  7.   

    to: TOBCB(修炼DELPHI) 你是怎么可以的..能不能全部代码贴出来