Prev: Memory leak after closing thread. (Windows CE)
Next: How to AdjustTokenPrivileges() after ImpersonateLoggedOnUser() ?
From: JoeC on 3 Dec 2009 16:07 I have been going through my book looking for a bitmap example. I want to find the correct bitmap header then manually plug in the color and bit data then bilt that over to a bitmap. I want to create my own graphics editor. I have not had any success in win32 although I can do it in Direct X. I am looking for the header so I can: bitmap.x =16 bitmap.y=16 bitmap.palette[16] or [256] (color palette) bitmap.bitdata[] = an array with pixle data. then take that make an image that I can eventually edit.
From: marc on 4 Dec 2009 12:48 On 3 déc, 22:07, JoeC <enki...(a)yahoo.com> wrote: > I have been going through my book looking for a bitmap example. I > want to find the correct bitmap header then manually plug in the color > and bit data then bilt that over to a bitmap. I want to create my own > graphics editor. I have not had any success in win32 although I can > do it in Direct X. > I am looking for the header so I can: > bitmap.x =16 > bitmap.y=16 > bitmap.palette[16] or [256] (color palette) > bitmap.bitdata[] = an array with pixle data. > then take that make an image that I can eventually edit. Why don't you use LoadImage() ?
From: JoeC on 4 Dec 2009 22:17 On Dec 4, 11:48 am, marc <marc.tes...(a)caramail.com> wrote: > On 3 déc, 22:07, JoeC <enki...(a)yahoo.com> wrote: > > > I have been going through my book looking for a bitmap example. I > > want to find the correct bitmap header then manually plug in the color > > and bit data then bilt that over to a bitmap. I want to create my own > > graphics editor. I have not had any success in win32 although I can > > do it in Direct X. > > I am looking for the header so I can: > > bitmap.x =16 > > bitmap.y=16 > > bitmap.palette[16] or [256] (color palette) > > bitmap.bitdata[] = an array with pixle data. > > then take that make an image that I can eventually edit. > > Why don't you use LoadImage() ? Sorry, I am using C++ win32. I can do this in directX with this struct. struct BITMAP_FILE{ BITMAPFILEHEADER bitmapfileheader; BITMAPINFOHEADER bitmapinfoheader; PALETTEENTRY * palette; BYTE * buffer; }; I got this one from another book. struct BITMAP_INFO{ BITMAPFILEHEADER bmHead; RGBQUAD bmColor[16]; }; I have seen several ways to do it but they all involve loading a file. I want to create a picture by plugging in the data then move on to making a customized bitmap editing program. I have already done one for a monochrome bitmap.
From: Friedel Jantzen on 5 Dec 2009 01:35 Hi, > Sorry, I am using C++ win32. I can do this in directX with this > struct. > > struct BITMAP_FILE{ > BITMAPFILEHEADER bitmapfileheader; > BITMAPINFOHEADER bitmapinfoheader; > PALETTEENTRY * palette; > BYTE * buffer; > }; This is correct. However with bitsPerPixel >= 16 there is no palette required. > I got this one from another book. > > struct BITMAP_INFO{ > BITMAPFILEHEADER bmHead; > RGBQUAD bmColor[16]; > }; This is not correct: BITMAPINFOHEADER is required. > I have seen several ways to do it but they all involve loading a > file. I want to create a picture by plugging in the data then move on > to making a customized bitmap editing program. I have already done > one for a monochrome bitmap. You can use CreateDIBSection: http://msdn.microsoft.com/en-us/library/dd183494(VS.85).aspx Before writing the bmp file, you must write the BITMAPFILEHEADER. Or you can prepare a memory block by foot. Look here how to setup BITMAPINFOHEADER: http://msdn.microsoft.com/en-us/library/dd183376(VS.85).aspx Here is a sample for a 16bit bmp: <code> HGLOBAL CreateTestBmp16() { LONG width = 601; LONG height = 400; WORD bitsPerPixel = 16; LONG lineLen = width; // count of 16bit-pixel in scanline if(lineLen & 1) lineLen++; // bytes in line must be multiple of 4 LONG dataSize = height * lineLen * 2; // *2 : 16bit = 2 bytes const DWORD headerSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); DWORD fileSize = headerSize + dataSize; HGLOBAL hBmp = GlobalAlloc(GHND, fileSize); if(hBmp == NULL) return NULL; LPBYTE bmpPtr = (LPBYTE)GlobalLock(hBmp); // Header PBITMAPFILEHEADER fHdr; PBITMAPINFOHEADER iHdr; LPBYTE bPtr; fHdr = PBITMAPFILEHEADER(bmpPtr); bPtr = bmpPtr + sizeof(BITMAPFILEHEADER); iHdr = PBITMAPINFOHEADER(bPtr); bPtr += sizeof(BITMAPINFOHEADER); fHdr->bfType = 0x4D42; // "BM", Little Endian fHdr->bfSize = fileSize; fHdr->bfReserved1 = 0; fHdr->bfReserved2 = 0; fHdr->bfOffBits = headerSize; iHdr->biSize = sizeof(BITMAPINFOHEADER); iHdr->biWidth = width; iHdr->biHeight = height; iHdr->biPlanes = 1; iHdr->biBitCount = bitsPerPixel; iHdr->biCompression = BI_RGB; // no compression //iHdr->biSizeImage = 0; // must set this, if compressed //iHdr->biXPelsPerMeter = 0; //iHdr->biYPelsPerMeter = 0; //iHdr->biClrUsed = 0; //iHdr->biClrImportant = 0; // pixel data unsigned __int16 *linePtr = (unsigned __int16 *)bPtr; unsigned __int16 *pixPtr; for(int h = 0; h < height; h++) { pixPtr = linePtr; for(int w = 0; w < width; w++) { *pixPtr++ = (unsigned __int16)((w + h) & 0xFFFF); // 16 bit: b5g5r5a1 } linePtr += lineLen; } GlobalUnlock(hBmp); return hBmp; } </code> HTH, Friedel
From: JoeC on 6 Dec 2009 04:55
On Dec 5, 12:35 am, Friedel Jantzen <nospam_...(a)freenet.de> wrote: > Hi, > > > Sorry, I am using C++ win32. I can do this in directX with this > > struct. > > > struct BITMAP_FILE{ > > BITMAPFILEHEADER bitmapfileheader; > > BITMAPINFOHEADER bitmapinfoheader; > > PALETTEENTRY * palette; > > BYTE * buffer; > > }; > > This is correct. > However with bitsPerPixel >= 16 there is no palette required. > > > I got this one from another book. > > > struct BITMAP_INFO{ > > BITMAPFILEHEADER bmHead; > > RGBQUAD bmColor[16]; > > }; > > This is not correct: BITMAPINFOHEADER is required. > > > I have seen several ways to do it but they all involve loading a > > file. I want to create a picture by plugging in the data then move on > > to making a customized bitmap editing program. I have already done > > one for a monochrome bitmap. > > You can use CreateDIBSection:http://msdn.microsoft.com/en-us/library/dd183494(VS.85).aspx > Before writing the bmp file, you must write the BITMAPFILEHEADER. > > Or you can prepare a memory block by foot. > Look here how to setup BITMAPINFOHEADER:http://msdn.microsoft.com/en-us/library/dd183376(VS.85).aspx > > Here is a sample for a 16bit bmp: > > <code> > > HGLOBAL CreateTestBmp16() > { > LONG width = 601; > LONG height = 400; > WORD bitsPerPixel = 16; > LONG lineLen = width; // count of 16bit-pixel in scanline > if(lineLen & 1) lineLen++; // bytes in line must be multiple of 4 > LONG dataSize = height * lineLen * 2; // *2 : 16bit = 2 bytes > const DWORD headerSize = sizeof(BITMAPFILEHEADER) + > sizeof(BITMAPINFOHEADER); > DWORD fileSize = headerSize + dataSize; > > HGLOBAL hBmp = GlobalAlloc(GHND, fileSize); > if(hBmp == NULL) return NULL; > LPBYTE bmpPtr = (LPBYTE)GlobalLock(hBmp); > > // Header > PBITMAPFILEHEADER fHdr; > PBITMAPINFOHEADER iHdr; > LPBYTE bPtr; > > fHdr = PBITMAPFILEHEADER(bmpPtr); > bPtr = bmpPtr + sizeof(BITMAPFILEHEADER); > iHdr = PBITMAPINFOHEADER(bPtr); > bPtr += sizeof(BITMAPINFOHEADER); > > fHdr->bfType = 0x4D42; // "BM", Little Endian > fHdr->bfSize = fileSize; > fHdr->bfReserved1 = 0; > fHdr->bfReserved2 = 0; > fHdr->bfOffBits = headerSize; > > iHdr->biSize = sizeof(BITMAPINFOHEADER); > iHdr->biWidth = width; > iHdr->biHeight = height; > iHdr->biPlanes = 1; > iHdr->biBitCount = bitsPerPixel; > iHdr->biCompression = BI_RGB; // no compression > //iHdr->biSizeImage = 0; // must set this, if compressed > //iHdr->biXPelsPerMeter = 0; > //iHdr->biYPelsPerMeter = 0; > //iHdr->biClrUsed = 0; > //iHdr->biClrImportant = 0; > > // pixel data > unsigned __int16 *linePtr = (unsigned __int16 *)bPtr; > unsigned __int16 *pixPtr; > > for(int h = 0; h < height; h++) { > pixPtr = linePtr; > for(int w = 0; w < width; w++) { > *pixPtr++ = (unsigned __int16)((w + h) & 0xFFFF); // 16 bit: b5g5r5a1 > } > linePtr += lineLen; > } > > GlobalUnlock(hBmp); > return hBmp; > > } > > </code> > > HTH, > Friedel Thanks. What commands can I look up to add a palette to a bitmap. I created a 16 color palette because I didn't want to add in 256 colors. What I want to do is create a bitmap that is not just monochrome. I am looking for how to create the bitmap then attach the pixel data and the palette. This what I have for my current bitmap. BYTE cdata[] = {0xff, 0xff, 0xff, 0,0,0, 0xff,0,0, ... //RGB Color data int num = 16; BYTE * pdata = &cdata[0]; int datasz = 3*num; int count = 0; while(count < datasz/num ){ bfo.bmColor[count].rgbRed = *pdata++; bfo.bmColor[count].rgbBlue = *pdata++; bfo.bmColor[count].rgbGreen = *pdata++; bfo.bmColor[count].rgbReserved = PC_NOCOLLAPSE;; count++; } (I create a palette very similar to this in DX. But I can't figure out how to add the palette to the bitmap.) BITMAP bitmap = {0,16,16,2,1,1}; bitmap.bmBits = data; //Pixel data hbitmap = CreateBitmapIndirect(&bitmap); hdc = GetDC(hwnd); HDC hdcmem = CreateCompatibleDC(hdc); SelectObject(hdcmem, hbitmap); BitBlt(hdc, 100, 150, 16, 16 , hdcmem, 0, 0, SRCCOPY); DeleteDC(hdcmem); ReleaseDC(hwnd, hdc); |