用Tbitmap调入一幅图片时,如果图片较大时。Tbitmap的width和height较小时它只能显示图片的局部。咋样使图片充满(stretch)Tbitmap?

解决方案 »

  1.   

    你试一下TBitMap.Canvas.StretchDraw
    ============================================================================
    The following example is taken from the custom draw demo. It shows how the OnCustomDraw event handler draws the background for the tree view before the items and lines are drawn.procedure TCustomDrawForm.TVCustomDraw(Sender: TCustomTreeView; const ARect: TRect; var DefaultDraw: Boolean);
    begin
    //This event should be used to draw any background colors or images.
    //ARect represents the entire client area of the TreeView.
    //Use the TreeView's canvas to do the drawing.
    //Note that drawing a background bitmap is not really supported by CustomDraw,
    //so scrolling can get messy. Best to subclass the TreeView and handle scrolling//messages.
      with TV.Canvas do
      begin
        if None1.Checked then //no picture
        begin
          Brush.Color := BkgColorDialog.Color;
          Brush.Style := FBrushStyle;
          FillRect(ARect);
        end else
          if Tile1.Checked then //tile bitmap
          begin
            Brush.Bitmap := Image1.Picture.Bitmap;
              FillRect(ARect);
            end else //Stretch across the canvas.            StretchDraw(ARect, Image1.Picture.Bitmap);
      end;
      DefaultDraw := FDefaultDraw;
      //setting DefaultDraw to false here prevents all calls to OnCustomDrawItem.
    end;
    ==============================================================================
    摘自Delphi 7 Help
      

  2.   

    如此简单,何苦来着,写那么多代码
    BitMap1.Stretch:=True;
      

  3.   

    D6的TBITMAP没有Stretch这个特性啵,D7才有吧?是吗?
      

  4.   

    TBitMap.Canvas.StretchDraw这么画可以,还一种是BitMap1.Stretch:=True;
      

  5.   

    Bitmap.Stretch := true;这样就可以了。不是d7才有的。。d5就有了,呵呵。。
      

  6.   

    Bitmap.autosize:=false;
    Bitmap.Stretch:=True;
      

  7.   

    我的咋没有呢?我下了d6的update2也不行呀?大家帮帮忙吧
      

  8.   

    先定义一个临时的TBitmap,然后 loadfromfile.载入。
    再用你的BitMap.Canvas.StretchDraw方法,将刚才的Bitmap的内容画上去就可以了吧。