unit Unit1;
{$mode objfpc}{$H+}
interface
uses
wincrt,FileUtil,intfgraphics, windows, SysUtils,
Forms, Controls, Graphics, LResources,FPimage, GraphUtil,
Process, ExtCtrls, Dialogs, StdCtrls, LCLProc, ActnList, LCLIntf,
Interfaces, Buttons, ExtDlgs, Menus, ComCtrls, strutils,GR32, GR32_Transforms,
Classes, GraphType,LCLType, Variants;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var Bmp:TBitmap32;
mybitmap,mybitmap2:TBitmap;
Degs:extended;
AdjustSizeNow:boolean;
BkColor:TColor;
Transparent:boolean;
Tmp: TBitmap32;
Transformation: TAffineTransformation;
inf1,inf2:TLazIntfImage;
ImgFormatDescription: TRawImageDescription;
begin
Bmp := TBitmap32.create;
Bmp.width := 200;
Bmp.height := 200;
Bmp.loadfromfile('new1.bmp');
Degs := 45;
AdjustSizeNow := true;
BkColor := clNone;
Transparent := false;
Tmp := TBitmap32.Create;
Transformation := TAffineTransformation.Create;
try
Transformation.BeginUpdate;
Transformation.SrcRect := FloatRect(0, 0, Bmp.Width, Bmp.Height);
Transformation.Translate(-0.5 * Bmp.Width, -0.5 * Bmp.Height);
Transformation.Rotate(0, 0, -Degs);
if AdjustSizeNow then
with Transformation.GetTransformedBounds do
Tmp.SetSize(Round(Right - Left), Round(Bottom - Top))
else
Tmp.SetSize(Bmp.Width, Bmp.Height);
Transformation.Translate(0.5 * Tmp.Width, 0.5 * Tmp.Height);
Transformation.EndUpdate;
Tmp.Clear(Color32(BkColor));
if not Transparent then
Bmp.DrawMode := dmTransparent;
Transform(Tmp, Bmp, Transformation);
Bmp.Assign(Tmp);
Bmp.OuterColor := Color32(BkColor);
if Transparent then
Bmp.DrawMode := dmTransparent;
finally
Transformation.Free;
Tmp.Free;
end;
mybitmap := TBitmap.create;
mybitmap.width := Bmp.width;
mybitmap.height := Bmp.height;
mybitmap2 := TBitmap.create;
mybitmap2.width := mybitmap.width;
mybitmap2.height := mybitmap.height;
mybitmap.assign(Bmp);
//The TLazIntfImage stuff ensures that the bitmap is 24 bit.
inf2:=TLazIntfImage.Create(mybitmap.Width,mybitmap.Height);
inf1:= mybitmap.CreateIntfImage;
try
ImgFormatDescription.Init_BPP24_B8G8R8_BIO_TTB(mybitmap.Width,mybitmap.Height);
inf2.DataDescription:=ImgFormatDescription;
inf2.CopyPixels(inf1);
mybitmap2.PixelFormat:=pf24bit;
mybitmap2.LoadFromIntfImage(inf2);
mybitmap2.PixelFormat:=pf24bit;
finally
inf1.free;
inf2.Free;
end;
image1.width := Bmp.width;
image1.height := Bmp.height;
image1.picture.bitmap.Assign(mybitmap2);
mybitmap.free;
mybitmap2.free;
Bmp.free;
end;
end.