Board index » delphi » How do I rotate a JPG image

How do I rotate a JPG image


2005-11-07 12:55:19 PM
delphi217
I'm sure this has been asked and answered many times here, but
I have never had to be it until now.
How do I rotate by 90 degrees, a TImage.Picture that has been
loaded from a jpg file? Does anyone have sample code or a
reference to code to do this?
 
 

Re:How do I rotate a JPG image

Mark Kimball wrote at 7-11-2005 5:55:19:
Quote
I'm sure this has been asked and answered many times here, but
I have never had to be it until now.
See: <tinyurl.com/dkzk2>
--
Groeten Sam Francke
 

Re:How do I rotate a JPG image

Mark Kimball writes:
Quote
I'm sure this has been asked and answered many times here, but
I have never had to be it until now.
How do I rotate by 90 degrees, a TImage.Picture that has been
loaded from a jpg file? Does anyone have sample code or a
reference to code to do this?
Here are some nice examples
www.efg2.com/Lab/ImageProcessing/RotateScanline.htm
www.efg2.com/Lab/ImageProcessing/FlipReverseRotate.htm
 

Re:How do I rotate a JPG image

Or use my wrapper:
codecentral.borland.com/Author.aspx
Gabriel
"Mark Kimball" <XXXX@XXXXX.COM>writes
Quote

I'm sure this has been asked and answered many times here, but
I have never had to be it until now.
How do I rotate by 90 degrees, a TImage.Picture that has been
loaded from a jpg file? Does anyone have sample code or a
reference to code to do this?
 

Re:How do I rotate a JPG image

Quote

I'm sure this has been asked and answered many times here, but
I have never had to be it until now.
How do I rotate by 90 degrees, a TImage.Picture that has been
loaded from a jpg file? Does anyone have sample code or a
reference to code to do this?
Here is the fastest way to do it: 4 times rotatate in 0milliseconds (0.8ms)
procedure TForm1.Button1Click(Sender: TObject);
Var
T1,T2 : DWord;
begin
T1:=gettickcount;
// Image1 must contain the picture to rotate, remember: no strect
Image2.Canvas.CopyRect(Rect(0,0,217,185),Image1.Canvas,Rect(217,0,0,185));
Image3.Canvas.CopyRect(Rect(0,0,217,185),Image2.Canvas,Rect(0,185,217,0));
Image4.Canvas.CopyRect(Rect(0,0,217,185),Image3.Canvas,Rect(217,0,0,185));
T2:=gettickcount;
Label1.caption:=' Time '+inttoStr(T2-T1);
end;
Regards
Jorgen Bauer
www.dncflex.dk please sign the guestbook to do a country test for me
 

Re:How do I rotate a JPG image

Quote
procedure TForm1.Button1Click(Sender: TObject);
Var
T1,T2 : DWord;
begin
T1:=gettickcount;
// Image1 must contain the picture to rotate, remember: no strect
Image2.Canvas.CopyRect(Rect(0,0,217,185),Image1.Canvas,Rect(217,0,0,185));
Image3.Canvas.CopyRect(Rect(0,0,217,185),Image2.Canvas,Rect(0,185,217,0));
Image4.Canvas.CopyRect(Rect(0,0,217,185),Image3.Canvas,Rect(217,0,0,185));
T2:=gettickcount;
Label1.caption:=' Time '+inttoStr(T2-T1);
end;

Sorry that was mirror / flip
Regards
Jorgen Bauer
www.dncflex.dk please sign the guestbook to do a country test for me
 

Re:How do I rotate a JPG image

OK, so do you (or does anyone) have example source CODE
(not components) to do the 90 degree rotate? Or links to
recent code examples would work too.
"JB" <XXXX@XXXXX.COM>writes:
Quote
>procedure TForm1.Button1Click(Sender: TObject);
>Var
>T1,T2 : DWord;
>begin
>T1:=gettickcount;
>// Image1 must contain the picture to rotate, remember: no strect
>Image2.Canvas.CopyRect(Rect(0,0,217,185),Image1.Canvas,Rect(217,0,0,185));
>Image3.Canvas.CopyRect(Rect(0,0,217,185),Image2.Canvas,Rect(0,185,217,0));
>Image4.Canvas.CopyRect(Rect(0,0,217,185),Image3.Canvas,Rect(217,0,0,185));
>T2:=gettickcount;
>Label1.caption:=' Time '+inttoStr(T2-T1);
>end;
>

Sorry that was mirror / flip


Regards

Jorgen Bauer
www.dncflex.dk please sign the guestbook to do a country test for me





 

Re:How do I rotate a JPG image

Mark Kimball writes:
Quote
OK, so do you (or does anyone) have example source CODE
(not components) to do the 90 degree rotate? Or links to
recent code examples would work too.


Just turn the pixels around. You need to work with intermediate bitmaps
to do the pixel processing.
procedure Rotate90(Source: TGraphic; Target: TJpegImage);
var
SourceBmp, TargetBmp: TBitmap;
r, c: Integer;
x, y: Integer;
begin
SourceBmp := TBitmap.Create;
SourceBmp.Assign(Source);
TargetBmp := TBitmap.Create;
TargetBmp.Width := SourceBmp.Height;
TargetBmp.Height := SourceBmp.Width;
for r := 0 to SourceBmp.Height - 1 do
begin
for c := 0 to SourceBmp.Width - 1 do
begin
//x := (SourceBmp.Height-1) - r; // -90
//y := c; //-90
x := r; //90
y := (SourceBmp.Width-1) - c; //90
// look into Bitmap.ScanLine for faster pixel access
TargetBmp.Canvas.Pixels[x, y] := SourceBmp.Canvas.Pixels[c, r];
end;
end;
Target.Assign(TargetBmp);
SourceBmp.Free;
TargetBmp.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Jpeg: TJPEGImage;
begin
Jpeg := TJPEGImage.Create;
Rotate90(Image1.Picture.Graphic, Jpeg);
Image1.Picture.Assign(Jpeg);
Jpeg.Free;
end;
 

Re:How do I rotate a JPG image

Mark Kimball writes:
Quote
OK, so do you (or does anyone) have example source CODE
(not components) to do the 90 degree rotate? Or links to
recent code examples would work too.
codecentral.borland.com/Item.aspx
It rotates Jpegs losslessly so that you don't lose any quality doing it.
Recommended!
Cheers,
Nicholas Sherlock
 

Re:How do I rotate a JPG image

I use Graphics32. sourceforge.net/projects/graphics32. Just takes 1
line of code:
var
MySourceImage: tBitmap32;
MyDestImage: tBitmap32;
begin
.
.
MySourceImage.Rotate90(MyDestImage);
.
.
end;
both images need to be tBitMap32.
-scott
"Mark Kimball" <XXXX@XXXXX.COM>writes
Quote

I'm sure this has been asked and answered many times here, but
I have never had to be it until now.
How do I rotate by 90 degrees, a TImage.Picture that has been
loaded from a jpg file? Does anyone have sample code or a
reference to code to do this?