How to get jpeg from Android Camera? Does it seem to be returned from JpegCallback in the data parameter? This array can simply write to the file?
2 answers
Sex this week asked this question. Things are like this: if you want to completely control the whole process of obtaining an image, then you need to write the code yourself, such as, for example, by the shurik link. But personally, I have this approach caused some problems - periodic departures on different phones. On samsung gio, galaxy s - works, on htc desire, samsung ace, motorola milestone - departures. Fuck off. I made it a little easier - via intent and standard camera application:
private Uri imageUri; public void takePhoto(View view) { Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); File photo = new File(Environment.getExternalStorageDirectory(), "Pic.jpg"); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo)); imageUri = Uri.fromFile(photo); startActivityForResult(intent, TAKE_PICTURE); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case TAKE_PICTURE: if (resultCode == Activity.RESULT_OK) { Uri selectedImage = imageUri; getContentResolver().notifyChange(selectedImage, null); ImageView imageView = (ImageView) findViewById(R.id.ImageView); ContentResolver cr = getContentResolver(); Bitmap bitmap; try { bitmap = android.provider.MediaStore.Images.Media .getBitmap(cr, selectedImage); imageView.setImageBitmap(bitmap); Toast.makeText(this, selectedImage.toString(), Toast.LENGTH_LONG).show(); } catch (Exception e) { Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT) .show(); Log.e("Camera", e.toString()); } } } } P.S. the code is taken from here .
- Thanks, helpful. Two notes: The TAKE_PICTURE constant is defined in your Activity by you. - it is important that the application has access-permission not only to the camera, but also to write external storage - the standard intent will not be able to write to the private area for your application files. - bear11
- quite right, I did not finish it. - antonderevyanko
|
tried to google ? :) Quite a popular question
|