加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 移动位图像素

发布时间:2020-12-15 09:40:19 所属栏目:大数据 来源:网络整理
导读:如果我想移动/移动位图的像素我该怎么办? procedure MovePixels(Bitmap: TBitmap; Horizontal,Vertical: Integer);begin { move the Bitmap pixels to new position }end; 例: 通过调用MovePixels(Image1.Picture.Bitmap,20,20),例如输出如下: 指定/更改
如果我想移动/移动位图的像素我该怎么办?

procedure MovePixels(Bitmap: TBitmap; Horizontal,Vertical: Integer);
begin
  { move the Bitmap pixels to new position }
end;

例:

通过调用MovePixels(Image1.Picture.Bitmap,20,20),例如输出如下:

指定/更改移动像素后左侧显示的画布颜色也很有用.所以在这个例子中灰色/棕色可能是蓝色等.

我注意到有Bitmap.Canvas.Pixels和Bitmap.Canvas.MoveTo属性,这是我需要做的吗?

我真的不知道,我打赌这很简单..

解决方法

您无法轻松移动像素,但您可以制作副本.

var
  Source,Dest: TRect;
....
Source := Rect(0,Bitmap.Width,Bitmap.Height);
Dest := Source;
Dest.Offset(X,Y);
Bitmap.Canvas.CopyRect(Dest,Bitmap.Canvas,Source);

剩下的就是用您选择的颜色填充空间,我确信您可以通过几次调用FillRect轻松完成.

但是,我认为不这样做会更简单.相反,我会创建一个新的位图.也许是这样的:

function CreateMovedImage(Bitmap: TBitmap; X,Y: Integer; BackColor: TColor): TBitmap;
var
  Source,Dest: TRect;
begin
  Source := Rect(0,Bitmap.Height);
  Dest := Source;
  Dest.Offset(X,Y);

  Result := TBitmap.Create;
  Try
    Result.SetSize(Bitmap.Width,Bitmap.Height);

    Result.Canvas.Brush.Style := bsSolid;
    Result.Canvas.Brush.Color := BackColor;
    Result.Canvas.FillRect(Source);

    Result.Canvas.CopyRect(Dest,Source);
  Except
    Result.Free;
    raise;
  End;
end;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读