将图像转换为绿色比例

时间:2017-11-25 06:17:53

标签: android

绿色转换图像

我试图以绿色标度转换图像..但是下面给出的代码不能正常工作.. plz告诉我这个代码有什么问题?如何转换绿色图像..请提出建议和解决方案..

     package com.example.tayyabamaryam.greenscale;

             import android.graphics.Bitmap;
             import android.graphics.Color;
             import android.graphics.drawable.BitmapDrawable;
             import android.os.Bundle;
             import android.support.v7.app.AppCompatActivity;
             import android.view.View;
             import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {
    Button b1;
    ImageView im;

    private Bitmap bmp;
    private Bitmap operation;




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        b1= (Button)findViewById(R.id.green) ;
        im=(ImageView)findViewById(R.id.img) ;

        BitmapDrawable abmp = (BitmapDrawable) im.getDrawable();
        bmp = abmp.getBitmap();
    }
    public void green(View view){
                operation = Bitmap.createBitmap(bmp.getWidth(),bmp.getHeight(), 
                bmp.getConfig());

        for(int i=0; i<bmp.getWidth(); i++){
            for(int j=0; j<bmp.getHeight(); j++){
                int p = bmp.getPixel(i, j);
                int r = Color.red(p);
                int g = Color.green(p);
                int b = Color.blue(p);
                int alpha = Color.alpha(p);

                r =  0;
                g =  g+150;
                b =  0;
                alpha = 0;
                operation.setPixel(i, j, Color.argb(Color.alpha(p), r, g, b));
            }
        }
        im.setImageBitmap(operation);
    }
}

1 个答案:

答案 0 :(得分:0)

用户滤色器

例如:

 icon.setColorFilter(Color.WHITE);