Delphi 如何";齐平;更改位图';s扫描线
我目前正在尝试将镜像添加到RotateBitmap例程(从)。这在伪代码中当前看起来像这样(BitMapRotated是一个TBitmap):Delphi 如何";齐平;更改位图';s扫描线,delphi,bitmap,vcl,delphi-2007,scanline,Delphi,Bitmap,Vcl,Delphi 2007,Scanline,我目前正在尝试将镜像添加到RotateBitmap例程(从)。这在伪代码中当前看起来像这样(BitMapRotated是一个TBitmap): var RowRotatedQ: pRGBquadArray; //4 bytes if must reflect then begin for each j do begin RowRotatedQ := BitmapRotated.Scanline[j]; manipulate RowRotatedQ end; en
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;
如果I必须旋转或反射,则此选项有效。如果我同时执行这两项操作,则调用SetSize
显然会使我以前通过扫描线所做的更改无效。如何“刷新”或保存更改?我尝试调用BitmapRotated.Handle
,BitmapRotated.dorment
并设置BitmapRotated.Canvas.Pixels[0,0]
,但运气不好
编辑:我发现了real问题-我正在用原始位图中的值覆盖我的更改。很抱歉这么做。也许这并不是一个真正的答案,但这段代码在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);
为什么不使用Graphics32.org或Vampyre Imaging这样的现成库呢?我只需要一个输出位图。无论如何,您的任务可能很有趣。@Arioch'The:我们已经在使用此例程,扩展它似乎很容易。@TLama:IIUYC
BitmapRotated
已经是输出位图。例程声明为过程RotateBitmap(const BitmapOriginal:TBitmap;//输入位图(可能已转换)const BitMapRotated:TBitmap;//输出位图…
谢谢!我将在周一检查。可能我的问题出在我认为的其他地方。