Hi, I am developing an application that captures images and sends them by email to capture images, works fine on the Samsung Galaxy and Sony Ericsson xperia, but doesnβt work on HTC devices, does anyone know the reason why? here is my image capture code
try { String fileName = Image_name+".jpg"; //create parameters for Intent with filename ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, fileName); values.put(MediaStore.Images.Media.DESCRIPTION,"Image capture by camera"); //imageUri is the current activity attribute, define and save it for later usage (also in onSaveInstanceState) outuri = getContentResolver().insert( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //outuri = Uri.fromFile(photo); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outuri); cameraIntent.putExtra("return-data", true); startActivityForResult(cameraIntent, 2); } catch (Exception e) { Toast.makeText(preview.this, ""+e, Toast.LENGTH_LONG).show(); }
and here is the code that I use to extract images
path = convertImageUriToFile(outuri, preview.this).getAbsolutePath(); arr.add(path); try { bitmap = getImage(path); public static File convertImageUriToFile (Uri imageUri, Activity activity) { Cursor cursor = null; try { String [] proj={MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID, MediaStore.Images.ImageColumns.ORIENTATION}; cursor = activity.managedQuery(imageUri, proj, // Which columns to return null, // WHERE clause; which rows to return (all rows) null, // WHERE clause selection arguments (none) null); // Order-by clause (ascending by name) int file_ColumnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); int orientation_ColumnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.ORIENTATION); if (cursor.moveToFirst()) { String orientation = cursor.getString(orientation_ColumnIndex); return new File(cursor.getString(file_ColumnIndex)); } return null; } finally { if (cursor != null) { cursor.close(); } } } public Bitmap getImage(String path) throws IOException { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(path, options); Bitmap targetBitmap=null; int srcWidth = options.outWidth; int srcHeight = options.outHeight; int[] newWH = new int[2]; newWH[0] = 1024; newWH[1] = (1024*srcHeight)/srcWidth; int inSampleSize = 1; while(srcWidth / 2 > newWH[0]){ srcWidth /= 2; srcHeight /= 2; inSampleSize *= 2; } // float desiredScale = (float) newWH[0] / srcWidth; // Decode with inSampleSize options.inJustDecodeBounds = false; options.inDither = false; options.inSampleSize = inSampleSize; options.inScaled = false; options.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap sampledSrcBitmap = BitmapFactory.decodeFile(path,options); ExifInterface exif = new ExifInterface(path); String s=exif.getAttribute(ExifInterface.TAG_ORIENTATION); System.out.println("Orientation>>>>>>>>>>>>>>>>>>>>"+s); Matrix matrix = new Matrix(); float rotation = rotationForImage(preview.this, Uri.fromFile(new File(path))); if (rotation != 0f) { matrix.preRotate(rotation); } int newh = ( w * sampledSrcBitmap.getHeight() ) /sampledSrcBitmap.getWidth(); Bitmap r=Bitmap.createScaledBitmap(sampledSrcBitmap, w, newh, true); Bitmap resizedBitmap = Bitmap.createBitmap( r, 0, 0, w, newh, matrix, true); return resizedBitmap; } }