Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 利用Jhlabs图像处理库获取圆柱体图像_Java_Android_Graphic - Fatal编程技术网

Java 利用Jhlabs图像处理库获取圆柱体图像

Java 利用Jhlabs图像处理库获取圆柱体图像,java,android,graphic,Java,Android,Graphic,我想在我的项目中实现图像处理。我用过JLabs图书馆。我想用这个库做以下效果 1) 德博斯 2) 雕刻 3) 缎纹蚀刻 4) 自定义形状如圆柱体 这是示例图像浮雕代码 public class EmbossFilter extends WholeImageFilter { private static final float pixelScale = 255.9f; private float azimuth = 2.3561945f; private f

我想在我的项目中实现图像处理。我用过JLabs图书馆。我想用这个库做以下效果

1) 德博斯 2) 雕刻 3) 缎纹蚀刻 4) 自定义形状如圆柱体

这是示例图像浮雕代码

public class EmbossFilter
        extends WholeImageFilter {
    private static final float pixelScale = 255.9f;
    private float azimuth = 2.3561945f;
    private float elevation = 0.5235988f;
    private boolean emboss = false;
    private float width45 = 3.0f;

    public void setAzimuth(float azimuth) {
        this.azimuth = azimuth;
    }

    public float getAzimuth() {
        return this.azimuth;
    }

    public void setElevation(float elevation) {
        this.elevation = elevation;
    }

    public float getElevation() {
        return this.elevation;
    }

    public void setBumpHeight(float bumpHeight) {
        this.width45 = 3.0f * bumpHeight;
    }

    public float getBumpHeight() {
        return this.width45 / 3.0f;
    }

    public void setEmboss(boolean emboss) {
        this.emboss = emboss;
    }

    public boolean getEmboss() {
        return this.emboss;
    }

    @Override
    protected int[] filterPixels(int width, int height, int[] inPixels, Rect transformedSpace) {
        int index = 0;
        int[] outPixels = new int[width * height];
        int bumpMapWidth = width;
        int bumpMapHeight = height;
        int[] bumpPixels = new int[bumpMapWidth * bumpMapHeight];
        int i = 0;
        while (i < inPixels.length) {
            bumpPixels[i] = PixelUtils.brightness(inPixels[i]);
            ++i;
        }
        int Lx = (int) (Math.cos(this.azimuth) * Math.cos(this.elevation) * 255.89999389648438);
        int Ly = (int) (Math.sin(this.azimuth) * Math.cos(this.elevation) * 255.89999389648438);
        int Lz = (int) (Math.sin(this.elevation) * 255.89999389648438);
        int Nz = (int) (1530.0f / this.width45);
        int Nz2 = Nz * Nz;
        int NzLz = Nz * Lz;
        int background = Lz;
        int bumpIndex = 0;
        int y = 0;
        while (y < height) {
            int s1 = bumpIndex;
            int s2 = s1 + bumpMapWidth;
            int s3 = s2 + bumpMapWidth;
            int x = 0;
            while (x < width) {
                int shade;
                if (y != 0 && y < height - 2 && x != 0 && x < width - 2) {
                    int NdotL;
                    int Nx = bumpPixels[s1 - 1] + bumpPixels[s2 - 1] + bumpPixels[s3 - 1] - bumpPixels[s1 + 1] - bumpPixels[s2 + 1] - bumpPixels[s3 + 1];
                    int Ny = bumpPixels[s3 - 1] + bumpPixels[s3] + bumpPixels[s3 + 1] - bumpPixels[s1 - 1] - bumpPixels[s1] - bumpPixels[s1 + 1];
                    shade = Nx == 0 && Ny == 0 ? background : ((NdotL = Nx * Lx + Ny * Ly + NzLz) < 0 ? 0 : (int) ((double) NdotL / Math.sqrt(Nx * Nx + Ny * Ny + Nz2)));
                } else {
                    shade = background;
                }
                if (this.emboss) {
                    int rgb = inPixels[index];
                    int a = rgb & -16777216;
                    int r = rgb >> 16 & 255;
                    int g = rgb >> 8 & 255;
                    int b = rgb & 255;
                    r = r * shade >> 8;
                    g = g * shade >> 8;
                    b = b * shade >> 8;
                    outPixels[index++] = a | r << 16 | g << 8 | b;
                } else {
                    outPixels[index++] = -16777216 | shade << 16 | shade << 8 | shade;
                }
                ++x;
                ++s1;
                ++s2;
                ++s3;
            }
            ++y;
            bumpIndex += bumpMapWidth;
        }
        return outPixels;
    }

    public String toString() {
        return "Stylize/Emboss...";
    }
}
公共类过滤器
扩展整个图像过滤器{
专用静态最终浮点像素比例=255.9f;
专用浮标方位角=2.3561945f;
专用浮球标高=0.5235988f;
私有布尔浮雕=false;
专用浮子宽度45=3.0f;
公共空间设置方位角(浮动方位角){
这个方位角=方位角;
}
公共浮点数(){
返回此参数。方位角;
}
公共标高(浮动标高){
本图中,标高=标高;
}
公共浮点数(){
返回此参数。高程;
}
公共空隙高度(浮动高度){
该点宽度45=3.0f*凸起高度;
}
公共浮动高度(){
返回此0.45/3.0f;
}
公共空白设置浮雕(布尔浮雕){
this.emboss=浮雕;
}
公共布尔getEmpress(){
退回这个。浮雕;
}
@凌驾
受保护的int[]过滤器像素(int-width、int-height、int[]inPixels、Rect-transformedSpace){
int指数=0;
int[]输出像素=新的int[宽度*高度];
int bumpMapWidth=宽度;
int bumpmapeight=高度;
int[]bumpPixels=新int[bumpMapWidth*bumpMapHeight];
int i=0;
而(i>16&255;
int g=rgb>>8&255;
intb=rgb&255;
r=r*阴影>>8;
g=g*shade>>8;
b=b*阴影>>8;
输出像素[index++]=a | r