Click here to Skip to main content
15,914,165 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Repeat a typedef or include a header with the typedef? Pin
cmk20-Feb-10 12:21
cmk20-Feb-10 12:21 
QuestionKeyBoard Hook Pin
devidmorton19-Feb-10 9:22
devidmorton19-Feb-10 9:22 
AnswerRe: KeyBoard Hook [modified] Pin
Abhi Lahare19-Feb-10 10:05
Abhi Lahare19-Feb-10 10:05 
GeneralRe: KeyBoard Hook [modified] Pin
devidmorton20-Feb-10 8:31
devidmorton20-Feb-10 8:31 
GeneralRe: KeyBoard Hook Pin
Abhi Lahare22-Feb-10 5:13
Abhi Lahare22-Feb-10 5:13 
QuestionFast and efficeint way to rotate a bitmap at integer multiples of 90°?? Pin
Kiran Satish19-Feb-10 9:05
Kiran Satish19-Feb-10 9:05 
AnswerRe: Fast and efficeint way to rotate a bitmap at integer multiples of 90°?? Pin
Chris Losinger19-Feb-10 12:09
professionalChris Losinger19-Feb-10 12:09 
AnswerRe: Fast and efficeint way to rotate a bitmap at integer multiples of 90°?? Pin
Jonathan Davies20-Feb-10 1:17
Jonathan Davies20-Feb-10 1:17 
You seem on the right track and I've done this in the past. Looking back at my code I see that in my code I wrote a description of what I was trying to do which I'll put below to save rewriting in the hope that the explanation may help you.I haven't put my whole function below, I've left out the part that finds the size of the new bitmap from the size of the old but maybe the part I've put will help.

The diagram is a bit out due to tabbing size but looked fine in Visual Studio and I'm sure you an get the idea.

