取出一张图片的部分来。
是这样的我想将一张图片拉伸后取出它的部分图片来,请问如何做那??

解决方案 »

  1.   

    如果是BMP位图的话可以通过定位坐标截取图象
      

  2.   

    u2m(UpToMe) 如何做那。能告诉我吗?
      

  3.   

    给你讲个思路吧
    首先定位你要切割位图的左上角坐标
    例如
    const
      SKIN_FILENAME = file.bmp';  SRCPOINT_BUTOPEN: TPoint = (X: 0; Y: 94);切割时
      skinInit;
      skinLoad(ExtractFilePath(paramstr(0)) + SKIN_FILENAME);
      skinImgInitAndUpdate(ButOpen, SRCPOINT_BUTOPEN);需要用到以下单元
    // Skinned
    // Copyright ?2001 Pulsar Studio / Lord Trancos.unit Skinned;// --------------------------------------------------------------------interfaceuses Windows, Classes, Messages, Forms, Graphics, ExtCtrls;var
      Skin: TBitmap = nil;const
      SKIN_CHKVAL_FALSE = 0;
      SKIN_CHKVAL_TRUE = 1;// Main functions.
    function skinInit: boolean;
    function skinLoad(_filename: string): boolean;
    procedure skinClose;// TImage functions.
    procedure skinImgSetCell(var _img: TImage; _cell: byte);
    function skinImgGetCell(_img: TImage): byte;
    procedure skinImgSetValue(var _img: TImage; _value: byte);
    function skinImgGetValue(_img: TImage): byte;
    function skinInitImg(var _img: TImage; _srcPoint: TPoint): boolean;
    function skinImgInside(_img: TImage; _x, _y: Integer): boolean;
    procedure skinImgUpdate(_img: TImage);
    function skinImgChecked(_img: TImage): boolean;
    function skinImgInitAndUpdate(_img: TImage; _srcPoint: TPoint): boolean;
    // --------------------------------------------------------------------implementation// --------------------------------------------------------------------function skinInit: boolean;begin
      try
        Skin := TBitmap.Create;
        Result := true;
      except
        Result := false;
      end;
    end;// --------------------------------------------------------------------procedure skinClose;begin
      if Assigned(Skin) then
      begin
        Skin.Free;
        Skin := nil
      end;
    end;// --------------------------------------------------------------------function skinLoad(_filename: string): boolean;begin
      Result := false;
      if Assigned(Skin) then
      try
        Skin.LoadFromFile(_filename);
        Result := true;
      except
      end;
    end;// --------------------------------------------------------------------procedure skinImgSetCell(var _img: TImage; _cell: byte);begin
      _img.Tag := (_img.Tag and $FFFFFFF0) + (_cell and $F);
    end;// -------------------------------------------------------------------function skinImgGetCell(_img: TImage): byte;begin
      Result := (_img.Tag and $F);
    end;// -------------------------------------------------------------------procedure skinImgSetValue(var _img: TImage; _value: byte);begin
      _img.Tag := (_img.Tag and $FFFFFF0F) + ((_value and $F) shl 4);
    end;// -------------------------------------------------------------------function skinImgGetValue(_img: TImage): byte;begin
      Result := ((_img.Tag shr 4) and $F);
    end;// -------------------------------------------------------------------procedure skinImgSetSrcPoint(var _img: TImage; _p: TPoint);var _l: longint;begin
      _l := ((_p.x and $FFF) shl 20) + ((_p.y and $FFF) shl 8);
      _img.Tag := (_img.Tag and $FF) + _l;
    end;// -------------------------------------------------------------------function skinImgGetSrcPoint(_img: TImage): TPoint;begin
      Result.x := (_img.Tag shr 20) and $FFF;
      Result.y := (_img.Tag shr 8) and $FFF;
    end;// --------------------------------------------------------------------function skinInitImg(var _img: TImage; _srcPoint: TPoint): boolean;begin
      try
        _img.Picture.Bitmap.Width := _img.Width;
        _img.Picture.Bitmap.Height := _img.Height;
        skinImgSetSrcPoint(_img, _srcPoint);
        Result := true;
      except
        Result := false;
      end;
    end;// --------------------------------------------------------------------function skinImgInside(_img: TImage; _x, _y: Integer): boolean;begin
      Result := (_x > -1) and (_y > -1) and
        (_x < _img.Width) and (_y < _img.Height);
    end;// --------------------------------------------------------------------procedure skinImgUpdate(_img: TImage);var _src: TRect;
      _dst: TRect;
      _srcPoint: TPoint;begin
      // Get source point.
      _srcPoint := skinImgGetSrcPoint(_img);  // Get Source rect. (skin.bmp).
      _src.Left := (_srcPoint.x);
      _src.Top := (_srcPoint.y) + (_img.Height * skinImgGetCell(_img));
      _src.Right := (_src.Left + _img.Width);
      _src.Bottom := (_src.Top + _img.Height);  // Dest. rect.
      _dst := Rect(0, 0, _img.Width, _img.Height);  // Draw
      _img.Picture.Bitmap.Canvas.CopyRect(_dst, Skin.Canvas, _src);
    end;// --------------------------------------------------------------------function skinImgChecked(_img: TImage): boolean;var _val: byte;begin
      _val := skinImgGetValue(_img);
      Result := (_val = SKIN_CHKVAL_TRUE);
    end;function skinImgInitAndUpdate(_img: TImage; _srcPoint: TPoint): boolean;begin
      Result := skinInitImg(_img, _srcPoint);
      if (Result) then skinImgUpdate(_img);
    end;// --------------------------------------------------------------------end.