在我的应用程序中,我想在imageview上用手指画线.我希望输出如下:
在此屏幕中,fish是imageview,红线是绘制线条.所以我按照下面的链接开发应用程序 链接.这是我的代码:
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.addphoto);
btnAddPhoto=(Button)findViewById(R.id.add);
btnEdit=(Button)findViewById(R.id.edit);
imageView=(ImageView)findViewById(R.id.photo);
btnAddPhoto.setOnClickListener(this);
btnEdit.setOnClickListener(this);
imageView.setOnTouchListener(this);
}
@Override
public void onWindowFocusChanged(boolean hasFocus){
width=imageView.getWidth();
height=imageView.getHeight();
Log.e("heightttt",""+height);
Log.e("Widthhhh",""+width);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.equals(btnAddPhoto)){
popup.setVisibility(View.VISIBLE);
}
if(v.equals(btnEdit)){
bitmap = Bitmap.createBitmap((int) width, (int) height,Bitmap.Config.ARGB_8888);
canvas = new Canvas(bitmap);
paint = new Paint();
paint.setColor(Color.BLACK);
imageView.setImageBitmap(bitmap);
imageView.setOnTouchListener(this);
}
}
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
downx = event.getX(); …Run Code Online (Sandbox Code Playgroud)