2013-06-28 4 views
0

J'essaie actuellement d'ajouter une mise en miroir à notre routine RotateBitmap (à partir de http://www.efg2.com/Lab/ImageProcessing/RotateScanline.htm). Cela ressemble actuellement à ceci (BitMapRotated est un TBitmap) en pseudo-code:Comment "vider" les modifications apportées à un ScanLine d'un bitmap

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; 

Cela fonctionne si je soit doit tourner ou réfléchir. Si je fais les deux alors apparemment l'appel à SetSize invalide mes changements précédents via ScanLine. Comment puis-je "vider" ou enregistrer mes modifications? J'ai essayé d'appeler BitmapRotated.Handle, BitmapRotated.Dormant et le réglage BitmapRotated.Canvas.Pixels[0, 0] mais sans chance.

Edit: J'ai trouvé le réel question - je suis mes changements avec l'écrasement des valeurs de l'image d'origine. Désolé pour l'effort.

+0

pourquoi ne pas utiliser libs comme ready-made Graphics32.org ou Vampyre Imaging? –

+0

Je voudrais simplement avoir un bitmap en sortie. Quoi qu'il en soit, ["ce Q & A"] (http://stackoverflow.com/a/10633410/960757) pourrait être intéressant pour votre tâche. – TLama

+0

@ Arioch'The: Nous utilisons déjà cette routine et il nous a semblé facile de l'étendre. –

Répondre

1

Peut-être que ce n'est pas vraiment une réponse, mais ce code fonctionne à la fois dans D2006 et XE3 et donne le résultat attendu. Il n'y a pas besoin de «vider» quoi que ce soit.

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

Merci! Je vais vérifier lundi. est ailleurs que je pense –

+0

J'ai encore vérifié - voir edit.: - / –

Questions connexes