Ver Mensaje Individual
  #2  
Antiguo 20-03-2015
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 38
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola aguml.

Código PHP:
#include <math>

void RotateBMP(Graphics::TBitmap *bmp, float rads, bool adjSize, TColor bkColor = clNone) {
  
float C,S;
  
Graphics::TBitmap *tmp = new Graphics::TBitmap;
  
int ofsX, ofsY;
  
TPoint pts[2];

  
C = cos(rads);
  
S = sin(rads);
  
tmp->TransparentColor     = bmp->TransparentColor;
  
tmp->TransparentMode      = bmp->TransparentMode;
  
tmp->Canvas->Brush->Color = bkColor;

  if(
adjSize) {
    
tmp->Width  = (int)bmp->Width * abs(C) + bmp->Height * abs(S);
    
tmp->Height = (int)bmp->Width * abs(S) + bmp->Height * abs(C);
    
ofsX        = (tmp->Width - bmp->Width * C + bmp->Height * S) / 2.0;
    
ofsY        = (tmp->Height - bmp->Width * S - bmp->Height * C) / 2.0;
  } else {
    
tmp->Width  = bmp->Width;
    
tmp->Height = bmp->Height;
    
ofsX        = (bmp->Width - bmp->Width * C + bmp->Height * S) / 2.0;
    
ofsY        = (bmp->Height - bmp->Width * S - bmp->Height * C) / 2.0;
  }
  
pts[0].x = floor(ofsX);
  
pts[0].y = floor(ofsY);
  
pts[1].x = floor(ofsX + bmp->Width * C);
  
pts[1].y = floor(ofsY + bmp->Width * S);
  
pts[2].x = floor(ofsX - bmp->Height * S);
  
pts[2].y = floor(ofsY + bmp->Height * C);
  
PlgBlt(tmp->Canvas->Handle, pts, bmp->Canvas->Handle, 0, 0,
    
bmp->Width, bmp->Height, 0, 0, 0);

  
bmp->Assign(tmp);
  
delete tmp;
} 
Ejemplo de uso:
Código PHP:
void __fastcall TForm1::btnRotateClick(TObject *Sender)
{
  
Graphics::TBitmap *bmp = new Graphics::TBitmap;
  
bmp->Assign(Image1->Picture->Bitmap);
  
RotateBMP(bmp, 0.5, false);
  
Image2->Picture->Bitmap->Assign(bmp);
  
delete bmp;
} 
Salida:



Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita