画圆(使用应用于带有for循环的图像中的像素)应用于、像素、图像、画圆

2023-09-03 10:19:43 作者:吹乱、一地阑珊

我想使用像素位置(从左上角开始,右下角结束)画一个圆(1或2表示循环)

我使用此方法成功绘制了一个矩形:

private void drawrect(int width,int height,int x,int y) {
    int top=y;
    int left=x;

    if(top<0){
        height+=top;
        top=0;
        }
    if(left<0){
        width+=left;
        left=0;
    }

    for (int j = 0; j <width; j++) {
        for (int i = 0; i <height; i++) {
                    pixels[((i+top)*w)+j+left] = 0xffffff;//white color
        }

    }

}
如何用TensorFlow实现基于深度学习的图像补全 看完这篇就明白了

像素数组包含像素索引,后跟其颜色。

pixels[index]=color;

在此之前,我将此代码用于"图像"和"像素"数组(如果这对您有帮助的话)

img = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
pixels = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();

但我如何才能像此图像一样只绘制白色像素而忽略其他像素?

推荐答案

以下是使用像素绘制圆的代码:它使用公式xend=x+r cos(角度)和yend=y+r sin(角度)。

#include <stdio.h>
#include <graphics.h>
#include <stdlib.h>
#include <conio.h>
#include <bios.h>
#include <math.h>

void DrawCircle(int x, int y, int r, int color)
{
      static const double PI = 3.1415926535;
      double i, angle, x1, y1;

      for(i = 0; i < 360; i += 0.1)
      {
            angle = i;
            x1 = r * cos(angle * PI / 180);
            y1 = r * sin(angle * PI / 180);
            putpixel(x + x1, y + y1, color);
      }
}

引用:http://www.softwareandfinance.com/Turbo_C/DrawCircle.html