Re: STGAPIBuffer rotated to landscape? Possible? How?



AFAIK there is no built in method to automatically rotate a bitmap for you built into GAPI. I don't use MFC but I'll tell you the approach I would take in pure code. Take the bitmap that needs to be rotated and copy it to a DIBSection then use the pointer to the raw bytes create a WORD array (76,800 items) and store all pixels as 16bit-565, rotating the picture -90 degrees as you go. Since bitmaps read from the bottom up the formula to get the pixels in the right spot would be (320-x)*240+(240-y). Then just copy the pixels to the screen buffer from the array.

MCM wrote:
I'm using STGapiBuffer on a PocketPC app. I've built things such that I can use MFC drawing functions to a memory DC (CBitmap-based) then use STGapiBuffer to throw it at the screen.

What I'm trying to do is tweak STGapiBuffer to rotate the bitmap for me as STGAPI is converting it to "native" format. I see that STGapiBuffer is getting at the bits, but it looks like the destination will need to be resized and the pixels need to be re-mapped to new locations.

Has anybody done this?

Currently, my display is 240x320 (as GAPI dictates). I'd like to make a 320x240 CBitmap and draw to it (which I can currently do) via a CDC. With that I need a modification to the "CreateNativeBitmap" and "CreateNativeBitmapFromBGRBits" functions that will rotate the bitmap from the standard orientation to the landscape orientation:


Transform the source bitmap (320x240) of:

 -------------------------> (+x)
|
|    (X0Y0)  X1 X2 .... (Xn-1=319)
|    Y0
|    Y1
|    ...
|    (Yn-1=239)
v
(+y)


to the desired orientation (90 CCW) of (240x320):

(+x)
^
|    (xn-1 = 319)
|    ...
|    x2
|    x1
|    (x0y0)  y1 y2 ... (yn-1 = 239)
|
 ------------------------> (+y)


In other words what needs to be changed in CreateNativeBitmap and CreateNativeBitmapFromBGRBits in order to rotate my HBITMAP 90deg counterclockwise?


Thanks!



.



Relevant Pages

  • Re: WM5 - Bitmap Rotation
    ... and use DirectX 3D to rotate and scale it. ... you're going to rotate the bitmap by 90, 180 or 270 degrees, because ... pixels from the original bitmap point to the same pixel on the ...
    (microsoft.public.pocketpc.developer)
  • Re: This is how I rotate an bitmap
    ... One of the cardinal rules is that you never rotate one way and then rotate back the other. ... Matrix transformations add compound errors to the values so that over time, ... Nothing of the original image is lost, it is getting smaller or the new bitmap is a little bigger then need be. ... When you've made your rotation there is no easy way to tell what is your original bitmap and what is white space. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Replacing the system mouse cursor
    ... PlgBlt is a fast way to rotate a bitmap. ... mouse_eventto inject mouse movements and clicks into Windows. ...
    (microsoft.public.vc.mfc)
  • Re: Text in Gdiplus
    ... from the bitmap do some form of rotate on it and then drawString. ... to rotate the text to the correct orientation and position. ... have no idea what the transform and matrix parameters were doing but ...
    (comp.lang.smalltalk.dolphin)
  • Re: Basic question
    ... The matrix transform relates to a Graphics object. ... To rotate the image ... Bitmap NorthBM = null; ... // load bitmap from file ...
    (microsoft.public.dotnet.framework.drawing)

Loading