Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros temas > Trucos
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Los mejores trucos

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 17-12-2007
Avatar de cHackAll
[cHackAll] cHackAll is offline
Baneado?
 
Registrado: oct 2006
Posts: 2.159
Poder: 20
cHackAll Va por buen camino
Rotando una imagen

Creo que es todo lo necesario para corregir imágenes escaneadas y tambien para edición de imagenes.

Código Delphi [-]
function Rotate(Canvas: TCanvas; Width, Height, iAngle: Integer; Back: LongBool): TBitmap;
var
 Points: array [0..2] of TPoint;
 Radio, Angle, _Angle: Real;
begin
 Points[0] := Point(-Width, Height);
 Points[1] := Point(Width, Height);
 Points[2] := Point(-Width, -Height);
// Points[3] := Point(Width, -Height);
 Radio := Sqrt(Sqr(Width / 2) + Sqr(Height / 2));
 _Angle := (360 - (iAngle mod 360)) * pi / 180;
 iAngle := 3;
 repeat Dec(iAngle);
  Angle := ArcTan(Points[iAngle].Y / Points[iAngle].X) + _Angle;
  if Points[iAngle].X < 0 then
   Angle := Angle + Pi;
  Points[iAngle] := Point(Round((Cos(Angle) * Radio) + Radio), Round(Radio - (Sin(Angle) * Radio)));
 until not LongBool(iAngle);

 Result := TBitmap.Create;
 Result.TransparentColor := clFuchsia;
 Result.Canvas.Brush.Color := clFuchsia;
 iAngle := Round(Radio * 2);
 Result.Height := iAngle;
 Result.Width := iAngle;
 plgblt(Result.Canvas.Handle, Points, Canvas.Handle, 0, 0, Width, Height, 0, 0, 0);
 if Back then Result.Canvas.CopyRect(Rect(0, 0, iAngle, iAngle), Result.Canvas, Rect(iAngle-1, 0, 0, iAngle));
end;

Modo de uso:

Código Delphi [-]
procedure TForm1.TrackBar1Change(Sender: TObject);
var Bitmap: TBitmap;
begin
 ImageHolder.Picture.LoadFromFile('c:\windows\Grano de café.bmp'); // TrackBar1.Min := -160; TrackBar1.Max := 160;
 Bitmap := Rotate(ImageHolder.Canvas, ImageHolder.Width, ImageHolder.Height, TrackBar1.Position, CheckBox1.Checked);
 ImageHolder.Picture.Assign(Bitmap);
 Bitmap.Destroy;
end;

Alternativas óptimas:
180º Result.Canvas.CopyRect(Rect(0, 0, Width, Height), Canvas, Rect(Width, Height - 1, 0, 0));
BitBlt(Result.Canvas.Handle, 0, 0, Width, Height, Canvas.Handle, 0, 0, SRCCOPY);

PD: en un truco anterior (Crear Thumbnails en blanco y negro de archivos JPEG), no hice la siguiente aclaración; se debiese liberar en algún momento la memoria asignada por la función... retorna un TBitmap asignado por si el usuario requiera editar el grafico después de utilizar la función.
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro


La franja horaria es GMT +2. Ahora son las 08:14:30.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi