Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Bild um 270° drehen (https://www.delphipraxis.net/167239-bild-um-270%B0-drehen.html)

resyiii 19. Mär 2012 18:07

Bild um 270° drehen
 
das ist der quelltext, um ein bild mittels canvas um 90 grad zu drehen,

Code:
procedure BitmapDrehen_90Grad(const Bitmap: TBitmap);
var P: PRGBQuad; //^THelpRGB;
    x,y,b,h : Integer;
    RowOut: ^TMyHelp;
    help: TBitmap;
begin
  Bitmap.PixelFormat := pf32bit;
  help := TBitmap.Create;
  try
    help.PixelFormat := pf32bit;
    b := bitmap.Height;
    h := bitmap.Width;
    help.Width := b;
    help.height := h;
    for y := 0 to (h-1) do
    begin
      rowOut := help.ScanLine[y];
      P := Bitmap.scanline[bitmap.height-1];
      inc(p,y);
      for x := 0 to (b-1) do
      begin
        rowout[x] := p^;
        inc(p,h);
      end;
    end;
  finally
    bitmap.Assign(help);
    help.Free;
  end;
end;


ich will mein bild aber auch in die andere richtung drehen, also entweder in -90° oder in 270°
wie ist das möglich?

Popov 19. Mär 2012 18:24

AW: Bild um 270° drehen
 
Versuch mal etwas mit for x zu machen.

resyiii 19. Mär 2012 18:30

AW: Bild um 270° drehen
 
hab was versucht, programm bricht aber immer zusammen

Popov 19. Mär 2012 18:36

AW: Bild um 270° drehen
 
Warum?

Bummi 19. Mär 2012 19:10

AW: Bild um 270° drehen
 
http://www.delphipraxis.net/165404-b...ll-drehen.html #7
eine neuere Unit ist auch enthalten in
http://www.delphipraxis.net/167172-r...-ausgeben.html

zeina 20. Feb 2019 09:38

AW: Bild um 270° drehen
 
Hallo,
ich habe noch dies Problem,gibt es jemanden mir ein paar tipp zu geben??

Neutral General 20. Feb 2019 09:45

AW: Bild um 270° drehen
 
Stell dir ein rechteckiges Bild vor. Such dir in diesem Bild ein Pixel (am besten am Rand) aus.
Dann dreh das Bild in deinem Kopf um 90° nach links schau dir an von wo nach wo dein Pixel wandert (X/Y-Position im Bild).

zeina 20. Feb 2019 09:50

AW: Bild um 270° drehen
 
Zitat:

Zitat von Neutral General (Beitrag 1426069)
Stell dir ein rechteckiges Bild vor. Such dir in diesem Bild ein Pixel (am besten am Rand) aus.
Dann dreh das Bild in deinem Kopf um 90° nach links schau dir an von wo nach wo dein Pixel wandert (X/Y-Position im Bild).

Danke Für Die Antwort.mein Programm kann ein bild nach rechts drehen.Ich würde gerne es auch nach links drehen.

Delphi-Quellcode:
type TRGBarray = array[0..0] of TRGBQuad;


procedure TFoto.rotate90(const Source:TGraphic ; Target: TBitmap);
var P: PRGBQuad;
  y, x, h, b: integer;
  Rowout: ^TRGBarray;
  sourcebmp: TBitmap;
begin
  sourcebmp := TBitmap.Create;
  try
    sourcebmp.PixelFormat := pf32bit;
    sourcebmp.Height := Source.Height;
    sourcebmp.Width := Source.Width;
    sourcebmp.Canvas.Draw(0, 0, Source);
    Target.PixelFormat := pf32bit;
    b := sourcebmp.Height;
    h := sourcebmp.Width;
    Target.Height := h;
    Target.Width := b;
    for y := 0 to (h - 1) do begin
      rowout := Target.ScanLine[y];
      p := sourcebmp.ScanLine[sourcebmp.height-1];
      inc(p, y);
      for x := 0 to (b-1) do begin
      rowout[x] := p^;
      inc(p, h);
    end;
    end;
  finally
    sourcebmp.Free;
  end;
end;

Sherlock 20. Feb 2019 10:00

AW: Bild um 270° drehen
 
Weisst Du wie Deine Methode ein Bild um 90° dreht? Das dürfte Dir die Lösung nämlich deutlich erleichtern... Schlagworte als Denkansatz: Zeilen, Spalten.

Sherlock

Alter Mann 20. Feb 2019 10:09

AW: Bild um 270° drehen
 
Versuch es hiermit mal:
Delphi-Quellcode:
procedure RotateBitmap(Degree: Word; Source, Dest: TBitmap);
var
  Points: array[0..2] of TPoint;
  Angle: Double;
  X1, X2,
  Y1, Y2: integer;
begin
  if Degree <= 360 then
  begin
    Angle:= (Degree- Degree div 90* 90)/ 180* pi;
    X1:= Round(Source.Width* sin(Angle));
    X2:= Round(Source.Width* cos(Angle));
    Y2:= Round(Source.Height* sin(Angle));
    Y1:= Round(Source.Height* cos(Angle));
    Case Degree of
      0..89, 360:
      begin
        Points[1] := Point(X2, 0);//rechts oben
        Points[0] := Point(0, X1);//links oben
        Points[2] := Point(Y2, Y1+ X1);//links unten
        Dest.Width:= X2+ Y2;
        Dest.Height:= Y1+ X1;
      end;
      90..179:
      begin
        Points[1] := Point(0, Y2);//rechts oben
        Points[0] := Point(X1, Y2+ X2);//links oben
        Points[2] := Point(X1+ Y1, X2);//links unten
        Dest.Width:= Y1+ X1;
        Dest.Height:= X2+ Y2;
      end;
      180..269:
      begin
        Points[1] := Point(Y2, X1+ Y1);//rechts oben
        Points[0] := Point(Y2+ X2, Y1);//links oben
        Points[2] := Point(X2, 0);//links unten
        Dest.Width:= X2+ Y2;
        Dest.Height:= Y1+ X1;
      end;
      270..359:
      begin
        Points[1] := Point(X1+ Y1, X2);//rechts oben
        Points[0] := Point(Y1, 0);//links oben
        Points[2] := Point(0, Y2);//links unten
        Dest.Width:= Y1+ X1;
        Dest.Height:= X2+ Y2;
      end;
    end;
    PlgBlt(Dest.Canvas.Handle, Points, Source.Canvas.Handle, 0, 0, Source.Width, Source.Height, 0, 0, 0);
  end;
end;
Habe ich hier in der DP gefunden.


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:21 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz