Skip to content

Commit

Permalink
test: fix crash on image.crop (#33148)
Browse files Browse the repository at this point in the history
* test: fix crash on image.crop

* Trigger CI
  • Loading branch information
dsanders11 committed Mar 23, 2022
1 parent 8ad1470 commit 4633376
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion spec-main/screen-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const formatHexByte = (val: number): string => {
* Get the hex color at the given pixel coordinate in an image.
*/
export const getPixelColor = (image: Electron.NativeImage, point: Electron.Point): string => {
const pixel = image.crop({ ...point, width: 1, height: 1 });
// image.crop crashes if point is fractional, so round to prevent that crash
const pixel = image.crop({ x: Math.round(point.x), y: Math.round(point.y), width: 1, height: 1 });
// TODO(samuelmaddock): NativeImage.toBitmap() should return the raw pixel
// color, but it sometimes differs. Why is that?
const [b, g, r] = pixel.toBitmap();
Expand Down

0 comments on commit 4633376

Please sign in to comment.