죄송합니다. 수학 포럼에 소속되어 있으면 죄송합니다. HTML5 캔버스 요소 내에서 둥근 모서리가 둥글게 보이도록 이미지를 둥글게했습니다. 내가 _roundedCornersColour의 모든 인스턴스를 대체하고 있기 때문 만 작동포인트가 곡선 바깥에 있는지 확인하십시오.
var cornersImgData = tempContext.getImageData(0, 0, img.width, img.height);
var topLeft = getPixel(cornersImgData, 0, 0);
var topRight = getPixel(cornersImgData, cornersImgData.width - 1, 0);
var bottomLeft = getPixel(cornersImgData, 0, cornersImgData.height - 1);
// Check that the rounded corners have actually been applied (e.g. make sure the user hasn't just clicked the button and then undo)
var bottomRight = getPixel(cornersImgData, cornersImgData.width - 1, cornersImgData.height - 1);
if (('rgb(' + topLeft[0] + ', ' + topLeft[1] + ', ' + topLeft[2] + ')' == _roundedCornersColour) ||
('rgb(' + topRight[0] + ', ' + topRight[1] + ', ' + topRight[2] + ')' == _roundedCornersColour) ||
('rgb(' + bottomLeft[0] + ', ' + bottomLeft[1] + ', ' + bottomLeft[2] + ')' == _roundedCornersColour) ||
('rgb(' + bottomRight[0] + ', ' + bottomRight[1] + ', ' + bottomRight[2] + ')' == _roundedCornersColour))
{
for (var x = 0; x < cornersImgData.width; x++)
{
for (var y = 0; y < cornersImgData.height; y++)
{
var colour = getPixel(cornersImgData, x, y);
if ('rgb(' + colour[0] + ', ' + colour[1] + ', ' + colour[2] + ')' == _roundedCornersColour)
{
setPixel(cornersImgData, x, y, colour[0], colour[1], colour[2], 0);
}
}
}
}
가끔 이미지 자체 내에서 몇 픽셀을 교체 결국 : 나는 다음과 같은 코드가 있습니다. 고등학교 수학은 약간 녹슬었고 x와 y가 모서리가 있어야 할 곳을 벗어나는 지 확인하는 가장 좋은 방법을 알아낼 수 없습니다. 아무도 도와 줄 수 있습니까? 조
P. 나는 모서리의 반경을 안다. – JoeS