1 |
package com.caddi.android.caddipictureupload.util; |
2 |
|
3 |
import android.graphics.Bitmap; |
4 |
import android.graphics.Matrix; |
5 |
|
6 |
/** |
7 |
* Created by torben on 7/26/15. |
8 |
*/ |
9 |
public class PictureUtil { |
10 |
public static Bitmap rotateImage(Bitmap input, int degrees) { |
11 |
Matrix matrix = new Matrix(); |
12 |
matrix.postRotate(degrees); |
13 |
|
14 |
return Bitmap.createBitmap(input, 0, 0, input.getWidth(), input.getHeight(), matrix, true); |
15 |
} |
16 |
|
17 |
public static Bitmap clipCenter(Bitmap input) { |
18 |
int w = input.getWidth(); |
19 |
int h = input.getHeight(); |
20 |
|
21 |
if ( w == h) { |
22 |
return input; |
23 |
} |
24 |
|
25 |
if ( h > w) { //portrait |
26 |
int diff = h - w; |
27 |
int diff2 = diff / 2; |
28 |
|
29 |
return Bitmap.createBitmap(input, 0, diff2, w, w); |
30 |
} else { // landscape |
31 |
int diff = w - h; |
32 |
int diff2 = diff / 2; |
33 |
|
34 |
return Bitmap.createBitmap(input, diff2, 0, h, h); |
35 |
} |
36 |
|
37 |
} |
38 |
|
39 |
} |