2013-06-28 142 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

我再次檢查 - 請參閱編輯。: - / –

相關問題