How to get the color of bitmap pixel? #5241
Replies: 3 comments 4 replies
-
I don't believe it's currently possible to do this. The picking engine is focused on picking vector objects, so an entire bitmap is treated as a single object. I think you'd have to customize the picking shaders to pick within the bitmap. |
Beta Was this translation helpful? Give feedback.
-
As a workaround, you can render the bitmap into a separate canvas: const canvas = document.createElement("canvas");
const canvasContext = canvas.getContext("2d");
const layer = new BitmapLayer({
id: "BitmapLayer",
bounds: [-122.519, 37.7045, -122.355, 37.829],
opacity: 0.5, //the retrieved color stays the same for varying opacities
image: "https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/sf-districts.png",
pickable: true,
onClick: ({bitmap, layer}) => {
if (bitmap) {
const x = bitmap.pixel[0];
const y = bitmap.pixel[1];
canvas.width = bitmap.size.width;
canvas.height = bitmap.size.height;
canvasContext.drawImage(layer.props.image.props.data, 0, 0);
const pixelColor = canvasContext.getImageData(x, y, 1, 1).data;
console.log('Color at picked pixel:', pixelColor);
}
},
}); It does not seem to be possible currently to get the pixel value directly from the ImageBitmap (see stackoverflow). |
Beta Was this translation helpful? Give feedback.
-
is there still no method of getting a pixel value from bitmaplayer? |
Beta Was this translation helpful? Give feedback.
-
getPickingInfo() is returning the color of layer. How can I get the color of pixel on BitmapLayer?
Beta Was this translation helpful? Give feedback.
All reactions