HRESULT ClassName::GetRotatedBitmapNT(/*[in]*/const CBitmap* pcbmBitmap, /*[out]*/CBitmap* &pcbmRotated, /*[in]*/float radians )
{
/*
Remarks:	A rotation is first applied to the corner co-ods of the input bitmap wrapped using the top-left
			corner as the 0,0 point. This gives a new set of corner co-od's from which the minimum amd maximum
			X and Y values can be found and the size of a bitmap required to contain a rotated bitmap with no 
			clipping of the corners can be found.

			A DIB bitmap of this size is then created and both this and the input bitmap are selected into 
			respectivew DC's. The background of the DIB being painted black its origin being altered to the
			minimum X and Y already found, these being -ve so that in the diagram below the 0,0 points
			of both bitmaps coincide. 

				origin2 xmin	0															xmax
						\	|	|															|
						  \					bitmap to hold rotated bitmap						
					ymin--	-----------------------------------------------------------------
							|																|
					0	--	|	---------------------------------------------------------	|
							|	|\					input bitmap						|	|
							|	| \														|	|
							|	|  \													|	|
							|	|	origin1												|	|
							|	|														|	|
							|	|														|	|
							|	|														|	|
							|	|														|	|
							|	|														|	|
							|	|														|	|
							|	|														|	|
							|	---------------------------------------------------------	|
							|																|
					ymax--	-----------------------------------------------------------------

			The World transform of the second DC is set to the transfor originally computed and when the input(1)
			is BitBlt'ed to the larger(2), this transform is applied to each pixel so that the whole bitmap is
			rotated, fitting nicely into the second bitmap. The second bitmap is then wrapped by a CBitmap
			and the [out] CBitmap* pcbmRotated set to point to it.
			[out] parameter

						
*/

and the code:
// Select source and destination bitmaps into their respective DC's
HBITMAP hbmOldSource = (HBITMAP)::SelectObject( hSourceDC, hBitmap );
HBITMAP hbmOldDest = (HBITMAP)::SelectObject( hDestDC, hbmResult );

// Draw the background color before changing mapping mode
HBRUSH hbrBack = CreateSolidBrush( clrBack );
HBRUSH hbrOld = (HBRUSH)::SelectObject( hDestDC, hbrBack );
PatBlt(hDestDC, 0, 0, (int)newwidth, (int)newheight, PATCOPY );
::DeleteObject( ::SelectObject( hDestDC, hbrOld ) );

BOOL bRet;
POINT OldSourceOrg;
POINT OldDestOrg;

bRet = OffsetWindowOrgEx(hDestDC,(int)xmin, (int)ymin, &OldDestOrg);

float C = (float)cos(radians);
float S = (float)sin(radians);

float T11 =  C;
float T12 =  S;
float T13 =  0;//- x;

float T21 =  -S;
float T22 =  C;
float T23 =  0;//- y;

// Use world transform to rotate the bitmap
// Set the advanced graphics mode to allow world transformations.
SetGraphicsMode(hDestDC, GM_ADVANCED);

// Set a two-dimensional linear transformation between world space and page space for
// the specified device context. This transformation can be used to scale, rotate,
// shear, or translate graphics output
XFORM xform;
xform.eM11 = T11;
xform.eM12 = T12;
xform.eM21 = T21;
xform.eM22 = T22;
xform.eDx =  T13;
xform.eDy =  T23;
SetWorldTransform( hDestDC, &xform );

// Now do the actual rotating
BitBlt(hDestDC,0,0,bm.bmWidth, bm.bmHeight, hSourceDC, 0, 0, SRCCOPY );

// Restore Origin.
bRet = OffsetWindowOrgEx(hSourceDC,OldSourceOrg.x, OldSourceOrg.y, NULL);

// Restore DCs
::SelectObject( hSourceDC, hbmOldSource );
::SelectObject( hDestDC, hbmOldDest );

pcbmRotated = new CBitmap();
pcbmRotated->Attach(hbmResult);

SetCursor(OldCursor);

return S_OK;

GeneralRe: Fast and efficeint way to rotate a bitmap at integer multiples of 90°?? Pin
Stephen Hewitt20-Feb-10 3:33
Stephen Hewitt20-Feb-10 3:33 
GeneralRe: Fast and efficeint way to rotate a bitmap at integer multiples of 90°?? Pin
Kiran Satish20-Feb-10 11:05
Kiran Satish20-Feb-10 11:05 
GeneralRe: Fast and efficeint way to rotate a bitmap at integer multiples of 90°?? Pin
Jonathan Davies20-Feb-10 11:30
Jonathan Davies20-Feb-10 11:30 
QuestionList of installed applications (as shown by "Open With" dialog box of windows.) Pin
Aseem Sharma19-Feb-10 1:10
Aseem Sharma19-Feb-10 1:10 
AnswerRe: List of installed applications (as shown by "Open With" dialog box of windows.) Pin
KingsGambit19-Feb-10 2:10
KingsGambit19-Feb-10 2:10 
AnswerRe: List of installed applications (as shown by "Open With" dialog box of windows.) Pin
fat_boy19-Feb-10 2:40
fat_boy19-Feb-10 2:40 
AnswerRe: List of installed applications (as shown by "Open With" dialog box of windows.) Pin
David Crow19-Feb-10 4:00
David Crow19-Feb-10 4:00 
QuestionConfusion Pin
john563218-Feb-10 23:41
john563218-Feb-10 23:41 
AnswerRe: Confusion Pin
Rajesh R Subramanian18-Feb-10 23:45
professionalRajesh R Subramanian18-Feb-10 23:45 
GeneralRe: Confusion Pin
john563218-Feb-10 23:56
john563218-Feb-10 23:56 
GeneralRe: Confusion Pin
Maximilien19-Feb-10 0:32
Maximilien19-Feb-10 0:32 
GeneralRe: Confusion Pin
Richard MacCutchan19-Feb-10 3:41
mveRichard MacCutchan19-Feb-10 3:41 
AnswerRe: Confusion Pin
KingsGambit19-Feb-10 2:21
KingsGambit19-Feb-10 2:21 
QuestionSorting/Arranging Rect buttons [modified] Pin
shiv@nand18-Feb-10 23:41
shiv@nand18-Feb-10 23:41 
AnswerRe: Sorting/Arranging Rect buttons Pin
Rajesh R Subramanian18-Feb-10 23:43
professionalRajesh R Subramanian18-Feb-10 23:43 
QuestionHow to add "Publisher" name to Custom Add ons in IE Pin
am 200918-Feb-10 23:30
am 200918-Feb-10 23:30 
AnswerRe: How to add "Publisher" name to Custom Add ons in IE Pin
KingsGambit19-Feb-10 1:25
KingsGambit19-Feb-10 1:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.