mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-23 05:52:42 -05:00
Save zero width and height on bitmap's imageData object
This commit is contained in:
parent
2f5c37910f
commit
75723a7ae2
2 changed files with 12 additions and 3 deletions
|
@ -329,10 +329,10 @@ const getHitBounds = function (raster) {
|
|||
let left = 0;
|
||||
let right = imageData.width;
|
||||
|
||||
while (bottom - 1 > top && rowBlank_(imageData, width, bottom - 1)) --bottom;
|
||||
while (top < bottom && rowBlank_(imageData, width, top)) ++top;
|
||||
while (right - 1 > left && columnBlank_(imageData, width, right - 1, top, bottom)) --right;
|
||||
while (bottom - 1 > top && rowBlank_(imageData, width, bottom - 1)) --bottom;
|
||||
while (left < right && columnBlank_(imageData, width, left, top, bottom)) ++left;
|
||||
while (right - 1 > left && columnBlank_(imageData, width, right - 1, top, bottom)) --right;
|
||||
|
||||
return new paper.Rectangle(left, top, right - left, bottom - top);
|
||||
};
|
||||
|
|
|
@ -89,9 +89,18 @@ const UpdateImageHOC = function (WrappedComponent) {
|
|||
}
|
||||
}
|
||||
const rect = getHitBounds(plasteredRaster);
|
||||
const imageData = plasteredRaster.getImageData(rect);
|
||||
|
||||
// If the bitmap has a zero width or height, save this information
|
||||
// since zero isn't a valid value for on imageData objects' widths and heights.
|
||||
if (rect.width === 0 || rect.height === 0) {
|
||||
imageData.sourceWidth = rect.width;
|
||||
imageData.sourceHeight = rect.height;
|
||||
}
|
||||
|
||||
this.props.onUpdateImage(
|
||||
false /* isVector */,
|
||||
plasteredRaster.getImageData(rect),
|
||||
imageData,
|
||||
(ART_BOARD_WIDTH / 2) - rect.x,
|
||||
(ART_BOARD_HEIGHT / 2) - rect.y);
|
||||
|
||||
|
|
Loading…
Reference in a new issue