Answer the question
In order to leave comments, you need to log in
How to put camera image in ImageView?
Hello. Help solve the problem. The task is that there are 2 text fields and an imageView on the activity. By clicking on the imageView, the Camera opens, then I take a photo, confirm, and here is the problem (in theory, the following steps are as follows: the window goes to the previous activity and the photograph is inserted into the imageView, and I save the path to the variable and work further with it). But a window crashes with a Google+ error, which does not even register in the logs and that's it. Can you suggest another option? I will be grateful.
Log:
Error:
Activity file code:
package gligent.dotumt;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
import java.io.File;
public class AddMean extends AppCompatActivity {
final int CAMERA_CAPTURE = 1;
final int PIC_CROP = 2;
private Uri picUri;
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_mean);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//createDirectory();
// imageView =(ImageView)findViewById(R.id.ImageView);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
/////////////////////////////////////////////
public void onClick(View v) {
try {
// Намерение для запуска камеры
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(captureIntent, CAMERA_CAPTURE);
} catch (ActivityNotFoundException e) {
// Выводим сообщение об ошибке
String errorMessage = "Ваше устройство не поддерживает съемку";
Toast toast = Toast
.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
// Вернулись от приложения Камера
if (requestCode == CAMERA_CAPTURE) {
// Получим Uri снимка
picUri = data.getData();
performCrop();
}
// Вернулись из операции кадрирования
else if(requestCode == PIC_CROP){
Bundle extras = data.getExtras();
// Получим кадрированное изображение
Bitmap thePic = extras.getParcelable("data");
// передаём его в ImageView
ImageView picView = (ImageView)findViewById(R.id.ImageView);
picView.setImageBitmap(thePic);
//imageView.setImageBitmap(thePic);
}
}
}
private void performCrop(){
try {
// Намерение для кадрирования. Не все устройства поддерживают его
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(picUri, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("outputX", 256);
cropIntent.putExtra("outputY", 256);
cropIntent.putExtra("return-data", true);
startActivityForResult(cropIntent, PIC_CROP);
}
catch(ActivityNotFoundException anfe){
String errorMessage = "Извините, но ваше устройство не поддерживает кадрирование";
Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question