Tuesday, January 12, 2016

Under MOBILE, CBitmap :: GetBitmapBits not be used, there are other ways?




            


M_hBmpScreen handle on ppc when I do a screen capture, get the screen bitmap,
Then converted into CBitmap * PBmp = CBitmap :: FromHandle (m_hBmpScreen);
Find PBmp- & gt happen when the bit map data; GetBitmapBits () function can not be used in mobile CBitmap not this member function,
Prawn ask you, what tactics?
Reply:
Nobody knows?
Reply:
Display image needs onPaint () l in realization
The following code fragment sums up how to paint a bitmap:

// Create a DC that matches the device.
hdcMem = CreateCompatibleDC (hdc);

// Select the bitmap into the compatible device context.
hOldSel = SelectObject (hdcMem, hBitmap);

// Get the bitmap dimensions from the bitmap.
GetObject (hBitmap, sizeof (BITMAP), & amp; bmp);

// Copy the bitmap image from the memory DC to the screen DC.
BitBlt (hdc, rect.left, rect.top, bmp.bmWidth, bmp.bmHeight,
hdcMem, 0, 0, SRCCOPY);

// Restore original bitmap selection and destroy the memory DC.
SelectObject (hdcMem, hOldSel);
DeleteDC (hdcMem);

Reply:
I would like to take bitmap data processing, but do not know how to get
Reply:
fp = fopen (filename, "rb"); // read bmp file
fread (file_head, FILE_HEADER_SIZE, 1, fp); // read the file header
fread (img_head, IMG_HEADER_SIZE, 1, fp); // read image header
If bit_count == 8 need to re-read the words palette version data,
Finally ret = fread (buf, hight × width, 1, fp); // read data
Reply:
Is not read from the BMP file, I mean, there is no information to obtain the bitmap data from the bitmap handle method HBITMAP,
Such as: GetBits ()
pc on
Reply:
You did not know? Or score enough?!
Reply:
void GetDibBits (HBITMAP hSourceBitmap, DWORD & amp; dwSize,
LPVOID & amp; pBuffer, DWORD & amp; dwWidth, DWORD & amp; dwHeight)
{
if (! hSourceBitmap)
return;

// 1. Getting bimap size.
BITMAP bm;
GetObject (hSourceBitmap, sizeof (BITMAP), & amp; bm);


// 2. Creating new bitmap and receive pointer to it's bits.
HBITMAP hTargetBitmap;

//2.1 Initilize DIBINFO structure
DIBINFO dibInfo;
dibInfo.bmiHeader.biBitCount = 24;
dibInfo.bmiHeader.biClrImportant = 0;
dibInfo.bmiHeader.biClrUsed = 0;
dibInfo.bmiHeader.biCompression = 0;
dibInfo.bmiHeader.biHeight = bm.bmHeight;
dibInfo.bmiHeader.biPlanes = 1;
dibInfo.bmiHeader.biSize = 40;
dibInfo.bmiHeader.biSizeImage = bm.bmWidth * bm.bmHeight * 3;
dibInfo.bmiHeader.biWidth = bm.bmWidth;
dibInfo.bmiHeader.biXPelsPerMeter = 3780;
dibInfo.bmiHeader.biYPelsPerMeter = 3780;
dibInfo.bmiColors [0] .rgbBlue = 0;
dibInfo.bmiColors [0] .rgbGreen = 0;
dibInfo.bmiColors [0] .rgbRed = 0;
dibInfo.bmiColors [0] .rgbReserved = 0;

dwSize = dibInfo.bmiHeader.biSizeImage;
dwWidth = bm.bmWidth;
dwHeight = bm.bmHeight;

//2.2 Create bitmap and receive pointer to points into pBuffer
HDC hDC = :: GetDC (NULL);
ASSERT (hDC);
hTargetBitmap = CreateDIBSection (hDC,
(Const BITMAPINFO *) dibInfo,
DIB_RGB_COLORS,
(Void **) & amp; pBuffer,
NULL,
0);

:: ReleaseDC (NULL, hDC);


// 3. Copy source bitmap into the target bitmap.

//3.1 Create 2 device contexts
CDC memDc;
if (! memDc.CreateCompatibleDC (NULL))
{
ASSERT (FALSE);
}

CDC targetDc;
if (! targetDc.CreateCompatibleDC (NULL))
{
ASSERT (FALSE);
}

//3.2 Select source bitmap into one DC, target into another
HBITMAP hOldBitmap1 = (HBITMAP) :: SelectObject (memDc.GetSafeHdc (), hSourceBitmap);
HBITMAP hOldBitmap2 = (HBITMAP) :: SelectObject (targetDc.GetSafeHdc (), hTargetBitmap);

//3.3 Copy source bitmap into the target one
targetDc.BitBlt (0, 0, bm.bmWidth, bm.bmHeight, & amp; memDc, 0, 0, SRCCOPY);

//3.4 Restore device contexts
:: SelectObject (memDc.GetSafeHdc (), hOldBitmap1);
:: SelectObject (targetDc.GetSafeHdc (), hOldBitmap2);
memDc.DeleteDC ();
targetDc.DeleteDC ();

DeleteObject (hSourceBitmap);
DeleteObject (hTargetBitmap);
}
Reply:
Thank you for your support, upstairs should be feasible,
I have used very similar
custom class DIBSectionCE resolved, the internal implementation with upstairsBOOL CDIBSectionCE :: SetBitmap (HBITMAP hBitmap, CPalette * pPalette / * = NULL * /)
{
DeleteObject ();

if (! hBitmap)
return FALSE;

// Get dimensions of bitmap
BITMAP bm;
if (:: GetObject (hBitmap, sizeof (bm), (LPVOID) & amp;! bm))
return FALSE;
bm.bmHeight = abs (bm.bmHeight);

CWindowDC dc (NULL);
#ifndef DIBSECTION_NO_PALETTE
CPalette * pOldPalette = NULL;

No comments:

Post a Comment