我目前正在尝试将镜像添加到我们的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;如果我,必须旋转或反射,这是可行的。如果两者都做了,那么显然对SetSize的调用通过ScanLine使我以前的更改无效。我如何“刷新”或保存我的更改?我试着打电话给BitmapRotated.Handle、BitmapRotated.Dormant和设置BitmapRotated.Canvas.Pixels[0, 0],但都没有成功。
编辑:,我发现了真正的问题--我正在用原始位图中的值覆盖我的更改。很抱歉这么做。
发布于 2013-06-28 12:03:56
也许这并不是真正的答案,但这段代码在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);https://stackoverflow.com/questions/17362589
复制相似问题