Click here to Skip to main content
15,886,362 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How i can Save Cimage file+ shapes & text on it? Pin
Alan Balkany1-Jul-10 5:59
Alan Balkany1-Jul-10 5:59 
GeneralRe: How i can Save Cimage file+ shapes & text on it? Pin
humais1-Jul-10 19:38
humais1-Jul-10 19:38 
GeneralRe: How i can Save Cimage file+ shapes & text on it? Pin
Alan Balkany6-Jul-10 3:23
Alan Balkany6-Jul-10 3:23 
QuestionDrawing on 8bpp grayscale bitmap (unmanaged) Pin
Alan Balkany29-Jun-10 4:52
Alan Balkany29-Jun-10 4:52 
AnswerRe: Drawing on 8bpp grayscale bitmap (unmanaged) Pin
Code-o-mat29-Jun-10 5:46
Code-o-mat29-Jun-10 5:46 
GeneralRe: Drawing on 8bpp grayscale bitmap (unmanaged) Pin
Alan Balkany29-Jun-10 5:53
Alan Balkany29-Jun-10 5:53 
GeneralRe: Drawing on 8bpp grayscale bitmap (unmanaged) Pin
Code-o-mat29-Jun-10 6:07
Code-o-mat29-Jun-10 6:07 
GeneralRe: Drawing on 8bpp grayscale bitmap (unmanaged) Pin
Alan Balkany29-Jun-10 8:21
Alan Balkany29-Jun-10 8:21 
Thanks for the help, Code-o-mat! I can now generate bitmaps, but they're coming out incorrectly.

Short version: I created an 8bpp bitmap, then I BitBlt it to the screen and save it into a file. The copy on the screen has color, which suggests it's not just 8bpp. The version saved to the file is 8bpp, but it's totally black, where it should have at least *some* of the drawing.

Question: How can I draw on an 8bpp grayscale bitmap and save it to a file? Can anyone see what I'm doing wrong?

========================================================
The Details

Declarations:
CBitmap bm;

HBITMAP hbm;
BITMAPINFO* bi = (BITMAPINFO *)malloc(sizeof(BITMAPINFO) + sizeof(RGBQUAD) * 256);
BITMAPINFOHEADER bih;


Constructor:
initBi ();
hbm = CreateDIBSection (hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);

...
void CEightBitDrawingView::initBi()
{
	bih.biSize = sizeof (BITMAPINFOHEADER);
	bih.biWidth = 200;
	bih.biHeight = -200;
	bih.biPlanes = 1;
	bih.biBitCount = 8;
	bih.biCompression = BI_RGB;
	bih.biSizeImage = 0;
	bih.biXPelsPerMeter = 14173;
	bih.biYPelsPerMeter = 14173;
	bih.biClrUsed = 0;
	bih.biClrImportant = 0;

	bi->bmiHeader = bih;

	for (int i = 0;   i < 256;   i++)
	{
		bi->bmiColors [i].rgbRed = i;
		bi->bmiColors [i].rgbGreen = i;
		bi->bmiColors [i].rgbBlue = i;
	}
}


OnDraw:

void CEightBitDrawingView::OnDraw(CDC* pDC/*pDC*/)
{

	CClientDC dc(this);
	CDC *mdc = GetDC ();

	HGDIOBJ tmp = mdc->SelectObject(hbm);

	mdc->FloodFill (0, 0, RGB (255, 255, 255));
	// Draw box:
	CBrush* br = new CBrush (RGB (255, 0, 255));
	CRect rect (30, 60, 130, 160);
	mdc->FillRect (&rect, br);

	mdc->TextOutW (50, 50, L"Testing...");

		CImage image;					
		//image.Attach ((HBITMAP)bm.m_hObject);
		image.Attach (hbm);
		HRESULT hr = image.Save(_T("C:\\test.tif"), Gdiplus::ImageFormatTIFF);


	GetClientRect(&rect);
	dc.BitBlt(0,0,rect.right,rect.bottom, mdc, 0,0,SRCCOPY);
	mdc->SelectObject (tmp);

	delete br;
}

GeneralRe: Drawing on 8bpp grayscale bitmap (unmanaged) Pin
Code-o-mat29-Jun-10 9:37
Code-o-mat29-Jun-10 9:37 
GeneralRe: Drawing on 8bpp grayscale bitmap (unmanaged) Pin
Code-o-mat29-Jun-10 9:46
Code-o-mat29-Jun-10 9:46 
GeneralRe: Drawing on 8bpp grayscale bitmap (unmanaged) Pin
Alan Balkany29-Jun-10 9:47
Alan Balkany29-Jun-10 9:47 
GeneralRe: Drawing on 8bpp grayscale bitmap (unmanaged) Pin
Code-o-mat29-Jun-10 9:55
Code-o-mat29-Jun-10 9:55 
GeneralRe: Drawing on 8bpp grayscale bitmap (unmanaged) Pin
Alan Balkany1-Jul-10 4:50
Alan Balkany1-Jul-10 4:50 
GeneralRe: Drawing on 8bpp grayscale bitmap (unmanaged) Pin
Code-o-mat1-Jul-10 5:57
Code-o-mat1-Jul-10 5:57 
QuestionShaving a section from a dialog. Pin
Spawn@Melmac29-Jun-10 4:46
Spawn@Melmac29-Jun-10 4:46 
AnswerRe: Shaving a section from a dialog. Pin
Code-o-mat29-Jun-10 5:13
Code-o-mat29-Jun-10 5:13 
GeneralRe: Shaving a section from a dialog. Pin
David Crow29-Jun-10 5:32
David Crow29-Jun-10 5:32 
GeneralRe: Shaving a section from a dialog. Pin
Code-o-mat29-Jun-10 5:34
Code-o-mat29-Jun-10 5:34 
GeneralRe: Shaving a section from a dialog. Pin
Spawn@Melmac29-Jun-10 5:51
Spawn@Melmac29-Jun-10 5:51 
GeneralRe: Shaving a section from a dialog. Pin
Code-o-mat29-Jun-10 5:58
Code-o-mat29-Jun-10 5:58 
AnswerRe: Shaving a section from a dialog. Pin
David Crow29-Jun-10 5:37
David Crow29-Jun-10 5:37 
GeneralRe: Shaving a section from a dialog. Pin
Spawn@Melmac29-Jun-10 5:55
Spawn@Melmac29-Jun-10 5:55 
GeneralRe: Shaving a section from a dialog. Pin
David Crow29-Jun-10 6:11
David Crow29-Jun-10 6:11 
GeneralRe: Shaving a section from a dialog. Pin
Spawn@Melmac29-Jun-10 6:43
Spawn@Melmac29-Jun-10 6:43 
AnswerRe: Shaving a section from a dialog. Pin
Maximilien29-Jun-10 5:55
Maximilien29-Jun-10 5:55 

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.