locked
Display image from pixel values RRS feed

  • Question

  • Hi All,

    I need to open .pgm image, display it, edit and save it. I am able to do everything except displaying. All I have is a unsigned char pointer which has raw pixel values. Can any one help in this regards.

    Thanks in advance 
    Tuesday, December 22, 2009 8:38 AM

Answers

  • If you really have raw pixel values, try using CreateDIBitmap.  YOu will have to supply a bitmap header and if each row isn't a multiple of 4 bytes you may have to tweak your raw pixel values to make it that way.  But it should get you a HBITMAP for display.
    • Marked as answer by Nancy Shao Tuesday, December 29, 2009 6:00 AM
    Tuesday, December 22, 2009 6:21 PM
  • And where is BitBlt?
    Thursday, December 24, 2009 9:00 AM

All replies

  • I suppose you can convert pgm to bitmap (using Netpbm, for example) and then display it.
    Tuesday, December 22, 2009 4:28 PM
  • If you really have raw pixel values, try using CreateDIBitmap.  YOu will have to supply a bitmap header and if each row isn't a multiple of 4 bytes you may have to tweak your raw pixel values to make it that way.  But it should get you a HBITMAP for display.
    • Marked as answer by Nancy Shao Tuesday, December 29, 2009 6:00 AM
    Tuesday, December 22, 2009 6:21 PM
  • Yes, CreateDIBitmap is a good choice.
    Tuesday, December 22, 2009 6:54 PM
  • Thanks for suggestion.
    I will try your advice and let you know the result.
    Wednesday, December 23, 2009 5:13 AM
  • Hi,

    Sorry for delay in reply, I was involved in some high priority work. As you suggested, I've tried using CreateDIBitmap. But it is not displaying the image. I might be missing something. Here is what I did:
    HDC dc;
    	dc = ::GetDC(m_hWnd);
    	BITMAPINFOHEADER infoHeader;
    	infoHeader.biBitCount = 8;
    	infoHeader.biClrImportant = 0;
    	infoHeader.biClrUsed = 0;
    	infoHeader.biCompression = 0;
    	infoHeader.biHeight = 172;
    	infoHeader.biPlanes = 1;
    	infoHeader.biSize = 31702;
    	infoHeader.biSizeImage = 31648;
    	infoHeader.biWidth = 184;
    	infoHeader.biXPelsPerMeter = 3780;
    	infoHeader.biYPelsPerMeter = 3780;
    	BITMAPINFO bitmapInfo;
    	CreateDIBitmap(dc, &infoHeader, CBM_INIT, input, &bitmapInfo, DIB_RGB_COLORS);
    	::ReleaseDC(m_hWnd, dc);
    I am using MFC application. I apologise for missing any basic thing, I have worked on image processing but new to C++.
    Thursday, December 24, 2009 6:14 AM
  • And where is BitBlt?
    Thursday, December 24, 2009 9:00 AM