Click here to Skip to main content
15,887,175 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: problem about alloc memory in another library and free in the main project Pin
kcynic21-Dec-07 21:05
kcynic21-Dec-07 21:05 
GeneralNumber Lock activation Pin
Larry Mills Sr21-Dec-07 13:52
Larry Mills Sr21-Dec-07 13:52 
GeneralRe: Number Lock activation Pin
Mark Salsbery21-Dec-07 14:59
Mark Salsbery21-Dec-07 14:59 
GeneralRe: Number Lock activation Pin
Larry Mills Sr22-Dec-07 9:50
Larry Mills Sr22-Dec-07 9:50 
Question.RC file formating differences Pin
KayakCoder21-Dec-07 10:40
KayakCoder21-Dec-07 10:40 
GeneralI hate programming today (project conflict/calling convention conflict, ... ) Pin
Maximilien21-Dec-07 7:24
Maximilien21-Dec-07 7:24 
GeneralGetting the bitmap in and out of a CGIPLUS Image class Pin
Anthony Appleyard21-Dec-07 6:39
Anthony Appleyard21-Dec-07 6:39 
GeneralRe: Getting the bitmap in and out of a CGIPLUS Image class Pin
Mark Salsbery21-Dec-07 7:32
Mark Salsbery21-Dec-07 7:32 
One way to obtain a GDI bitmap from a GDI+ Bitmap is to use
Bitmap::GetHBITMAP() to get a copy as a GDI HBITMAP, something like:
Bitmap MyBitmap(L"C:\\some.jpg");

Color clr(0x00,0x00,0x00);
HBITMAP hbm;
MyBitmap.GetHBITMAP(clr, &hbm);

//BITMAP bm;
//::GetObject(hbm, sizeof(BITMAP), &bm);

You can also build a DIBSection and extract the pixel data yourself,
something like:
Bitmap MyBitmap(L"C:\\some.jpg");

WORD BitsPerPixel = 24;
int BytesPerRow = (((MyBitmap.GetWidth() * (long)BitsPerPixel + 31L) &(~31L)) / 8L);
int PixelDataSize = MyBitmap.GetHeight() * BytesPerRow;

BITMAPINFO BitmapInfo;

BITMAPINFOHEADER *pBMIH = &BitmapInfo.bmiHeader;
pBMIH->biSize = sizeof(BITMAPINFOHEADER);
pBMIH->biWidth = MyBitmap.GetWidth();
pBMIH->biHeight = MyBitmap.GetHeight(); // positive indicates bottom-up DIB
pBMIH->biPlanes = 1;
pBMIH->biBitCount = BitsPerPixel;
pBMIH->biCompression = BI_RGB;
pBMIH->biSizeImage = PixelDataSize;
pBMIH->biXPelsPerMeter = 0;
pBMIH->biYPelsPerMeter = 0;
pBMIH->biClrUsed = 0;
pBMIH->biClrImportant = 0;

BYTE *pPixelDataBytes = 0;
HBITMAP hBitmap = CreateDIBSection(NULL, &BitmapInfo, DIB_RGB_COLORS, (void **)&pPixelDataBytes , NULL, 0); 

BitmapData bmData;
Rect bmRect(0, 0, MyBitmap.GetWidth(), MyBitmap.GetHeight()); 
MyBitmap.LockBits(&bmRect, ImageLockModeRead, PixelFormat24bppRGB, &bmData); 

BYTE *pCurrentSourceByte = (BYTE *)bmData.Scan0;
// DIBsection is bottom-up...start at the bottom row...
BYTE *pCurrentDestinationByte = pPixelDataBytes + ((MyBitmap.GetHeight() - 1) * BytesPerRow);
// ... and work our way up
int DestinationStride = -BytesPerRow;

for (UINT CurY = 0; CurY < MyBitmap.GetHeight(); ++CurY)
{
	// copy one row of pixel data
	memcpy(pCurrentDestinationByte, pCurrentSourceByte, BytesPerRow);

	pCurrentSourceByte += bmData.Stride;
	pCurrentDestinationByte += DestinationStride;
}

MyBitmap.UnlockBits(&bmData);


Mark
Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

GeneralRe: Getting the bitmap in and out of a CGIPLUS Image class Pin
Anthony Appleyard21-Dec-07 12:19
Anthony Appleyard21-Dec-07 12:19 
GeneralRe: Getting the bitmap in and out of a CGIPLUS Image class Pin
Mark Salsbery21-Dec-07 12:39
Mark Salsbery21-Dec-07 12:39 
GeneralRe: Getting the bitmap in and out of a CGIPLUS Image class [modified] Pin
Anthony Appleyard21-Dec-07 23:29
Anthony Appleyard21-Dec-07 23:29 
GeneralRe: Getting the bitmap in and out of a CGIPLUS Image class Pin
Mark Salsbery22-Dec-07 7:06
Mark Salsbery22-Dec-07 7:06 
GeneralRe: Getting the bitmap in and out of a CGIPLUS Image class Pin
poda18-Mar-10 19:53
poda18-Mar-10 19:53 
GeneralGDI+ Why does the trick fail, one Rect to two Points Pin
followait21-Dec-07 6:16
followait21-Dec-07 6:16 
GeneralRe: GDI+ Why does the trick fail, one Rect to two Points Pin
Mark Salsbery21-Dec-07 6:26
Mark Salsbery21-Dec-07 6:26 
GeneralRe: GDI+ Why does the trick fail, one Rect to two Points Pin
followait21-Dec-07 7:45
followait21-Dec-07 7:45 
GeneralRe: GDI+ Why does the trick fail, one Rect to two Points Pin
Mark Salsbery21-Dec-07 8:48
Mark Salsbery21-Dec-07 8:48 
GeneralGDI+ A transformation from world coordinate to page coordinate makes picture foggy Pin
followait21-Dec-07 6:08
followait21-Dec-07 6:08 
GeneralRe: GDI+ A transformation from world coordinate to page coordinate makes picture foggy Pin
CPallini21-Dec-07 6:49
mveCPallini21-Dec-07 6:49 
GeneralGetUserName() return "SYSTEM" FOR SYSTEM PROCESS Pin
vicky0000021-Dec-07 4:25
vicky0000021-Dec-07 4:25 
GeneralRe: GetUserName() return "SYSTEM" FOR SYSTEM PROCESS Pin
myshketer21-Dec-07 5:05
myshketer21-Dec-07 5:05 
GeneralRe: GetUserName() return "SYSTEM" FOR SYSTEM PROCESS Pin
vicky0000021-Dec-07 6:02
vicky0000021-Dec-07 6:02 
GeneralRe: GetUserName() return "SYSTEM" FOR SYSTEM PROCESS Pin
Mark Salsbery21-Dec-07 6:35
Mark Salsbery21-Dec-07 6:35 
GeneralRe: GetUserName() return "SYSTEM" FOR SYSTEM PROCESS Pin
Mark Salsbery21-Dec-07 7:44
Mark Salsbery21-Dec-07 7:44 
GeneralExtra bytes between struct elements spoiling match between structs and binary file formats: cure found Pin
Anthony Appleyard21-Dec-07 1:59
Anthony Appleyard21-Dec-07 1:59 

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.