2013-06-28 143 views
0

我目前正试图添加镜像到我们的RotateBitmap例程(从http://www.efg2.com/Lab/ImageProcessing/RotateScanline.htm)。这目前看起来是这样的(BitMapRotated是TBitmap)的伪代码:如何“刷新”更改位图的ScanLine

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],但没有运气。

编辑:我找到了真正的问题 - 我重写我的变化从原始位值。对此感到抱歉。

+0

为什么不使用现成的库像Graphics32.org或吸血鬼的影像? –

+0

我只是有一个输出位图。无论如何,['这个Q&A'](http://stackoverflow.com/a/10633410/960757)可能对你的任务很有意思。 – TLama

+0

@ Arioch'The:我们已经在使用这个例程,它似乎是一个简单的任务来扩展它。 –

回答

1

也许这不是一个真正的答案,但是这个代码可以在D2006和XE3中使用,并且可以得到预期的结果。没有必要“冲洗”任何东西。

enter image description here

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); 
+0

谢谢!我会在星期一检查。可能是我的问题在我看来是另一个地方 –

+0

我再次检查 - 请参阅编辑。: - / –

相关问题