una tomar samsung pantalla laptop hacer computadora como celular captura android camera imageview

android - tomar - Cuando capturo la imagen de la cámara, ¿perdió la calidad de la imagen? ¿Qué hacer?



como tomar captura de pantalla en computadora (4)

Mi código para hacer clic en una imagen es:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, 300);

Código de resultado de la actividad:

if (requestCode == 300) { Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, bytes); File destination = new File(Environment.getExternalStorageDirectory(), System.currentTimeMillis() + ".jpg"); FileOutputStream fo; try { destination.createNewFile(); fo = new FileOutputStream(destination); fo.write(bytes.toByteArray()); fo.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if(number.equalsIgnoreCase("1")) { imageViewOneNumber.setImageBitmap(thumbnail); image1=""; image1= getEncoded64ImageStringFromBitmap(thumbnail); } else { RelativeLayoutImage2.setVisibility(View.GONE); FrameImage2.setVisibility(View.VISIBLE); imageViewTwoNumber.setImageBitmap(thumbnail); image2=""; image2= getEncoded64ImageStringFromBitmap(thumbnail); } }

Imagen de la demostración de captura de cámara:

Por favor ayudame a resolver este problema. Cuando hago clic en la foto de la cámara, disminuye el tamaño de la imagen.


De los documentos

La aplicación Android Camera guarda una foto de tamaño completo si le das un archivo para guardar. Debe proporcionar un nombre de archivo totalmente calificado donde la aplicación de la cámara debe guardar la foto.

Código de muestra desde allí

File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File ... } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); } String mCurrentPhotoPath; private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = "file:" + image.getAbsolutePath(); return image; }


Implementarlo así:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File image = createImage(this); Uri uri = Uri.parse("file://" + image.getAbsolutePath()); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); startActivityForResult(intent, CAMERA_REQUEST); public File createImage(Context context) throws IOException { File dir = new File(Environment.getExternalStorageDirectory() + "/" + context.getString(R.string.company_name) + "/Images"); if (!dir.exists()) { if (!dir.mkdirs()) { throw new IOException("Something wrong happened at" + dir); } } String timeStamp = new SimpleDateFormat("ddMMyyyy_HHmmss", Locale.getDefault()).format(new Date()); String imageName = context.getString(R.string.app_name) + "_" + timeStamp + ".jpg"; return new File(dir.getPath() + File.separator + imageName); }

Y finalmente en onActivityResult() puedes obtener tu imagen:

if (requestCode == CAMERA_REQUEST) { //Here you can load image by Uri }


Use este código puede ser que lo ayude

Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE); String path=Environment.getExternalStorageDirectory()+File.separator+Constants.APP_FOLDER_NAME+File.separator+Constants.ATTACHMENTS_FOLDER_NAME; File mediapath=new File(path); if(!mediapath.exists()) { mediapath.mkdirs(); } captured_image_uri=null; captured_image_uri=Uri.fromFile(new File(mediapath.getPath(),"Image"+System.currentTimeMillis()+".jpg")); intent.putExtra(MediaStore.EXTRA_OUTPUT,captured_image_uri); startActivityForResult(intent, Constants.PICK_FILE_FROM_CAMERA);

onActivityResult escribe este código

if(requestCode==Constants.PICK_FILE_FROM_CAMERA&&resultCode==getActivity().RESULT_OK) { try { if(captured_image_uri!=null) { ExifInterface exifInterface = new ExifInterface(captured_image_uri.getPath()); int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); Matrix matrix = new Matrix(); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: { matrix.postRotate(90); break; } case ExifInterface.ORIENTATION_ROTATE_180: { matrix.postRotate(180); break; } case ExifInterface.ORIENTATION_ROTATE_270: { matrix.postRotate(270); break; } } FileInputStream fis = new FileInputStream(captured_image_uri.getPath()); Bitmap bmp = BitmapFactory.decodeStream(fis); Bitmap rotated = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true); FileOutputStream fos = new FileOutputStream(captured_image_uri.getPath()); rotated.compress(Bitmap.CompressFormat.JPEG, 85, fos); uploadFileToServer(captured_image_uri.getPath()); } }catch (Exception e) { e.printStackTrace(); } }


iniciar intento

Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); File file = new File(Environment.getExternalStorageDirectory()+File.separator + "image.jpg"); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intent, 300);

en onActivityResult(){..}

protected void onActivityResult(int requestCode, int resultCode, Intent data) { //Check that request code matches ours: if (requestCode == 300) { //Get our saved file into a bitmap object: File file = new File(Environment.getExternalStorageDirectory()+File.separator + "image.jpg"); Bitmap bitmap = decodeSampledBitmapFromFile(file.getAbsolutePath(), 1000, 700); } }

aquí está el decodeSampledBitmapFromFile()

public static Bitmap decodeSampledBitmapFromFile(String path, int reqWidth, int reqHeight) { // BEST QUALITY MATCH //First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(path, options); // Calculate inSampleSize, Raw height and width of image final int height = options.outHeight; final int width = options.outWidth; options.inPreferredConfig = Bitmap.Config.RGB_565; int inSampleSize = 1; if (height > reqHeight) { inSampleSize = Math.round((float)height / (float)reqHeight); } int expectedWidth = width / inSampleSize; if (expectedWidth > reqWidth) { //if(Math.round((float)width / (float)reqWidth) > inSampleSize) // If bigger SampSize.. inSampleSize = Math.round((float)width / (float)reqWidth); } options.inSampleSize = inSampleSize; // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(path, options); }