我的问题是我将从相机拍摄一张图像,然后将其发送到活动中的图像视图。之后,我需要在图像上绘制一个圆形或矩形。它应该是一个空闲的手。我的意思是我想画任何尺寸。然后应该保存该图像。我试图将图像放到视图中,但我无法绘制它。我是android的新手。任何人都可以帮助我吗?
//This is camera Intent
camera =(Button)findViewById(R.id.camera_button);
camera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
rl_main.setVisibility(View.GONE);
rl_image.setVisibility(View.VISIBLE);
Intent intent =new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(REQUEST_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
// start the image capture Intent
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case SPEECH_RECOGNITION_CODE: {
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> result = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
String text = result.get(0);
description.setText(text);
}
break;
}
case REQUEST_IMAGE_CAPTURE:
{
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
loadimage();
}
}
}
}
private void loadimage() {
if (fileUri!=null){
Bitmap myImg = BitmapFactory.decodeFile(fileUri.getPath());
File file = new File(fileUri.getPath());
BitmapFactory.Options bounds =new BitmapFactory.Options();
bounds.inSampleSize = 4;
bounds.inJustDecodeBounds = true;
String path = file.getPath();
BitmapFactory.decodeFile(path,bounds);
BitmapFactory.Options opts =new BitmapFactory.Options();
opts.inSampleSize = 4;
Bitmap bm = BitmapFactory.decodeFile(path,opts);
ExifInterface exif =null;
try {
exif =new ExifInterface(path);
} catch (IOException e) {
e.printStackTrace();
}
String orientString = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
int orientation = orientString != null ? Integer.parseInt(orientString) : ExifInterface.ORIENTATION_NORMAL;
int rotationAngle = 0;
if (orientation == ExifInterface.ORIENTATION_ROTATE_90){
rotationAngle = 90;
}
if (orientation == ExifInterface.ORIENTATION_ROTATE_180){
rotationAngle = 180;
}
if (orientation == ExifInterface.ORIENTATION_ROTATE_270){
rotationAngle = 270;
}
final Matrix matrix = new Matrix();
matrix.setRotate(rotationAngle, (float) bm.getWidth() / 2, (float) bm.getHeight() / 2);
Bitmap rotatedBitmap = Bitmap.createBitmap(bm, 0, 0, bounds.outWidth,bounds.outHeight, matrix, true);
/* Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap rotated = Bitmap.createBitmap(myImg, 0, 0, myImg.getWidth(), myImg.getHeight(),
matrix, true);*/
Bitmap mutableBitmap = rotatedBitmap.copy(Bitmap.Config.ARGB_8888, true);
camera_IV.setImageBitmap(mutableBitmap);
DisplayMetrics displaymetrics =new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height1 = displaymetrics.heightPixels;
int width1 = displaymetrics.widthPixels;
Log.e("MA", "Height= " + height1 + " " + width1);
paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.GREEN);
paint.setStrokeWidth(3);
// paint.setTextSize(25);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
originalBitmap =Bitmap.createScaledBitmap(rotatedBitmap, camera_IV.getWidth(), camera_IV.getHeight(), false);
imageBitmap = originalBitmap.copy(Bitmap.Config.RGB_565, true);
camera_IV.setOnDragListener(new View.OnDragListener() {
@Override
public boolean onDrag(View view, DragEvent dragEvent) {
return false;
}
});
camera_IV.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent event) {
});
BitmapFactory.Options myOptions = new BitmapFactory.Options();
myOptions.inDither = true;
myOptions.inScaled = false;
myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;// important
myOptions.inPurgeable = true;
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setColor(0xFFFF0000);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
// mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(10);
}
}
`