Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can write your own conversion in a "lockbits" method. It takes a while to understand how to lock/unlock bits correctly, but the effort is worth it, and once you have the code working you'll see how it can be applied to other scenarios. For example, using an lock/unlock bits technique you can access the pixel values from a bitmap, copy those pixel values into an array, manipulate the array, and then copy the modified array back into a bitmap. That's much faster than calling GetPixel() and SetPixel(). That's still not the fastest image manipulation code one can write, but it's relatively easy to implement and maintain the code.</p> <p>It's been a while since I've written VB6 code, but Bob Powell's often has good examples, and he has a page about lock bits:</p> <p><a href="http://www.bobpowell.net/lockingbits.htm" rel="nofollow">http://www.bobpowell.net/lockingbits.htm</a></p> <p>In a pinch you could create a new Bitmap of the appropriate format and call SetPixel() for every pixel:</p> <ol> <li>Every pixel (x,y) in your 24-bit color image will have a color value (r,g,b)</li> <li>After conversion to a 24-bit gray image, each pixel (x,y) will have a three equal values for each color channel; that can be expressed as (n,n,n) as Willem wrote in his reply. If all three colors R,G,B have the same value, then you can say that color value is the "grayscale" value of that pixel. This is the same shade of gray that you will see in your final 8-bit bitmap.</li> <li>Call SetPixel for each pixel (x,y) in a newly created 8-bit bitmap that is the same width and height as the original color image. </li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload