我想将文本与图像组合,并将组合的位图设置为ImageView。我编写了一段代码来从ImageView获取Bitmap并进行设置。现在不知道合适的代码来组合文本。
请帮忙。
public class MainActivity extends AppCompatActivity {
ImageView iv;
TextView tv;
Button btn_red, btn_green, btn_blue;
Bitmap bmp, operation;
int i,j;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView) findViewById(R.id.iv);
btn_red = (Button) findViewById(R.id.btn_red);
btn_blue = (Button) findViewById(R.id.btn_green);
btn_green = (Button) findViewById(R.id.btn_green);
BitmapDrawable drawable = (BitmapDrawable) iv.getDrawable();
bmp = drawable.getBitmap();
}
public void red(View view){
operation = Bitmap.createBitmap(bmp.getWidth(),bmp.getHeight(),bmp.getConfig());
for (i=0;i<bmp.getWidth();i++)
for (j=0;j<bmp.getHeight();j++){
int p =bmp.getPixel(i,j);
int r = Color.red(p)+100;
int g = Color.green(p);
int b = Color.blue(p);
int a = Color.alpha(p);
operation.setPixel(i,j,Color.argb(a,r,g,b));
}
iv.setImageBitmap(operation);
}