ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Rotate 45 degrees

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
egrobler Posted - Apr 05 2014 : 19:31:57
Hi,

If I rotate a bitmap (square transparent png) 90 degrees everything works fine.

But when I do 45 degrees, the image gets smaller and smaller.
MyBitmap.Rotate(45, True, ierBicubic, clWhite);



I just want to position the car which is a square image at an angle while preserving it's size.

Thanks & Regards
Regards
Eric
4   L A T E S T    R E P L I E S    (Newest First)
egrobler Posted - Apr 06 2014 : 17:46:38
Hi William,

Thank you for the excellent detailed example.
I do not know the ImageEn library that well so I did not even consider to use a working layer and then to merge it.

After a long search I also found that I can pass center arguments to the resize procedure.
I will compare the 2 methods/approaches a bit later.

procedure Rotate45Example(aBitMap : TIEBitmap);
var ow, oh : Integer;
begin
  ow := aBitMap.Width;
  oh := aBitMap.Height;
  aBitMap.Rotate(45, True, ierBicubic, clWhite);
  aBitMap.Resize(ow, oh, 0, 0, iehCenter, ievCenter);
  ImageEnView1.Update;
end;


Regards
Eric
w2m Posted - Apr 06 2014 : 15:40:11
You can rotate the car in a layer and the car remains the same size regardless of the rotation angle. The actual layer grows to accommodate the car but the car dimensions is not changed.

Here is a demo:
PAS

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtDlgs, StdCtrls, ExtCtrls, imageenio, imageenproc, ieview,
  imageenview;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Open1: TButton;
    Rotate1: TButton;
    ImageEnView1: TImageEnView;
    ImageEnProc1: TImageEnProc;
    ImageEnIO1: TImageEnIO;
    OpenPictureDialog1: TOpenPictureDialog;
    Save1: TButton;
    SavePictureDialog1: TSavePictureDialog;
    AddLayer1: TButton;
    Exit1: TButton;
    Merge1: TButton;
    procedure Open1Click(Sender: TObject);
    procedure Rotate1Click(Sender: TObject);
    procedure Save1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure AddLayer1Click(Sender: TObject);
    procedure Exit1Click(Sender: TObject);
    procedure Merge1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses hyiedefs, hyieutils, iexhelperfunctions;

procedure TForm1.AddLayer1Click(Sender: TObject);
var
  iLayer: integer;
  iWidth: integer;
  iHeight: integer;
begin
  iLayer := ImageEnView1.LayersAdd;
  { Set IO Params }
  ImageEnView1.IO.Params.BitsPerSample := 8;
  ImageEnView1.IO.Params.SamplesPerPixel := 4;
  iWidth := ImageEnView1.IEBitmap.Width;
  iHeight := ImageEnView1.IEBitmap.Height;
  { Render a transparent layer }
  ImageEnView1.IEBitmap.IEInitialize(iWidth, iHeight, clBlack, True);
  ImageEnView1.Update;
  ImageEnView1.LayersCurrent := iLayer;
  ImageEnView1.CurrentLayer.VisibleBox := True;
  ImageEnView1.CurrentLayer.Selectable := True;
  ImageEnView1.LayersDrawBox := True;
  ImageEnView1.CurrentLayer.Locked := False;
  ImageEnView1.MouseInteract := [miMoveLayers, miResizeLayers];
end;

procedure TForm1.Exit1Click(Sender: TObject);
begin
  Close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  IERegisterFormats;
  OpenPictureDialog1.Filter := GraphicFilter(TGraphic);
  SavePictureDialog1.Filter := GraphicFilter(TGraphic);
   { Set bitmaps to handle transparency }
  ImageEnView1.IO.Params.BMP_HandleTransparency := True;
  ImageEnView1.LayersResizeAspectRatio := iearALTKey;
  { Allow selection of transparent layers }
  ImageEnView1.SelectionOptions := ImageEnView1.SelectionOptions +
    [iesoSelectTranspLayers];
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  IEUnregisterFormats;
end;

procedure TForm1.Merge1Click(Sender: TObject);
begin
  ImageEnView1.LayersMergeAll;
  ImageEnView1.Update;
end;

procedure TForm1.Open1Click(Sender: TObject);
begin
  if OpenPictureDialog1.Execute then
  begin
    ImageEnView1.IO.LoadFromFile(OpenPictureDialog1.Filename);
    ImageEnView1.Update;
  end;
