List of usage examples for java.lang OutOfMemoryError printStackTrace
public void printStackTrace()
From source file:Main.java
public static Bitmap getDesirableBitmap(String imgPath, int desiredSize) { try {/* www. java 2 s. c o m*/ int scale = getDesirableBitmapSampleSize(imgPath, desiredSize); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = scale; Bitmap originalBitmap = BitmapFactory.decodeFile(imgPath, options); int rotation = getExifOrientation(imgPath); if (rotation != 0) { Matrix matrix = new Matrix(); matrix.postRotate(rotation); Bitmap exifBitmap = Bitmap.createBitmap(originalBitmap, 0, 0, originalBitmap.getWidth(), originalBitmap.getHeight(), matrix, true); originalBitmap.recycle(); return exifBitmap; } return originalBitmap; } catch (Exception ex) { ex.printStackTrace(); //TODO: Handle } catch (OutOfMemoryError e) { e.printStackTrace(); //Hmmm...what to do... } return null; }
From source file:Main.java
public static Bitmap getRotatedBitmap(Bitmap bitmap, int degrees) { if (degrees != 0 && bitmap != null) { Matrix m = new Matrix(); m.setRotate(degrees, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2); try {//from ww w . j a v a 2s . c om Bitmap b2 = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true); if (bitmap != b2) { bitmap.recycle(); bitmap = b2; } } catch (OutOfMemoryError ex) { // TODO Auto-generated catch block ex.printStackTrace(); } } return bitmap; }
From source file:Main.java
public static Bitmap getRotatedBitmap(Bitmap bitmap, int degrees) { if (degrees != 0 && bitmap != null) { Matrix m = new Matrix(); m.setRotate(degrees, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2); try {//from w w w .j a va2 s. c o m Bitmap b2 = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true); if (bitmap.equals(b2)) { bitmap.recycle(); bitmap = b2; } } catch (OutOfMemoryError ex) { // TODO Auto-generated catch block ex.printStackTrace(); } } return bitmap; }
From source file:Main.java
public static Bitmap rotateBitmap(String src, Bitmap bitmap) { try {//from ww w .j av a2s .c o m int orientation = getExifOrientation(src); if (orientation == 1) { return bitmap; } Matrix matrix = new Matrix(); switch (orientation) { case 2: matrix.setScale(-1, 1); break; case 3: matrix.setRotate(180); break; case 4: matrix.setRotate(180); matrix.postScale(-1, 1); break; case 5: matrix.setRotate(90); matrix.postScale(-1, 1); break; case 6: matrix.setRotate(90); break; case 7: matrix.setRotate(-90); matrix.postScale(-1, 1); break; case 8: matrix.setRotate(-90); break; default: return bitmap; } try { Bitmap oriented = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); bitmap.recycle(); return oriented; } catch (OutOfMemoryError e) { e.printStackTrace(); return bitmap; } } catch (IOException e) { e.printStackTrace(); } return bitmap; }
From source file:Main.java
public static Bitmap getImageBitmapFromAssetsFolderThroughImagePathName(Context context, String imagePathName, int reqWidth, int reqHeight) { BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true;/*from w ww .j a v a 2s . c o m*/ Bitmap bitmap = null; AssetManager assetManager = context.getResources().getAssets(); InputStream inputStream = null; try { inputStream = assetManager.open(imagePathName); inputStream.mark(Integer.MAX_VALUE); } catch (IOException e) { e.printStackTrace(); return null; } catch (OutOfMemoryError e) { e.printStackTrace(); System.gc(); return null; } try { if (inputStream != null) { BitmapFactory.decodeStream(inputStream, null, opts); inputStream.reset(); } else { return null; } } catch (OutOfMemoryError e) { e.printStackTrace(); System.gc(); return null; } catch (Exception e) { e.printStackTrace(); return null; } opts.inSampleSize = calculateInSampleSiez(opts, reqWidth, reqHeight); // Log.d(TAG,""+opts.inSampleSize); opts.inJustDecodeBounds = false; opts.inPreferredConfig = Bitmap.Config.RGB_565; opts.inPurgeable = true; opts.inInputShareable = true; opts.inDither = false; opts.inTempStorage = new byte[512 * 1024]; try { if (inputStream != null) { bitmap = BitmapFactory.decodeStream(inputStream, null, opts); } else { return null; } } catch (OutOfMemoryError e) { e.printStackTrace(); System.gc(); return null; } catch (Exception e) { e.printStackTrace(); return null; } finally { if (inputStream != null) { try { inputStream.close(); } catch (Exception e) { e.printStackTrace(); return null; } } } //Log.d(TAG,"w:"+bitmap.getWidth()+" h:"+bitmap.getHeight()); if (bitmap != null) { try { bitmap = Bitmap.createScaledBitmap(bitmap, reqWidth, reqHeight, true); } catch (OutOfMemoryError outOfMemoryError) { outOfMemoryError.printStackTrace(); System.gc(); return null; } } return bitmap; }
From source file:Main.java
private static Bitmap stackblur(Bitmap sentBitmap, int radius) { Bitmap bitmap = null;/* www . j a v a2s. com*/ try { bitmap = sentBitmap.copy(sentBitmap.getConfig(), true); } catch (OutOfMemoryError e) { e.printStackTrace(); return sentBitmap; } if (radius < 1) { return (null); } int w = bitmap.getWidth(); int h = bitmap.getHeight(); int[] pix = new int[w * h]; bitmap.getPixels(pix, 0, w, 0, 0, w, h); int wm = w - 1; int hm = h - 1; int wh = w * h; int div = radius + radius + 1; int r[] = new int[wh]; int g[] = new int[wh]; int b[] = new int[wh]; int rsum, gsum, bsum, x, y, i, p, yp, yi, yw; int vmin[] = new int[Math.max(w, h)]; int divsum = (div + 1) >> 1; divsum *= divsum; int dv[] = new int[256 * divsum]; for (i = 0; i < 256 * divsum; i++) { dv[i] = (i / divsum); } yw = yi = 0; int[][] stack = new int[div][3]; int stackpointer; int stackstart; int[] sir; int rbs; int r1 = radius + 1; int routsum, goutsum, boutsum; int rinsum, ginsum, binsum; for (y = 0; y < h; y++) { rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0; for (i = -radius; i <= radius; i++) { p = pix[yi + Math.min(wm, Math.max(i, 0))]; sir = stack[i + radius]; sir[0] = (p & 0xff0000) >> 16; sir[1] = (p & 0x00ff00) >> 8; sir[2] = (p & 0x0000ff); rbs = r1 - Math.abs(i); rsum += sir[0] * rbs; gsum += sir[1] * rbs; bsum += sir[2] * rbs; if (i > 0) { rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; } else { routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; } } stackpointer = radius; for (x = 0; x < w; x++) { r[yi] = dv[rsum]; g[yi] = dv[gsum]; b[yi] = dv[bsum]; rsum -= routsum; gsum -= goutsum; bsum -= boutsum; stackstart = stackpointer - radius + div; sir = stack[stackstart % div]; routsum -= sir[0]; goutsum -= sir[1]; boutsum -= sir[2]; if (y == 0) { vmin[x] = Math.min(x + radius + 1, wm); } p = pix[yw + vmin[x]]; sir[0] = (p & 0xff0000) >> 16; sir[1] = (p & 0x00ff00) >> 8; sir[2] = (p & 0x0000ff); rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; rsum += rinsum; gsum += ginsum; bsum += binsum; stackpointer = (stackpointer + 1) % div; sir = stack[(stackpointer) % div]; routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; rinsum -= sir[0]; ginsum -= sir[1]; binsum -= sir[2]; yi++; } yw += w; } for (x = 0; x < w; x++) { rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0; yp = -radius * w; for (i = -radius; i <= radius; i++) { yi = Math.max(0, yp) + x; sir = stack[i + radius]; sir[0] = r[yi]; sir[1] = g[yi]; sir[2] = b[yi]; rbs = r1 - Math.abs(i); rsum += r[yi] * rbs; gsum += g[yi] * rbs; bsum += b[yi] * rbs; if (i > 0) { rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; } else { routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; } if (i < hm) { yp += w; } } yi = x; stackpointer = radius; for (y = 0; y < h; y++) { // Preserve alpha channel: ( 0xff000000 & pix[yi] ) pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum]; rsum -= routsum; gsum -= goutsum; bsum -= boutsum; stackstart = stackpointer - radius + div; sir = stack[stackstart % div]; routsum -= sir[0]; goutsum -= sir[1]; boutsum -= sir[2]; if (x == 0) { vmin[y] = Math.min(y + r1, hm) * w; } p = x + vmin[y]; sir[0] = r[p]; sir[1] = g[p]; sir[2] = b[p]; rinsum += sir[0]; ginsum += sir[1]; binsum += sir[2]; rsum += rinsum; gsum += ginsum; bsum += binsum; stackpointer = (stackpointer + 1) % div; sir = stack[stackpointer]; routsum += sir[0]; goutsum += sir[1]; boutsum += sir[2]; rinsum -= sir[0]; ginsum -= sir[1]; binsum -= sir[2]; yi += w; } } bitmap.setPixels(pix, 0, w, 0, 0, w, h); return (bitmap); }
From source file:com.nextgis.maplibui.util.ControlHelper.java
public static Bitmap getBitmap(InputStream is, BitmapFactory.Options options) { Bitmap result = null;/* ww w . j a v a 2 s . c om*/ if (is == null) return null; try { result = BitmapFactory.decodeStream(is, null, options); } catch (OutOfMemoryError oom) { oom.printStackTrace(); try { options.inSampleSize *= 4; result = BitmapFactory.decodeStream(is, null, options); } catch (OutOfMemoryError oom1) { oom1.printStackTrace(); } } try { is.close(); } catch (IOException e) { e.printStackTrace(); } return result; }
From source file:com.daiv.android.twitter.services.SendTweet.java
public static Bitmap rotateBitmap(Bitmap bitmap, int orientation) { Log.v("Test_composing_image", "rotation: " + orientation); try {/*from w w w . ja va 2s. c om*/ Matrix matrix = new Matrix(); switch (orientation) { case ExifInterface.ORIENTATION_NORMAL: return bitmap; case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: matrix.setScale(-1, 1); break; case ExifInterface.ORIENTATION_ROTATE_180: matrix.setRotate(180); break; case ExifInterface.ORIENTATION_FLIP_VERTICAL: matrix.setRotate(180); matrix.postScale(-1, 1); break; case ExifInterface.ORIENTATION_TRANSPOSE: matrix.setRotate(90); matrix.postScale(-1, 1); break; case ExifInterface.ORIENTATION_ROTATE_90: matrix.setRotate(90); break; case ExifInterface.ORIENTATION_TRANSVERSE: matrix.setRotate(-90); matrix.postScale(-1, 1); break; case ExifInterface.ORIENTATION_ROTATE_270: matrix.setRotate(-90); break; default: return bitmap; } try { Bitmap bmRotated = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); bitmap.recycle(); return bmRotated; } catch (OutOfMemoryError e) { e.printStackTrace(); return null; } } catch (Exception e) { e.printStackTrace(); } return bitmap; }
From source file:FacebookImageLoader.java
public static Bitmap processImageFromBitmap(final Bitmap bitmap, final int maxDimension) { // Check input if (bitmap == null) { return null; }/* w ww . j a v a2 s.c o m*/ // Calculate the resize ratio. Make the longest side // somewhere in the vicinity of 'maxDimension' pixels. int maxSide = Math.max(bitmap.getWidth(), bitmap.getHeight()); float newWidth = bitmap.getWidth(); float newHeight = bitmap.getHeight(); float ratio = 0; if (maxSide > maxDimension) { ratio = (float) maxDimension / (float) maxSide; newWidth *= ratio; newHeight *= ratio; } try { return Bitmap.createScaledBitmap(bitmap, Math.round(newWidth), Math.round(newHeight), false); } catch (OutOfMemoryError e) { e.printStackTrace(); return null; } }
From source file:io.jari.geenstijl.API.API.java
/** * setCache saves the article array to the cache. * Expires in 30 mins.//from ww w. ja va 2 s . c om */ private static void setCache(Artikel[] artikels, Context context) { try { SharedPreferences preferences = context.getSharedPreferences("geenstijl", 0); preferences.edit().putString("items", SerializeObject.objectToString(artikels)) .putLong("items_age", Calendar.getInstance().getTimeInMillis()).commit(); } catch (OutOfMemoryError kutTelefoon) { kutTelefoon.printStackTrace(); Log.e(TAG, "Unable to cache data due to memory errors (get a better phone!), App will download data every time it starts."); } }