Précédent   Forum du club des développeurs et IT Pro > C et C++ > Outils pour C & C++ > C++Builder
C++Builder Environnement de développement RAD C++Builder. Avant de poster -> F.A.Q C++Builder, Sources C++Builder
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 07/06/2011, 14h04   #1
uknow
Membre régulier
 
Inscription : juin 2008
Messages : 88
Détails du profil
Informations forums :
Inscription : juin 2008
Messages : 88
Points : 85
Points : 85
Par défaut Rotation d'image avec bitblt/xform

Bonjour à tous,

J'essaie de faire pivoter une image, seulement le problème est que je n'arrive pas à spécifier un autre centre pour la rotation.

Mon image est rectangulaire mais contient un cercle centré, le code que j'utilise effectue bien une rotation mais sur le point haut gauche de mon image, ce qui bien entendu ne correspond pas à ce que je voudrais, et c'est pourquoi je viens vers vous; voici mon code actuel :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef M_PI
	#define M_PI 3.14
#endif
 
#define min(a, b)  (((a) < (b)) ? (a) : (b)) 
#define max(a, b)  (((a) > (b)) ? (a) : (b))
 
void  TProjector::rotatePicture(TImage * source, int angle)
{
	Graphics::TBitmap *SrcBitmap = source->Picture->Bitmap;
	Graphics::TBitmap *DestBitmap= new Graphics::TBitmap;
 
	float radians=(-2*3.1416*angle)/360;
 
	float cosine=(float)cos(radians);
	float sine=(float)sin(radians);
 
	float Point1x=(-SrcBitmap->Height*sine);
	float Point1y=(SrcBitmap->Height*cosine);
	float Point2x=(SrcBitmap->Width*cosine-SrcBitmap->Height*sine);
	float Point2y=(SrcBitmap->Height*cosine+SrcBitmap->Width*sine);
	float Point3x=(SrcBitmap->Width*cosine);
	float Point3y=(SrcBitmap->Width*sine);
 
	float minx=min(0,min(Point1x,min(Point2x,Point3x)));
	float miny=min(0,min(Point1y,min(Point2y,Point3y)));
	float maxx=max(Point1x,max(Point2x,Point3x));
	float maxy=max(Point1y,max(Point2y,Point3y));
 
	int DestBitmapWidth=(int)ceil(fabs(maxx)-minx);
	int DestBitmapHeight=(int)ceil(fabs(maxy)-miny);
 
	DestBitmap->Height=DestBitmapHeight;
	DestBitmap->Width=DestBitmapWidth;
 
	SetGraphicsMode(DestBitmap->Canvas->Handle,GM_ADVANCED);
	XFORM xform;
	xform.eM11=cosine;
	xform.eM12=-sine;
	xform.eM21=sine;
	xform.eM22=cosine;
	xform.eDx = (float)-minx;
	xform.eDy = (float)-miny;
 
	SetWorldTransform(DestBitmap->Canvas->Handle,&xform);
 
	BitBlt(DestBitmap->Canvas->Handle,
			0,
			0,
			DestBitmap->Width,
			DestBitmap->Height,
			SrcBitmap->Canvas->Handle,
			0,
			0,
			SRCCOPY);
 
	Image15->Picture->Bitmap = DestBitmap;
 
 
	delete DestBitmap;
}
Je développe sous Borland (BCB) sous windows. Si vous avez une astuce afin que je puisse faire tourner mon image sur son centre merci bien de m'en faire part.

Cordialement.
uknow est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/07/2011, 17h46   #2
nirgal76
Membre chevronné
 
Inscription : septembre 2007
Messages : 464
Détails du profil
Informations forums :
Inscription : septembre 2007
Messages : 464
Points : 730
Points : 730
Un exemple ici en delphi :

http://www.phidels.com/php/index.php...ip.php3&id=526
nirgal76 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 11h30.


 
 
 
 
Partenaires

Hébergement Web