0

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

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;

如果我必须旋转反射,这将有效。如果我两者都做,那么显然调用会使我之前通过 ScanLine 所做的更改无效。如何“刷新”或保存我的更改?我尝试调用,并设置但没有运气。SetSizeBitmapRotated.HandleBitmapRotated.DormantBitmapRotated.Canvas.Pixels[0, 0]

编辑:我发现了真正的问题——我正在用原始位图中的值覆盖我的更改。很抱歉的努力。

4

1 回答 1

1

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

在此处输入图像描述

  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);
于 2013-06-28T12:03:56.423 回答