设置像素;像素坐标与数据类型 'long'
setPixel; Pixelkoordinates with Datatype 'long'
我正在尝试将 Siemens Star 绘制到空位图中。当我记下圆像素坐标的公式时,pogramm 告诉我,它会产生一个长整数而不是整数。
double d = 0.001;
Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
for(int r = Rin; r < Rout; r++){
double phi = 0;
while( phi < 2* Math.PI){
for(int i = 0; i<Math.PI/nPeriods*1/d; i++){
int x = Math.round(X_Center + Math.cos(phi)*r);
int y = Math.round(Y_Center + Math.sin(phi)*r);
bmp.setPixel(x,y,Color.BLACK);
phi = phi+d;
}
for(int i = 0; i<Math.PI/nPeriods*1/d; i++){
phi = phi+d;
}
}
}
我已经在 Matlab 中尝试过这个算法,它运行良好。谁能告诉我我的错误?
您需要使用以下代码将 Math.round 结果转换为整数:
int x = (int) Math.round(X_Center + Math.cos(phi)*r);
我正在尝试将 Siemens Star 绘制到空位图中。当我记下圆像素坐标的公式时,pogramm 告诉我,它会产生一个长整数而不是整数。
double d = 0.001;
Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
for(int r = Rin; r < Rout; r++){
double phi = 0;
while( phi < 2* Math.PI){
for(int i = 0; i<Math.PI/nPeriods*1/d; i++){
int x = Math.round(X_Center + Math.cos(phi)*r);
int y = Math.round(Y_Center + Math.sin(phi)*r);
bmp.setPixel(x,y,Color.BLACK);
phi = phi+d;
}
for(int i = 0; i<Math.PI/nPeriods*1/d; i++){
phi = phi+d;
}
}
}
我已经在 Matlab 中尝试过这个算法,它运行良好。谁能告诉我我的错误?
您需要使用以下代码将 Math.round 结果转换为整数:
int x = (int) Math.round(X_Center + Math.cos(phi)*r);