首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将更改“刷新”到位图的ScanLine

如何将更改“刷新”到位图的ScanLine
EN

Stack Overflow用户
提问于 2013-06-28 10:26:40
回答 1查看 329关注 0票数 0

我目前正在尝试将镜像添加到我们的RotateBitmap例程中(来自http://www.efg2.com/Lab/ImageProcessing/RotateScanline.htm)。目前,伪代码中的这个示例(BitMapRotated是一个TBitmap)如下所示:

代码语言:javascript
复制
var
  RowRotatedQ: pRGBquadArray; //4 bytes

if must reflect then
begin
  for each j do
  begin
    RowRotatedQ := BitmapRotated.Scanline[j];
    manipulate RowRotatedQ
  end;
end;

if must rotate then
begin
  BitmapRotated.SetSize(NewWidth, NewHeight); //resize it for rotation
  ...
end;

如果我必须旋转反射,这是可行的。如果两者都做了,那么显然对SetSize的调用通过ScanLine使我以前的更改无效。我如何“刷新”或保存我的更改?我试着打电话给BitmapRotated.HandleBitmapRotated.Dormant和设置BitmapRotated.Canvas.Pixels[0, 0],但都没有成功。

编辑:,我发现了真正的问题--我正在用原始位图中的值覆盖我的更改。很抱歉这么做。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-28 12:03:56

也许这并不是真正的答案,但这段代码在D2006和XE3中都有效,并给出了预期的结果。没有必要“冲洗”任何东西。

代码语言:javascript
复制
  procedure RotateBitmap(const BitMapRotated: TBitmap);
  type
    PRGBQuadArray = ^TRGBQuadArray;
    TRGBQuadArray = array [Byte] of TRGBQuad;
  var
    RowRotatedQ: PRGBQuadArray;
    t: TRGBQuad;
    ix, iy: Integer;
  begin
    //first step
    for iy := 0 to BitMapRotated.Height - 1 do begin
      RowRotatedQ := BitMapRotated.Scanline[iy];
     // make vertical mirror
      for ix := 0 to BitMapRotated.Width div 2 - 1 do begin
        t := RowRotatedQ[ix];
        RowRotatedQ[ix] := RowRotatedQ[BitMapRotated.Width - ix - 1];
        RowRotatedQ[BitMapRotated.Width - ix - 1] := t;
      end;
    end;

    //second step
    BitMapRotated.SetSize(BitMapRotated.Width  + 50, BitMapRotated.Height + 50);
    //some coloring instead of rotation
    for iy := 0 to BitMapRotated.Height div 10 do begin
      RowRotatedQ := BitMapRotated.Scanline[iy];
      for ix := 0 to BitMapRotated.Width - 1 do
        RowRotatedQ[ix].rgbRed := 0;
    end;
  end;

var
  a, b: TBitmap;
begin
  a := TBitmap.Create;
  a.PixelFormat := pf32bit;
  a.SetSize(100, 100);
  a.Canvas.Brush.Color := clRed;
  a.Canvas.FillRect(Rect(0, 0, 50, 50));
  b := TBitmap.Create;
  b.Assign(a);
  RotateBitmap(b);
  Canvas.Draw(0, 0, a);
  Canvas.Draw(110, 0, b);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17362589

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档