How to draw a line using ontouchevent in image Bitmap as a background in android.here i am using image Bitmap as a background image in android.But the image will not be Overlapped if i draw a line.
Asked
Active
Viewed 2,793 times
1
-
http://www.coderanch.com/t/527716/Android/Mobile/Open-source-PDF-viewer-Android try this link.. – Deepak Swami Feb 24 '12 at 07:08
2 Answers
2
this is a beautiful link, u can follow this for your solution:

Community
- 1
- 1

jyotiprakash
- 2,086
- 1
- 20
- 26
0
use something like this in your on touch
/////declare variable/////
float downx = 0;
float downy = 0;
float upx = 0;
float upy = 0;
Canvas canvas;
Paint paint;
///////put this in on create//////
imageView = (ImageView)findViewById(R.id.ImageView);
bitmap = Bitmap.createBitmap(480,640,Bitmap.Config.ARGB_8888);
Display currentDisplay = getWindowManager().getDefaultDisplay();
float dw = currentDisplay.getWidth();
float dh = currentDisplay.getHeight();
canvas = new Canvas(bitmap);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStrokeWidth(6);
paint.setStrokeMiter(2);
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.RED);
imageView.setImageBitmap(bitmap);
imageView.setOnTouchListener(this);
/////bitmap = your bitmap you want to load as back ground/////
/////your on touch method///////
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action)
{
case MotionEvent.ACTION_DOWN:
downx = event.getX();
downy = event.getY();
break;
case MotionEvent.ACTION_MOVE:
upx = event.getX();
upy = event.getY();
canvas.drawLine(downx, downy, upx, upy, paint);
imageView.invalidate();
downx = upx;
downy = upy;
break;
case MotionEvent.ACTION_UP:
upx = event.getX();
upy = event.getY();
canvas.drawLine(downx, downy, upx, upy, paint);
imageView.invalidate();
break;
case MotionEvent.ACTION_CANCEL:
break;
default:
break;
}
return true;
}
i hope you got your answer..

Deepak Swami
- 3,838
- 1
- 31
- 46
-
-
finally another one error in onTouchevent imageview cannot be resolved.what is the mistake – Feb 24 '12 at 05:52
-
ya i put already.but still the imageview cannot be resolved in the line imageView.invalidate(); in ontouchevent – Feb 24 '12 at 05:57
-