473,396 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

GDI: Pixel intensity to grayscale bitmap drawing issue, MFC

1
Hi,

I am reading some image data out of a camera pixels and have extracted the raw pixel intensity. Each "pixel" on the Camera sensor has either a R,G, or B filter that gives the intensity of the 'R', 'G', or 'B' 'pixel'. I read this data and then extract and store the individual R, G, or B pixel intensities into 3 separate 2d unsigned char arrays called m_ptrRed2DPostDecimationArray. m_ptrGreen2DPostDecimationArray, and m_ptrBlue2DPostDecimationArray. Now I can use SetPixel to display the extracted R, G, and B in 3 separate 'R', 'G', or 'B' window areas. I can display them either in color or grayscale through:
For grayscale: dc.SetPixel(j, i, RGB(theApp.m_ptrRed2DPostDecimationArray[i][j], theApp.m_ptrRed2DPostDecimationArray[i][j], theApp.m_ptrRed2DPostDecimationArray[i][j]));
For color: dc.SetPixel(j, i, RGB(theApp.m_ptrRed2DPostDecimationArray[i][j], 0, 0));

However, I realize SetPixel is very ineffecient so looking at other ways to display. I only need the 8 bit grayscale image so was hoping that I could achieve it using CreateBitmap. m_ptrRed2DPostDecimationArray is a BYTE array (actually unsigned char) that holds the 8 bit raw pixel intensities from the camera pixels that have a red filter on them. Here is my current code (that does not work):
Expand|Select|Wrap|Line Numbers
  1. void CVC_ExampleDlg::OnPaint() 
  2. {
  3.         CDC *pDC = GetDC();
  4.  
  5.         BOOL retval = m_redBitmap.CreateBitmap(600, 200, 1, 8, theApp.m_ptrRed2DPostDecimationArray);
  6.  
  7.         CDC memDC; 
  8.         memDC.CreateCompatibleDC(pDC); 
  9.         memDC.SelectObject(&m_redBitmap);
  10.         retVal = pDC->BitBlt(0, 0, 600, 200, &memDC, 0, 0, SRCCOPY);
  11.         memDC.DeleteDC();
  12.                                 ReleaseDC(pDC);
  13.         CDialog::OnPaint();
  14. }
  15.  
Now I know I can create a grayscale palette and use the raw data as an index to that palette but it seems to me that CreateBitmap has that built in functionality. I mean it seems like that when I give it 1 color plane and 8bpp, it should automatically create a grayscale 8bit bitmap, no?

Can anyone see what I'm doing wrong. I mean all I want is that I already have the pixel intensity from 0-255 (8 bit) in a byte array. Since I just only want a grayscale bitmap, creating a grayscale palette and indexing it seems overkill especially when CreateBitmap seems to (theoretically) encapsulate that functionality.

I guess, if my question is clear enough, what is the easiet and/or most efficiect way to create a 8bit grayscale image from the raw pixel intensity value from 0-255?

Thank you,

-Vivek Kinra
Jun 2 '10 #1
0 2594

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Anirudh Saria | last post by:
Does anyone know how to read in a grayscale bitmap image in Visual C++ and store the pixel values in an array ? Thanks, Anirudh
0
by: Sébastien Bicaïs | last post by:
Hi, I made a VB class to generate images on the fly. The idea is to generate an image with a text, a font, a font size, a maximum width and height given as parameters, and the text to fit in the...
2
by: Nick Cardi | last post by:
I have a very strange issue. I have written a Dot Net application in VB.Net. When the application is run on some laptops the Forms are painted strangely. Labels are much wider then they were when...
0
by: Mike Starkey | last post by:
I have created a transparent control and I am using to to create drawing objects Inside the transparent objects I have created I am trying to using the draw shapes oval, rectangle etc. An example...
1
by: Dennis Myrén | last post by:
Hi. I use System.Drawing.Bitmap to copy bitmap pixel data. I use LockBits to retrieve a BitmapData which in turn provides me with the Scan0 property which i then use to loop the pixel data using...
6
by: Crirus | last post by:
Strange behaviour: I havea bitmap that I draw and add to an array of bitmaps... Do I have to create a bitmap using New every time? I tried to draw the bitmap in a for loop alike this: Dim...
3
by: Jason B | last post by:
Hi all, I'm somewhat new to Python and I'm trying to figure out the best way to accomplish the following: From an array of pixel data in an XML file (given the format, width and height of the...
3
by: Piotrekk | last post by:
Hi I i am zooming part of an image ( 15x15 px for example ). What i see are pixels ( but kinda renderred or something like that ) i nnot rectangular form. I need to see them as rectangular...
6
by: ProtossLee | last post by:
Hi, I am currently working on a project for image processing. a double matrix m1(1300X1000) need to be converted into bitmap and displayed on screen. so far I've made the following code: For i...
8
by: ofiras | last post by:
Hi, I made a "Paint" program, but I couldn't find a method to paint 1 pixel using graphic state ("Graphics g = Graphics.FromHwnd(this.Handle);") How can I paint 1 pixel? I guess I can make a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.