【问题标题】:setPixel; Pixelkoordinates with Datatype 'long'设置像素;数据类型为“long”的像素坐标
【发布时间】:2017-02-02 12:53:24
【问题描述】:

我正在尝试将 Siemens Star 绘制到空位图中。当我记下圆形像素坐标的公式时,程序告诉我,它会产生一个长整数而不是整数。

    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 中尝试过这种算法,效果很好。谁能告诉我我的错误?

【问题讨论】:

    标签: android math android-bitmap imaging


    【解决方案1】:

    您需要使用以下代码将 Math.round 结果转换为整数:

    int x = (int) Math.round(X_Center + Math.cos(phi)*r);
    

    【讨论】:

    • 这么简单...谢谢!
    猜你喜欢
    • 2015-01-17
    • 2013-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-04
    • 2023-04-06
    相关资源
    最近更新 更多