|
@@ -5,7 +5,10 @@ |
5 |
5 |
|
import android.graphics.Bitmap; |
6 |
6 |
|
import android.graphics.BitmapFactory; |
7 |
7 |
|
import android.graphics.Canvas; |
|
8 |
+ |
import android.graphics.Matrix; |
8 |
9 |
|
import android.graphics.Paint; |
|
10 |
+ |
import android.graphics.drawable.GradientDrawable; |
|
11 |
+ |
import android.media.ExifInterface; |
9 |
12 |
|
import android.net.ConnectivityManager; |
10 |
13 |
|
import android.net.NetworkInfo; |
11 |
14 |
|
import android.net.Uri; |
|
@@ -126,9 +129,11 @@ |
126 |
129 |
|
} |
127 |
130 |
|
} |
128 |
131 |
|
|
129 |
|
- |
|
130 |
132 |
|
public static Bitmap decodeBitmapFromStreamFixed(InputStream inputStream, int reqWidth, int reqHeight) { |
|
133 |
+ |
return decodeBitmapFromStreamFixed(inputStream, reqWidth, reqHeight, null); |
|
134 |
+ |
} |
131 |
135 |
|
|
|
136 |
+ |
public static Bitmap decodeBitmapFromStreamFixed(InputStream inputStream, int reqWidth, int reqHeight, String path){ |
132 |
137 |
|
byte[] byteArr = new byte[0]; |
133 |
138 |
|
byte[] buffer = new byte[1024]; |
134 |
139 |
|
int len; |
|
@@ -159,7 +164,12 @@ |
159 |
164 |
|
options.inJustDecodeBounds = false; |
160 |
165 |
|
options.inPreferredConfig = Bitmap.Config.ARGB_8888; |
161 |
166 |
|
|
162 |
|
- |
return BitmapFactory.decodeByteArray(byteArr, 0, count, options); |
|
167 |
+ |
Bitmap finalBitmap = BitmapFactory.decodeByteArray(byteArr, 0, count, options); |
|
168 |
+ |
|
|
169 |
+ |
if(path==null) |
|
170 |
+ |
return finalBitmap; |
|
171 |
+ |
|
|
172 |
+ |
return rotateBitmap(finalBitmap, path); |
163 |
173 |
|
|
164 |
174 |
|
} catch (Exception e) { |
165 |
175 |
|
e.printStackTrace(); |
|
@@ -167,6 +177,64 @@ |
167 |
177 |
|
return null; |
168 |
178 |
|
} |
169 |
179 |
|
} |
|
180 |
+ |
|
|
181 |
+ |
private static Bitmap rotateBitmap(Bitmap finalBitmap, String path) { |
|
182 |
+ |
ExifInterface exif = null; |
|
183 |
+ |
try { |
|
184 |
+ |
exif = new ExifInterface(path); |
|
185 |
+ |
} catch (IOException e) { |
|
186 |
+ |
e.printStackTrace(); |
|
187 |
+ |
} |
|
188 |
+ |
int orientation; |
|
189 |
+ |
try { |
|
190 |
+ |
orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); |
|
191 |
+ |
} catch (NullPointerException e) { |
|
192 |
+ |
e.printStackTrace(); |
|
193 |
+ |
return finalBitmap; |
|
194 |
+ |
} |
|
195 |
+ |
|
|
196 |
+ |
Matrix matrix = new Matrix(); |
|
197 |
+ |
switch (orientation) { |
|
198 |
+ |
case ExifInterface.ORIENTATION_NORMAL: |
|
199 |
+ |
return finalBitmap; |
|
200 |
+ |
case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: |
|
201 |
+ |
matrix.setScale(-1, 1); |
|
202 |
+ |
break; |
|
203 |
+ |
case ExifInterface.ORIENTATION_ROTATE_180: |
|
204 |
+ |
matrix.setRotate(180); |
|
205 |
+ |
break; |
|
206 |
+ |
case ExifInterface.ORIENTATION_FLIP_VERTICAL: |
|
207 |
+ |
matrix.setRotate(180); |
|
208 |
+ |
matrix.postScale(-1, 1); |
|
209 |
+ |
break; |
|
210 |
+ |
case ExifInterface.ORIENTATION_TRANSPOSE: |
|
211 |
+ |
matrix.setRotate(90); |
|
212 |
+ |
matrix.postScale(-1, 1); |
|
213 |
+ |
break; |
|
214 |
+ |
case ExifInterface.ORIENTATION_ROTATE_90: |
|
215 |
+ |
matrix.setRotate(90); |
|
216 |
+ |
break; |
|
217 |
+ |
case ExifInterface.ORIENTATION_TRANSVERSE: |
|
218 |
+ |
matrix.setRotate(-90); |
|
219 |
+ |
matrix.postScale(-1, 1); |
|
220 |
+ |
break; |
|
221 |
+ |
case ExifInterface.ORIENTATION_ROTATE_270: |
|
222 |
+ |
matrix.setRotate(-90); |
|
223 |
+ |
break; |
|
224 |
+ |
default: |
|
225 |
+ |
return finalBitmap; |
|
226 |
+ |
} |
|
227 |
+ |
try { |
|
228 |
+ |
Bitmap bmRotated = |
|
229 |
+ |
Bitmap.createBitmap(finalBitmap, 0, 0, finalBitmap.getWidth(), finalBitmap.getHeight(), matrix, true); |
|
230 |
+ |
finalBitmap.recycle(); |
|
231 |
+ |
return bmRotated; |
|
232 |
+ |
} |
|
233 |
+ |
catch (OutOfMemoryError e) { |
|
234 |
+ |
e.printStackTrace(); |
|
235 |
+ |
return null; |
|
236 |
+ |
} |
|
237 |
+ |
} |
170 |
238 |
|
|
171 |
239 |
|
|
172 |
240 |
|
public static Bitmap mergeBitmaps(Bitmap original, Bitmap overlay) { |