end;

procedure TForm1.Rotate1Click(Sender: TObject);
begin
  ImageEnView1.IEBitmap.Rotate(45, True, ierBicubic, clWhite);
  ImageEnView1.LayersFixRotations(ImageEnView1.LayersCurrent);
  ImageEnView1.LayersFixSizes(ImageEnView1.LayersCurrent);
  ImageEnView1.LayersFixBorders(ImageEnView1.LayersCurrent);
  ImageEnView1.Update;
end;

procedure TForm1.Save1Click(Sender: TObject);
begin
  if SavePictureDialog1.Execute then
  begin
    ImageEnView1.IO.SaveToFile(SavePictureDialog1.Filename);
  end;
end;

end.
end.

DFM

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Rotate Layers'
  ClientHeight = 299
  ClientWidth = 635
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  OnDestroy = FormDestroy
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 635
    Height = 41
    Align = alTop
    TabOrder = 0
    DesignSize = (
      635
      41)
    object Open1: TButton
      Left = 11
      Top = 9
      Width = 75
      Height = 25
      Caption = 'Open'
      TabOrder = 0
      OnClick = Open1Click
    end
    object Rotate1: TButton
      Left = 173
      Top = 9
      Width = 75
      Height = 25
      Caption = 'Rotate'
      TabOrder = 1
      OnClick = Rotate1Click
    end
    object Save1: TButton
      Left = 335
      Top = 9
      Width = 75
      Height = 25
      Caption = 'Save'
      TabOrder = 2
      OnClick = Save1Click
    end
    object AddLayer1: TButton
      Left = 92
      Top = 9
      Width = 75
      Height = 25
      Caption = 'Add Layer'
      TabOrder = 3
      OnClick = AddLayer1Click
    end
    object Exit1: TButton
      Left = 545
      Top = 9
      Width = 75
      Height = 25
      Anchors = [akTop, akRight]
      Caption = 'Exit'
      TabOrder = 4
      OnClick = Exit1Click
    end
    object Merge1: TButton
      Left = 254
      Top = 9
      Width = 75
      Height = 25
      Caption = 'Merge'
      TabOrder = 5
      OnClick = Merge1Click
    end
  end
  object ImageEnView1: TImageEnView
    Left = 0
    Top = 41
    Width = 635
    Height = 258
    Background = clBtnFace
    ParentCtl3D = False
    EnableInteractionHints = True
    Align = alClient
    TabOrder = 1
  end
  object ImageEnProc1: TImageEnProc
    PreviewsParams = [prppShowResetButton, prppHardReset]
    PreviewFont.Charset = DEFAULT_CHARSET
    PreviewFont.Color = clWindowText
    PreviewFont.Height = -11
    PreviewFont.Name = 'Tahoma'
    PreviewFont.Style = []
    Left = 41
    Top = 66
  end
  object ImageEnIO1: TImageEnIO
    PreviewFont.Charset = DEFAULT_CHARSET
    PreviewFont.Color = clWindowText
    PreviewFont.Height = -11
    PreviewFont.Name = 'Tahoma'
    PreviewFont.Style = []
    Left = 76
    Top = 66
  end
  object OpenPictureDialog1: TOpenPictureDialog
    Left = 118
    Top = 66
  end
  object SavePictureDialog1: TSavePictureDialog
    Left = 154
    Top = 69
  end
end


Here are the png images for testing:
Road Background

Car

Result


Two Cars


STEPS
1. Open the road background.png
2. Add a layer
3. Open the car.png
4. Position the car with the mouse
5. Rotate the car as many times as you want at 45 degrees. (Angle does not matter}
6. Merge the layers
7. Save to a file

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Custom ImageEn Development
egrobler Posted - Apr 06 2014 : 14:13:06
Hi Nigel,

Yes, the actual image gets larger but the car gets smaller relative to the new image.

Corel has a maintain original image size option.
I assume I just need a function that will copy the center of the rotated image to a new bitmap?

Thanks
Eric
xequte Posted - Apr 06 2014 : 13:30:31
Hi Eric

I cannot reproduce that. I rotated an image 45 deg. eight times and the content remained the same size (though naturally the image as a whole becomes bigger because of the background area growing corners with each non-90 rotation).

You'll need to show us more code, I'm afraid.

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com