converting byte to bit
-
Hi I am doing a project in image processing using MFC. GetBitmapBits() stores the pixel value in a BYTE array. It works fine with 8 bits bitmap, but when working with 4 bits bitmap, it combines 2 pixel values and stores in the BYTE array. How to overcome this problem
-
Hi I am doing a project in image processing using MFC. GetBitmapBits() stores the pixel value in a BYTE array. It works fine with 8 bits bitmap, but when working with 4 bits bitmap, it combines 2 pixel values and stores in the BYTE array. How to overcome this problem
Use && and || to combine and mask values, instead of + or =. For example, FF && F0 == F0. If you take an 8 bit number and set it to equal itself && 15, you get only the low four bits, && 240 gives you the high four. In that way, you can set one pixel to zero. Then if you want to set the pixel in the low four bits, you just put oldVal || newval, that copies it in. to copy into the high four, do this: oldval || ( newVal << 4). this shifts the values up four bits first. To just set two pixels do this (pixelLeft << 4) + pixelRight. You can use plus here, because you're replacing both values. Christian Graus - Microsoft MVP - C++
-
Use && and || to combine and mask values, instead of + or =. For example, FF && F0 == F0. If you take an 8 bit number and set it to equal itself && 15, you get only the low four bits, && 240 gives you the high four. In that way, you can set one pixel to zero. Then if you want to set the pixel in the low four bits, you just put oldVal || newval, that copies it in. to copy into the high four, do this: oldval || ( newVal << 4). this shifts the values up four bits first. To just set two pixels do this (pixelLeft << 4) + pixelRight. You can use plus here, because you're replacing both values. Christian Graus - Microsoft MVP - C++
-
Close, but not quite. The operators he wants are | and & (bitwise operators as opposed to logical operators). See http://www.codeproject.com/cpp/bitbashing.asp[^]
Dagnamit. Sorry. :-O Christian Graus - Microsoft MVP - C++