如何使用十六进制获取搜索栏

时间:2014-02-14 03:32:44

标签: java android

我试图让这个搜索栏改变黑白图片的对比度,问题是我需要使用这个特定的库,我必须插入应该影响对比度的代码段。它需要一个十六进制(有点笑)

static int Lower1 = 0xFFEEEEEE; //very close to White 
    static int Lower2 = 0xFFDDDDDD;

    static int Color1 = Color.WHITE;    //0xFFFFFFFF
    static int Color2 = Color.DKGRAY;
    static int Color3 = Color.BLACK;    //0xFF000000

    public static void sharpen(Bitmap source ) {
        sharpen(source, Lower1, Lower2, Color1, Color2, Color3 );
    }
    public static void sharpen(Bitmap source, int lower1 ) {
        sharpen(source, lower1, Lower2, Color1, Color2, Color3 );
    }
    public static void sharpen(Bitmap source, int lower1, int lower2, int color1, int color2, int color3 ) {
        int w = source.getWidth();
        int h = source.getHeight();

        //loop through pixels and make a hard determination
        //if white leave it, otherwise turn it black
        for (int x = 0; x < w; x++) {
          for (int y = 0; y < h; y++) {           
            int color = source.getPixel(x, y);
            if (color >= lower1)
                source.setPixel(x, y, color1);  
            else if (color >= lower2)
                source.setPixel(x, y, color2);
            else
                source.setPixel(x, y,color3);   
          }
        }
    }

这是我用于搜索栏的内容:

seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                sharp = back;
                ManipBitmap.sharpen(sharp,progress);
                image.setImageBitmap(sharp);

            }
        });

我正在尝试在移动滑块时更新背景,即黑色和白色图像 谢谢!

1 个答案:

答案 0 :(得分:2)

SeekBar值范围设置为0(0x00)到255(0xFF),然后将代码更改为:

@Override
public void onProgressChanged(SeekBar seekBar, int progress,
        boolean fromUser) {
    int lower = Color.argb(0xFF, progress, progress, progress);
    sharp = Bitmap.createBitmap(back); // create a copy

    ManipBitmap.sharpen(sharp,lower);
    image.setImageBitmap(sharp);
}

Color.argb(alpha, red, green, blue)将在ARGB中返回相应的颜色代码。此外,由于您的过程具有破坏性(覆盖相同的图像),您需要创建一个副本并对其进行操作。