У меня есть вид с кнопкой и просмотр изображений.Там я хочу сделать фотографию большого размера с помощью камеры Android и установить ее в режиме просмотра изображений.С помощью следующего кода я не получаю изображение в просмотре изображений.Что не так в моем коде? Пожалуйста, помогите. Спасибо за помощь
package de.camera.test;
...
public class CameratestActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
public File mTemp;
public ImageView image;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button cameraButton = (Button) findViewById(R.id.button);
image = (ImageView) findViewById(R.id.imageview);
cameraButton.setOnClickListener(this);
}
public void onClick(View v) {
Intent camera = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
try {
mTemp = File.createTempFile("myCameraShot", null);
camera.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
Uri.fromFile(mTemp));
startActivityForResult(camera, 0);
} catch (IOException e) {
e.printStackTrace();
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (data == null)
return;
Bitmap b;
try {
b = Media.getBitmap(getContentResolver(), Uri.fromFile(mTemp));
image.setImageBitmap(b);
Drawable d = image.getDrawable();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Макет main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<ImageView
android:id="@+id/imageview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>