如何将像素从一个位图复制到另一个圆形位图?

发布于 2024-09-29 09:29:52 字数 377 浏览 0 评论 0原文

我正在使用 setPixel 和 getPixel 函数,但它们使用的矩阵自然是矩形。我正在尝试复制圆形像素!

更新 : 现在我正在使用这个,但我希望有比这个更有效的东西:

for(int i=0;i<eHeight ; i++)
        for(int j=0;j<eWidth ; j++)
            if( Math.pow((i-eHeight/2),2) +  Math.pow((j-eWidth/2),2) < Math.pow((eHeight/2),2)) 
                mutable.setPixel((int)xpos+j, (int)ypos+i, r[i*eWidth + j]) ;

I am using setPixel and getPixel functions but they are using matrices which is naturally rectangle.I am trying to copy pixels shaped like circle !

update :
now i am using this but i hope there is something more efficient than this one :

for(int i=0;i<eHeight ; i++)
        for(int j=0;j<eWidth ; j++)
            if( Math.pow((i-eHeight/2),2) +  Math.pow((j-eWidth/2),2) < Math.pow((eHeight/2),2)) 
                mutable.setPixel((int)xpos+j, (int)ypos+i, r[i*eWidth + j]) ;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

维持三分热 2024-10-06 09:29:53

如果你的圈子是固定的,我敢打赌有一种方法可以使用遮罩来快速完成它 - 谷歌搜索告诉我 PorterDuffXfermode 就是你所需要的。

否则,您可以通过更有效地进行计算来节省一些时间。首先,不要使用 pow 来求平方。其次,预先计算环外的半径。理论上,你的编译器会为你解决所有这些问题,但不要指望它。

第三,考虑使用 Bresenham 圆算法 来查找圆的每一行的起点和终点,并且然后一次复制一行像素,而不是一次复制一个像素。

If your circle is fixed, I bet there's a way to use masks to do it really fast -- googling tells me that PorterDuffXfermode is what you need.

Otherwise, you can save some time by doing the computation more efficiently. First, don't use pow to square things. Second, precompute your radius outside the loop. Your compiler in theory will fix all this for you, but don't count on it.

Third, consider using Bresenham's circle algorithm to find the start and end of each row of the circle, and then copy the pixels one row at a time instead of one pixel at a time.

掐死时间 2024-10-06 09:29:53

您需要做一些数学计算来确定您要复制的像素是否应该是圆的一部分。

(x - h)^2 + (y - k)^2 = r^2

You will need to do some math to figure out if the pixel you are about to copy should be part of the circle or not.

(x - h)^2 + (y - k)^2 = r^2
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文