List of usage examples for android.graphics Matrix preRotate
public boolean preRotate(float degrees)
From source file:Main.java
public static Bitmap rotateBitmap(Bitmap bitmap, int rotation) { Matrix matrix = new Matrix(); matrix.preRotate(rotation); Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);//w w w. j a va2 s .co m return rotatedBitmap; }
From source file:Main.java
public static Bitmap rotateFromDegree(Bitmap bitmap, int degree) { if (bitmap == null || degree == 0) return bitmap; Matrix matrix = new Matrix(); matrix.preRotate(degree); Bitmap mBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); return mBitmap; }
From source file:Main.java
public static Bitmap createRotatedBitmap(Bitmap bm, float degree) { Bitmap bitmap = null;// w w w . ja v a 2s . c o m if (degree != 0) { Matrix matrix = new Matrix(); matrix.preRotate(degree); bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true); } return bitmap; }
From source file:Main.java
private static Bitmap rotate(Bitmap bmp, int rotation) { if (rotation == 0) return bmp; try {/* ww w. ja va2 s . c o m*/ Matrix matrix = new Matrix(); matrix.preRotate(rotation); return Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true); } finally { bmp.recycle(); } }
From source file:Main.java
private static Matrix configureMatrix(int rotation, int rotationDegrees) { Matrix matrix = new Matrix(); if (rotation != 0f) { matrix.preRotate(rotationDegrees); }/*from ww w . jav a 2s .c o m*/ return matrix; }
From source file:Main.java
/** * Adjust the photo orientation/* w w w . j a v a 2 s. c o m*/ * @param pathToFile * @return */ public static Bitmap adjustPhotoOrientation(String pathToFile) { try { Bitmap bitmap = BitmapFactory.decodeFile(pathToFile); ExifInterface exif = new ExifInterface(pathToFile); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); int rotate = 0; switch (exifOrientation) { case ExifInterface.ORIENTATION_ROTATE_90: rotate = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: rotate = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: rotate = 270; break; } if (rotate != 0) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); // Setting pre rotate Matrix mtx = new Matrix(); mtx.preRotate(rotate); // Rotating Bitmap & convert to ARGB_8888, required by tess bitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, false); bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true); return bitmap; } } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:Main.java
static public Bitmap getOrientedBitmapFromBitmapAndPath(Bitmap bitmap, String filePath) { Log.d(TAG, "[AirImagePickerUtils] Entering getOrientedBitmapFromBitmapAndPath"); try {//from w w w . ja va2 s . c om // Get orientation from EXIF ExifInterface exif = new ExifInterface(filePath); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); // Compute rotation matrix Matrix rotation = new Matrix(); switch (exifOrientation) { case ExifInterface.ORIENTATION_ROTATE_90: rotation.preRotate(90); break; case ExifInterface.ORIENTATION_ROTATE_180: rotation.preRotate(180); break; case ExifInterface.ORIENTATION_ROTATE_270: rotation.preRotate(270); break; } // Return new bitmap Log.d(TAG, "[AirImagePickerUtils] Exiting getOrientedBitmapFromBitmapAndPath"); return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), rotation, true); } catch (Exception exception) { Log.d(TAG, "Couldn't fix bitmap orientation: " + exception.getMessage()); Log.d(TAG, "[AirImagePickerUtils] Exiting getOrientedBitmapFromBitmapAndPath"); return bitmap; } }
From source file:Main.java
public static Bitmap fixRotateMirrorImage(Bitmap src) { Matrix rotateRight = new Matrix(); float[] mirrorY = { -1, 0, 0, 0, 1, 0, 0, 0, 1 }; Matrix matrixMirrorY = new Matrix(); matrixMirrorY.setValues(mirrorY);/*from ww w . jav a 2s . co m*/ rotateRight.postConcat(matrixMirrorY); rotateRight.preRotate(270); final Bitmap rotMirrorImg = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), rotateRight, true); src.recycle(); return rotMirrorImg; }
From source file:fi.tuukka.weather.utils.Utils.java
public static void showImage(Activity activity, View view, Bitmap bmp) { final Dialog imageDialog = new Dialog(activity); imageDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); imageDialog.setContentView(R.layout.showimage); imageDialog.setCancelable(true);//from w w w . jav a 2 s .com ImageView imageView = (ImageView) imageDialog.findViewById(R.id.imageView); // Getting width & height of the given image. DisplayMetrics displayMetrics = activity.getResources().getDisplayMetrics(); int wn = displayMetrics.widthPixels; int hn = displayMetrics.heightPixels; int wo = bmp.getWidth(); int ho = bmp.getHeight(); Matrix mtx = new Matrix(); // Setting rotate to 90 mtx.preRotate(90); // Setting resize mtx.postScale(((float) 1.3 * wn) / ho, ((float) 1.3 * hn) / wo); // Rotating Bitmap Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, wo, ho, mtx, true); BitmapDrawable bmd = new BitmapDrawable(rotatedBMP); imageView.setImageDrawable(bmd); imageView.setOnClickListener(new View.OnClickListener() { public void onClick(View button) { imageDialog.dismiss(); } }); imageDialog.show(); }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.PictureObj.java
public static DbObject from(Context context, Uri imageUri) throws IOException { // Query gallery for camera picture via // Android ContentResolver interface ContentResolver cr = context.getContentResolver(); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;//from www .ja va 2 s .c o m BitmapFactory.decodeStream(cr.openInputStream(imageUri), null, options); int targetSize = 200; int xScale = (options.outWidth + targetSize - 1) / targetSize; int yScale = (options.outHeight + targetSize - 1) / targetSize; int scale = xScale < yScale ? xScale : yScale; //uncomment this to get faster power of two scaling //for(int i = 0; i < 32; ++i) { // int mushed = scale & ~(1 << i); // if(mushed != 0) // scale = mushed; //} options.inJustDecodeBounds = false; options.inSampleSize = scale; Bitmap sourceBitmap = BitmapFactory.decodeStream(cr.openInputStream(imageUri), null, options); int width = sourceBitmap.getWidth(); int height = sourceBitmap.getHeight(); int cropSize = Math.min(width, height); float scaleSize = ((float) targetSize) / cropSize; Matrix matrix = new Matrix(); matrix.postScale(scaleSize, scaleSize); float rotation = PhotoTaker.rotationForImage(context, imageUri); if (rotation != 0f) { matrix.preRotate(rotation); } Bitmap resizedBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, width, height, matrix, true); ByteArrayOutputStream baos = new ByteArrayOutputStream(); resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 90, baos); byte[] data = baos.toByteArray(); sourceBitmap.recycle(); sourceBitmap = null; resizedBitmap.recycle(); resizedBitmap = null; System.gc(); // TODO: gross. JSONObject base = new JSONObject(); if (ContentCorral.CONTENT_CORRAL_ENABLED) { try { String type = cr.getType(imageUri); if (type == null) { type = "image/jpeg"; } base.put(CorralClient.OBJ_LOCAL_URI, imageUri.toString()); base.put(CorralClient.OBJ_MIME_TYPE, type); String localIp = ContentCorral.getLocalIpAddress(); if (localIp != null) { base.put(Contact.ATTR_LAN_IP, localIp); } } catch (JSONException e) { Log.e(TAG, "impossible json error possible!"); } } return from(base, data); }