List of usage examples for android.graphics BitmapFactory decodeByteArray
public static Bitmap decodeByteArray(byte[] data, int offset, int length, Options opts)
From source file:com.modestmaps.providers.connection.TileBaseHelper.java
public Bitmap getTile(String tileQ) throws OutOfMemoryError { //bmg.recycle(); byte[] tile = { -119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 1, 0, 0, 0, 1, 0, 8, 3, 0, 0, 0, 107, -84, 88, 84, 0, 0, 0, 25, 116, 69, 88, 116, 83, 111, 102, 116, 119, 97, 114, 101, 0, 65, 100, 111, 98, 101, 32, 73, 109, 97, 103, 101, 82, 101, 97, 100, 121, 113, -55, 101, 60, 0, 0, 3, 32, 105, 84, 88, 116, 88, 77, 76, 58, 99, 111, 109, 46, 97, 100, 111, 98, 101, 46, 120, 109, 112, 0, 0, 0, 0, 0, 60, 63, 120, 112, 97, 99, 107, 101, 116, 32, 98, 101, 103, 105, 110, 61, 34, -17, -69, -65, 34, 32, 105, 100, 61, 34, 87, 53, 77, 48, 77, 112, 67, 101, 104, 105, 72, 122, 114, 101, 83, 122, 78, 84, 99, 122, 107, 99, 57, 100, 34, 63, 62, 32, 60, 120, 58, 120, 109, 112, 109, 101, 116, 97, 32, 120, 109, 108, 110, 115, 58, 120, 61, 34, 97, 100, 111, 98, 101, 58, 110, 115, 58, 109, 101, 116, 97, 47, 34, 32, 120, 58, 120, 109, 112, 116, 107, 61, 34, 65, 100, 111, 98, 101, 32, 88, 77, 80, 32, 67, 111, 114, 101, 32, 53, 46, 48, 45, 99, 48, 54, 48, 32, 54, 49, 46, 49, 51, 52, 55, 55, 55, 44, 32, 50, 48, 49, 48, 47, 48, 50, 47, 49, 50, 45, 49, 55, 58, 51, 50, 58, 48, 48, 32, 32, 32, 32, 32, 32, 32, 32, 34, 62, 32, 60, 114, 100, 102, 58, 82, 68, 70, 32, 120, 109, 108, 110, 115, 58, 114, 100, 102, 61, 34, 104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 119, 51, 46, 111, 114, 103, 47, 49, 57, 57, 57, 47, 48, 50, 47, 50, 50, 45, 114, 100, 102, 45, 115, 121, 110, 116, 97, 120, 45, 110, 115, 35, 34, 62, 32, 60, 114, 100, 102, 58, 68, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 32, 114, 100, 102, 58, 97, 98, 111, 117, 116, 61, 34, 34, 32, 120, 109, 108, 110, 115, 58, 120, 109, 112, 61, 34, 104, 116, 116, 112, 58, 47, 47, 110, 115, 46, 97, 100, 111, 98, 101, 46, 99, 111, 109, 47, 120, 97, 112, 47, 49, 46, 48, 47, 34, 32, 120, 109, 108, 110, 115, 58, 120, 109, 112, 77, 77, 61, 34, 104, 116, 116, 112, 58, 47, 47, 110, 115, 46, 97, 100, 111, 98, 101, 46, 99, 111, 109, 47, 120, 97, 112, 47, 49, 46, 48, 47, 109, 109, 47, 34, 32, 120, 109, 108, 110, 115, 58, 115, 116, 82, 101, 102, 61, 34, 104, 116, 116, 112, 58, 47, 47, 110, 115, 46, 97, 100, 111, 98, 101, 46, 99, 111, 109, 47, 120, 97, 112, 47, 49, 46, 48, 47, 115, 84, 121, 112, 101, 47, 82, 101, 115, 111, 117, 114, 99, 101, 82, 101, 102, 35, 34, 32, 120, 109, 112, 58, 67, 114, 101, 97, 116, 111, 114, 84, 111, 111, 108, 61, 34, 65, 100, 111, 98, 101, 32, 80, 104, 111, 116, 111, 115, 104, 111, 112, 32, 67, 83, 53, 32, 87, 105, 110, 100, 111, 119, 115, 34, 32, 120, 109, 112, 77, 77, 58, 73, 110, 115, 116, 97, 110, 99, 101, 73, 68, 61, 34, 120, 109, 112, 46, 105, 105, 100, 58, 70, 49, 69, 65, 51, 53, 51, 69, 56, 54, 55, 68, 49, 49, 69, 51, 66, 48, 57, 48, 68, 49, 48, 56, 50, 49, 57, 67, 67, 68, 56, 50, 34, 32, 120, 109, 112, 77, 77, 58, 68, 111, 99, 117, 109, 101, 110, 116, 73, 68, 61, 34, 120, 109, 112, 46, 100, 105, 100, 58, 70, 49, 69, 65, 51, 53, 51, 70, 56, 54, 55, 68, 49, 49, 69, 51, 66, 48, 57, 48, 68, 49, 48, 56, 50, 49, 57, 67, 67, 68, 56, 50, 34, 62, 32, 60, 120, 109, 112, 77, 77, 58, 68, 101, 114, 105, 118, 101, 100, 70, 114, 111, 109, 32, 115, 116, 82, 101, 102, 58, 105, 110, 115, 116, 97, 110, 99, 101, 73, 68, 61, 34, 120, 109, 112, 46, 105, 105, 100, 58, 70, 49, 69, 65, 51, 53, 51, 67, 56, 54, 55, 68, 49, 49, 69, 51, 66, 48, 57, 48, 68, 49, 48, 56, 50, 49, 57, 67, 67, 68, 56, 50, 34, 32, 115, 116, 82, 101, 102, 58, 100, 111, 99, 117, 109, 101, 110, 116, 73, 68, 61, 34, 120, 109, 112, 46, 100, 105, 100, 58, 70, 49, 69, 65, 51, 53, 51, 68, 56, 54, 55, 68, 49, 49, 69, 51, 66, 48, 57, 48, 68, 49, 48, 56, 50, 49, 57, 67, 67, 68, 56, 50, 34, 47, 62, 32, 60, 47, 114, 100, 102, 58, 68, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 62, 32, 60, 47, 114, 100, 102, 58, 82, 68, 70, 62, 32, 60, 47, 120, 58, 120, 109, 112, 109, 101, 116, 97, 62, 32, 60, 63, 120, 112, 97, 99, 107, 101, 116, 32, 101, 110, 100, 61, 34, 114, 34, 63, 62, -55, 39, 49, -69, 0, 0, 0, 18, 80, 76, 84, 69, -52, -52, -52, 102, 102, 102, -103, -103, -103, 51, 51, 51, 0, 0, 0, 75, 75, 75, -112, 33, 7, 1, 0, 0, 4, -76, 73, 68, 65, 84, 120, -38, -20, -101, -19, -126, -85, 42, 12, 69, 77, -128, -9, 127, -27, 91, 69, -27, 43, 80, -67, -75, -75, 61, -77, -42, -113, 25, -37, 42, -122, 45, 4, -48, -19, 52, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -64, 105, -44, 123, -1, -93, -95, 63, 34, 119, -27, -57, -109, 21, -41, -33, 23, -64, -53, -1, 22, -64, -81, -5, -1, -72, 0, -2, -49, 11, 32, -89, 4, -112, 16, -37, -3, -75, 93, 32, 43, -11, -61, 2, 56, -105, 5, 127, -92, 34, -34, 55, -95, 94, 32, -128, 81, -22, -89, 4, -112, 44, 15, -2, 69, 1, 124, 126, -18, -65, 41, -128, -92, -16, -77, -118, -120, -101, -121, -56, 80, 69, -27, -4, -122, -53, 42, -82, -51, 113, -39, -56, 18, -26, 47, -126, 52, 93, 62, -37, -83, 44, -11, -29, 2, -52, -25, -105, 74, 0, -39, 67, 10, -89, 4, 72, -57, 105, -11, 69, -82, -92, 84, 21, -66, 91, -128, 20, -1, -74, -79, 68, 40, 18, -81, 102, 113, -27, 68, -106, -21, -7, -64, 18, 96, -7, 81, 117, 57, 110, -17, 28, -113, -67, 67, -39, 69, -26, -76, 35, -53, -73, -79, -12, -78, -44, -49, 11, 48, -123, -19, 66, 103, 21, -110, 84, -127, 110, 111, -83, 5, -48, -3, -73, 45, -77, -122, -67, -96, -78, 7, -92, -29, -11, -2, 28, -112, -99, 62, 125, -108, -84, -75, -22, 81, 1, -78, -97, 92, -36, 124, -110, 29, 101, -105, -9, 102, 1, 36, -43, 32, -5, -76, -43, 36, 28, 20, 64, -77, 93, 53, 106, -8, 68, 0, -35, 123, -40, -51, 2, 108, -41, 124, -17, 17, 82, 36, -84, -125, 2, 72, 94, -119, 88, -75, 71, 81, 78, 15, -100, -1, 118, 1, -42, 106, -58, -65, 110, -72, 64, -22, 11, 48, 55, -5, -99, -67, 81, -52, 105, -47, -100, -5, -82, -71, -1, 59, 4, 88, 91, -6, 46, -125, -10, -89, 40, 125, 1, 124, 69, 90, 109, -44, -107, -45, 80, -19, 117, -65, 0, -79, 14, 111, 16, 96, 29, -12, -61, 84, -49, 3, -126, -20, -19, -28, 27, 4, -120, 67, -95, -77, 5, -104, 14, 11, 96, -89, 58, 87, -34, 117, 72, -93, -20, -12, 69, 2, 44, -101, -82, -100, 22, -100, 76, -126, -82, 91, -119, 80, -52, -89, -78, 36, -5, 77, 2, -52, 99, -78, 123, 105, 24, -108, -30, 58, -9, -50, 51, -103, -85, -81, 47, 16, 96, -82, -86, -37, -89, 3, -95, -41, 0, -14, 89, -46, 96, 34, 116, 76, 0, -55, 5, -112, -69, 5, -48, 61, 115, -55, -82, -128, -76, -127, -71, -44, -100, 107, 1, 66, -77, -73, -42, 51, -66, -94, 67, -120, -49, 71, 33, 119, -73, 0, 75, -4, 62, 109, -83, -117, -95, -48, 78, 95, -25, -5, 72, -26, 98, -56, -7, 109, 81, 19, -30, 113, -15, -109, 43, -101, -122, -82, -91, -5, -67, -55, 21, -91, -34, 39, -64, -28, -115, 101, 109, 27, -110, -37, -65, 31, 45, -121, -45, 60, -88, 45, 102, -37, -53, 105, -70, 31, -25, 58, 103, -5, -88, 0, 50, -70, -79, 81, -59, 47, -93, 27, 34, -34, -83, 119, 64, 52, -104, -59, 44, 19, -95, 121, -105, 108, -10, 44, -2, -82, 60, 0, 0, 0, 0, 0, 0, 0, 0, -16, 111, 115, -34, -50, -13, -61, 38, -64, -93, -43, -47, -31, 61, -7, -53, 4, -48, -77, -73, -2, 55, -1, -124, 94, -7, -48, -64, -86, -114, 31, 86, -15, 50, 1, -4, -39, -126, 16, -32, 50, 1, 74, 119, -21, 103, -69, 64, 58, -9, -23, 46, -112, -37, 55, 94, -42, 94, -17, 74, -126, -81, 92, 61, 4, 64, -128, 43, 4, -80, -52, -99, 90, 60, -58, -52, -86, 104, -8, 90, -11, -119, 127, 118, 123, -8, -93, 91, -105, -17, 121, 96, 11, 37, -21, -110, -94, -85, 108, 62, -38, -55, -5, 5, 8, -123, -121, -91, 52, 122, 54, -106, 30, 29, -6, 103, -43, -27, -33, 13, 61, -80, -103, 0, 109, 73, -117, 0, -82, -116, -21, 34, 1, 90, 119, -85, -60, -73, 4, 42, 127, 80, -49, -41, -86, 35, -1, -84, 108, -113, -125, 99, -82, 31, 122, 96, 43, 37, -53, -110, 102, 1, 102, 47, 70, 124, -76, -8, -26, 28, -80, 6, 87, -8, 97, -105, -10, 111, -6, 90, 117, -32, -97, 109, -100, -76, 35, 15, -84, -26, 6, 98, -85, -92, -72, 41, -83, -125, -24, 106, 1, 86, -47, 119, -97, -126, 22, 62, -47, 94, 18, -84, -100, 33, -101, -75, -42, -74, 53, 88, 30, 88, -83, 92, -103, 69, 73, 86, 92, 111, 19, -64, -70, 34, 79, 5, -80, -116, 67, -3, 1, -62, -14, -64, 106, -27, -53, -51, 75, 50, -29, 122, -4, -24, -118, -1, 87, 15, -125, -66, 122, -25, -55, -10, -75, 106, -33, 63, 27, 90, -1, 72, -99, -65, 12, 1, 76, 39, -82, 21, -41, -57, 5, -80, 125, -83, -38, -9, -49, 58, -53, -47, -48, -11, -64, 110, -89, 49, -99, -72, 95, 33, -64, -26, 104, 81, 75, 0, -53, 62, 122, -50, 3, 107, 123, -55, -78, 5, -49, -3, 2, -104, -66, -42, 51, 2, 12, 61, -80, 63, 33, 64, -21, 107, -19, 10, 48, -75, -26, -66, -79, 7, -74, 43, 64, -73, 11, 108, -81, -48, -68, -4, 42, -51, 25, 1, 106, 95, 107, -106, 4, 27, -1, 108, -19, 34, 29, 123, 96, -77, 36, 24, -114, 37, -63, -53, 56, 39, 64, 53, 28, 14, -122, 65, 105, 15, -44, -25, 2, 116, -121, -63, -73, 10, 32, -81, 10, 96, -6, 103, -85, 124, 49, -10, -64, -86, 113, -108, -44, 115, -111, -86, 11, 76, -59, -1, 87, -42, 67, -18, -56, 48, 88, -49, -30, -102, 11, 87, -5, 103, -59, -97, -16, -64, -106, 47, -41, 77, -10, 116, 60, -113, 75, -46, -92, -3, -59, 36, 104, -72, 91, 45, 1, 76, 95, 107, 58, -62, -14, -49, -122, 98, 49, 52, -10, -64, -90, 83, 27, 37, 89, 113, 109, 67, -78, 127, -67, 79, -76, -18, 86, 67, -128, -114, -81, 85, -121, -2, -39, 114, 97, 59, -12, -64, -102, -53, -31, 81, -41, -12, -87, -13, -67, 124, 91, 86, 14, 8, -48, -15, -75, -22, 19, -1, 108, -100, -8, 57, 73, 19, -95, -114, 7, -42, -72, 33, 34, -26, 89, -78, -72, 36, -1, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -65, -59, 127, 2, 12, 0, 35, -109, 40, -115, 21, -105, 28, -78, 0, 0, 0, 0, 73, 69, 78, 68, -82, 66, 96, -126 };/*from w ww . j a va 2 s . c o m*/ System.out.println("byte array tile[] initialized..now loading default nullTile.png.."); System.out.println("nullTile.png loaded as byte array"); System.out.println("tileQ: " + tileQ + " !!"); //TODO: catch if tileQ = null if (tileQ != null) { Cursor cursor = this.tileDB.query(tableName, new String[] { columnName }, tileQ, null, null, null, null); cursor.moveToFirst(); //TODO: this todo note should be movoed to readme.txt: //try to limit the number of tiles pre-loaded into memory by InteractiveMapProvider.. try { tile = cursor.getBlob(0); } catch (Exception e) { System.out.println( "null cursor returned..no such tile found in db..returning nulltile..\n" + e.getMessage()); } cursor.close(); } //ByteArrayInputStream bmgIS = new ByteArrayInputStream(tile); bmg = null; //if(Runtime.getRuntime().freeMemory()>24576){ // try{ bmg = BitmapFactory.decodeByteArray(tile, 0, tile.length, bmgOptions); // }catch(OutOfMemoryError e){ //// p.map = null; // map = null; // bmg.recycle(); // System.out.println("decodeByteArray out of memory..please wait.."); // } tile = null; return bmg; }
From source file:com.android.leanlauncher.WidgetPreviewLoader.java
private Bitmap readFromDb(String name, Bitmap b) { if (mCachedSelectQuery == null) { mCachedSelectQuery = CacheDb.COLUMN_NAME + " = ? AND " + CacheDb.COLUMN_SIZE + " = ?"; }/*from w w w . j a va2 s.c om*/ SQLiteDatabase db = mDb.getReadableDatabase(); Cursor result; try { result = db.query(CacheDb.TABLE_NAME, new String[] { CacheDb.COLUMN_PREVIEW_BITMAP }, // cols to return mCachedSelectQuery, // select query new String[] { name, mSize }, // args to select query null, null, null, null); } catch (SQLiteDiskIOException e) { recreateDb(); return null; } catch (SQLiteCantOpenDatabaseException e) { throw e; } if (result.getCount() > 0) { result.moveToFirst(); byte[] blob = result.getBlob(0); result.close(); final BitmapFactory.Options opts = mCachedBitmapFactoryOptions.get(); opts.inBitmap = b; opts.inSampleSize = 1; try { return BitmapFactory.decodeByteArray(blob, 0, blob.length, opts); } catch (IllegalArgumentException e) { removeItemFromDb(mDb, name); return null; } } else { result.close(); return null; } }
From source file:com.klinker.android.twitter.activities.compose.Compose.java
private Bitmap getThumbnail(Uri uri) throws FileNotFoundException, IOException { InputStream input = getContentResolver().openInputStream(uri); int reqWidth = 150; int reqHeight = 150; byte[] byteArr = new byte[0]; byte[] buffer = new byte[1024]; int len;//from w w w . jav a2s . com int count = 0; try { while ((len = input.read(buffer)) > -1) { if (len != 0) { if (count + len > byteArr.length) { byte[] newbuf = new byte[(count + len) * 2]; System.arraycopy(byteArr, 0, newbuf, 0, count); byteArr = newbuf; } System.arraycopy(buffer, 0, byteArr, count, len); count += len; } } final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeByteArray(byteArr, 0, count, options); options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); options.inPurgeable = true; options.inInputShareable = true; options.inJustDecodeBounds = false; options.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap b = BitmapFactory.decodeByteArray(byteArr, 0, count, options); ExifInterface exif = new ExifInterface(IOUtils.getPath(uri, context)); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); b = ImageUtils.cropSquare(b); return rotateBitmap(b, orientation); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.daiv.android.twitter.ui.compose.Compose.java
private Bitmap getThumbnail(Uri uri) throws IOException { InputStream input = getContentResolver().openInputStream(uri); int reqWidth = 150; int reqHeight = 150; byte[] byteArr = new byte[0]; byte[] buffer = new byte[1024]; int len;/*from w w w. jav a 2 s . co m*/ int count = 0; try { while ((len = input.read(buffer)) > -1) { if (len != 0) { if (count + len > byteArr.length) { byte[] newbuf = new byte[(count + len) * 2]; System.arraycopy(byteArr, 0, newbuf, 0, count); byteArr = newbuf; } System.arraycopy(buffer, 0, byteArr, count, len); count += len; } } final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeByteArray(byteArr, 0, count, options); options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); options.inPurgeable = true; options.inInputShareable = true; options.inJustDecodeBounds = false; options.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap b = BitmapFactory.decodeByteArray(byteArr, 0, count, options); ExifInterface exif = new ExifInterface(IOUtils.getPath(uri, context)); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); b = ImageUtils.cropSquare(b); return rotateBitmap(b, orientation); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.fastbootmobile.encore.art.AlbumArtCache.java
private boolean getArtistArt(final Resources res, final Artist artist, final IAlbumArtCacheListener listener) throws RemoteException { // Try to get the art from the provider first final ProviderIdentifier id = artist.getProvider(); final IMusicProvider binder = safeGetBinder(id); boolean providerprovides = false; boolean result = false; if (binder != null) { providerprovides = result = binder.getArtistArt(artist, new IArtCallback.Stub() { @Override//from w w w . j a va2 s .co m public void onArtLoaded(final Bitmap bitmap) throws RemoteException { new Thread() { public void run() { if (bitmap != null) { RecyclingBitmapDrawable rcb = ImageCache.getDefault().put(res, getEntityArtKey(artist), bitmap); listener.onArtLoaded(artist, rcb); } else { listener.onArtLoaded(artist, null); } } }.start(); } }); } if (!providerprovides) { // Hardcode warning: Image providers tend to return... funny images for empty // names and '<unknown>'. We just don't want images for them then. if (artist.getName() == null || artist.getName().isEmpty() || "<unknown>".equals(artist.getName())) { return false; } // Try to get it first from FreeBase, then from Google Image if none found or error // (Google Images might return some random/unwanted images, so prefer FreeBase first) String url = null; try { url = FreeBaseClient.getArtistImageUrl(artist.getName()); } catch (JSONException e) { Log.e(TAG, "JSON error while getting image from FreeBase"); } catch (RateLimitException e) { Log.w(TAG, "Rate limit hit while getting image from FreeBase"); } catch (IOException e) { Log.e(TAG, "IO error while getting image from FreeBase"); } if (url == null) { try { url = GoogleImagesClient.getImageUrl("Music Band " + artist.getName()); } catch (RateLimitException e) { Log.w(TAG, "Rate limit hit while getting image from Google Images"); } catch (JSONException e) { Log.e(TAG, "JSON Error while getting image from Google Images"); } catch (IOException e) { Log.e(TAG, "IO error while getting image from Google Images (" + e.getMessage() + ")"); } } if (url != null) { try { byte[] imageData = HttpGet.getBytes(url, "", true); BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inMutable = true; Bitmap image = BitmapFactory.decodeByteArray(imageData, 0, imageData.length, opts); if (image != null) { result = true; RecyclingBitmapDrawable rcb = ImageCache.getDefault().put(res, getEntityArtKey(artist), image); listener.onArtLoaded(artist, rcb); } } catch (InterruptedIOException ignore) { } catch (IOException e) { Log.e(TAG, "Failed to download album art image"); } catch (RateLimitException e) { Log.w(TAG, "Rate limited while getting image"); } } else { ImageCache.getDefault().put(res, getEntityArtKey(artist), (RecyclingBitmapDrawable) null); listener.onArtLoaded(artist, null); result = true; } } return result; }
From source file:com.daiv.android.twitter.ui.compose.Compose.java
public Bitmap getBitmapToSend(Uri uri) throws IOException { InputStream input = getContentResolver().openInputStream(uri); int reqWidth = 750; int reqHeight = 750; byte[] byteArr = new byte[0]; byte[] buffer = new byte[1024]; int len;/*w w w . ja v a 2 s . c o m*/ int count = 0; try { while ((len = input.read(buffer)) > -1) { if (len != 0) { if (count + len > byteArr.length) { byte[] newbuf = new byte[(count + len) * 2]; System.arraycopy(byteArr, 0, newbuf, 0, count); byteArr = newbuf; } System.arraycopy(buffer, 0, byteArr, count, len); count += len; } } final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeByteArray(byteArr, 0, count, options); options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); options.inPurgeable = true; options.inInputShareable = true; options.inJustDecodeBounds = false; options.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap b = BitmapFactory.decodeByteArray(byteArr, 0, count, options); ExifInterface exif = new ExifInterface(IOUtils.getPath(uri, context)); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); input.close(); return rotateBitmap(b, orientation); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.eleybourn.bookcatalogue.utils.Utils.java
/** * Given byte array that represents an image (jpg, png etc), return as a bitmap. * /*from w w w .jav a 2s.c om*/ * @param bytes Raw byte data * * @return bitmap */ static public Bitmap getBitmapFromBytes(byte[] bytes) { if (bytes == null || bytes.length == 0) return null; BitmapFactory.Options options = new BitmapFactory.Options(); Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options); String s = "Array " + bytes.length + " bytes, bitmap " + bitmap.getHeight() + "x" + bitmap.getWidth(); System.out.println(s); return bitmap; }
From source file:com.daiv.android.twitter.services.TestPullNotificationService.java
public Bitmap decodeSampledBitmapFromResourceMemOpt(InputStream inputStream, int reqWidth, int reqHeight) { byte[] byteArr = new byte[0]; byte[] buffer = new byte[1024]; int len;/*w w w .j ava2 s. co m*/ int count = 0; try { while ((len = inputStream.read(buffer)) > -1) { if (len != 0) { if (count + len > byteArr.length) { byte[] newbuf = new byte[(count + len) * 2]; System.arraycopy(byteArr, 0, newbuf, 0, count); byteArr = newbuf; } System.arraycopy(buffer, 0, byteArr, count, len); count += len; } } final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeByteArray(byteArr, 0, count, options); options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); options.inPurgeable = true; options.inInputShareable = true; options.inJustDecodeBounds = false; options.inPreferredConfig = Bitmap.Config.ARGB_8888; return BitmapFactory.decodeByteArray(byteArr, 0, count, options); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.codename1.impl.android.AndroidImplementation.java
@Override public Object createImage(byte[] bytes, int offset, int len) { BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; try {/*ww w. j ava 2s .com*/ BitmapFactory.Options.class.getField("inPurgeable").set(opts, true); } catch (Exception e) { // inPurgeable not supported // http://www.droidnova.com/2d-sprite-animation-in-android-addendum,505.html } return BitmapFactory.decodeByteArray(bytes, offset, len, opts); }
From source file:com.piusvelte.sonet.core.SonetService.java
private void buildWidgetButtons(Integer appWidgetId, boolean updatesReady, int page, boolean hasbuttons, int scrollable, int buttons_bg_color, int buttons_color, int buttons_textsize, boolean display_profile, int margin) { final String widget = Integer.toString(appWidgetId); // Push update for this widget to the home screen int layout;// w w w . j a v a 2s . c om if (hasbuttons) { if (sNativeScrollingSupported) { if (margin > 0) layout = R.layout.widget_margin_scrollable; else layout = R.layout.widget_scrollable; } else if (display_profile) { if (margin > 0) layout = R.layout.widget_margin; else layout = R.layout.widget; } else { if (margin > 0) layout = R.layout.widget_noprofile_margin; else layout = R.layout.widget_noprofile; } } else { if (sNativeScrollingSupported) { if (margin > 0) layout = R.layout.widget_nobuttons_margin_scrollable; else layout = R.layout.widget_nobuttons_scrollable; } else if (display_profile) { if (margin > 0) layout = R.layout.widget_nobuttons_margin; else layout = R.layout.widget_nobuttons; } else { if (margin > 0) layout = R.layout.widget_nobuttons_noprofile_margin; else layout = R.layout.widget_nobuttons_noprofile; } } // wrap RemoteViews for backward compatibility RemoteViews views = new RemoteViews(getPackageName(), layout); if (hasbuttons) { Bitmap buttons_bg = Bitmap.createBitmap(1, 1, Config.ARGB_8888); Canvas buttons_bg_canvas = new Canvas(buttons_bg); buttons_bg_canvas.drawColor(buttons_bg_color); views.setImageViewBitmap(R.id.buttons_bg, buttons_bg); views.setTextColor(R.id.buttons_bg_clear, buttons_bg_color); views.setFloat(R.id.buttons_bg_clear, "setTextSize", buttons_textsize); views.setOnClickPendingIntent(R.id.button_post, PendingIntent.getActivity(SonetService.this, 0, Sonet.getPackageIntent(SonetService.this, SonetCreatePost.class) .setAction(LauncherIntent.Action.ACTION_VIEW_CLICK) .setData(Uri.withAppendedPath(Widgets.getContentUri(SonetService.this), widget)), 0)); views.setTextColor(R.id.button_post, buttons_color); views.setFloat(R.id.button_post, "setTextSize", buttons_textsize); views.setOnClickPendingIntent(R.id.button_configure, PendingIntent.getActivity(SonetService.this, 0, Sonet.getPackageIntent(SonetService.this, ManageAccounts.class).setAction(widget), 0)); views.setTextColor(R.id.button_configure, buttons_color); views.setFloat(R.id.button_configure, "setTextSize", buttons_textsize); views.setOnClickPendingIntent(R.id.button_refresh, PendingIntent.getService(SonetService.this, 0, Sonet.getPackageIntent(SonetService.this, SonetService.class).setAction(widget), 0)); views.setTextColor(R.id.button_refresh, buttons_color); views.setFloat(R.id.button_refresh, "setTextSize", buttons_textsize); views.setTextColor(R.id.page_up, buttons_color); views.setFloat(R.id.page_up, "setTextSize", buttons_textsize); views.setTextColor(R.id.page_down, buttons_color); views.setFloat(R.id.page_down, "setTextSize", buttons_textsize); } // set margin if (scrollable == 0) { final AppWidgetManager mgr = AppWidgetManager.getInstance(SonetService.this); // check if native scrolling is supported if (sNativeScrollingSupported) { // native scrolling try { final Intent intent = SonetRemoteViewsServiceWrapper.getRemoteAdapterIntent(SonetService.this); if (intent != null) { intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); intent.putExtra(Widgets.DISPLAY_PROFILE, display_profile); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); sSetRemoteAdapter.invoke(views, appWidgetId, R.id.messages, intent); // empty sSetEmptyView.invoke(views, R.id.messages, R.id.empty_messages); // onclick // Bind a click listener template for the contents of the message list final Intent onClickIntent = Sonet.getPackageIntent(SonetService.this, SonetWidget.class); onClickIntent.setAction(ACTION_ON_CLICK); onClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); onClickIntent.setData(Uri.parse(onClickIntent.toUri(Intent.URI_INTENT_SCHEME))); final PendingIntent onClickPendingIntent = PendingIntent.getBroadcast(SonetService.this, 0, onClickIntent, PendingIntent.FLAG_UPDATE_CURRENT); sSetPendingIntentTemplate.invoke(views, R.id.messages, onClickPendingIntent); } else { // fallback on non-scrolling widget sNativeScrollingSupported = false; } } catch (NumberFormatException e) { Log.e(TAG, e.toString()); } catch (IllegalArgumentException e) { Log.e(TAG, e.toString()); } catch (IllegalAccessException e) { Log.e(TAG, e.toString()); } catch (InvocationTargetException e) { Log.e(TAG, e.toString()); } } if (!sNativeScrollingSupported) { Cursor statuses_styles = getContentResolver().query( Uri.withAppendedPath(Statuses_styles.getContentUri(SonetService.this), widget), new String[] { Statuses_styles._ID, Statuses_styles.FRIEND, Statuses_styles.PROFILE, Statuses_styles.MESSAGE, Statuses_styles.CREATEDTEXT, Statuses_styles.MESSAGES_COLOR, Statuses_styles.FRIEND_COLOR, Statuses_styles.CREATED_COLOR, Statuses_styles.MESSAGES_TEXTSIZE, Statuses_styles.FRIEND_TEXTSIZE, Statuses_styles.CREATED_TEXTSIZE, Statuses_styles.STATUS_BG, Statuses_styles.ICON, Statuses_styles.PROFILE_BG, Statuses_styles.FRIEND_BG, Statuses_styles.IMAGE_BG, Statuses_styles.IMAGE }, null, null, Statuses_styles.CREATED + " DESC LIMIT " + page + ",-1"); if (statuses_styles.moveToFirst()) { int count_status = 0; views.removeAllViews(R.id.messages); while (!statuses_styles.isAfterLast() && (count_status < 16)) { int friend_color = statuses_styles.getInt(6), created_color = statuses_styles.getInt(7), friend_textsize = statuses_styles.getInt(9), created_textsize = statuses_styles.getInt(10), messages_color = statuses_styles.getInt(5), messages_textsize = statuses_styles.getInt(8); // get the item wrapper RemoteViews itemView; if (display_profile) { itemView = new RemoteViews(getPackageName(), R.layout.widget_item); // set profiles background byte[] profile_bg = statuses_styles.getBlob(13); if (profile_bg != null) { Bitmap profile_bgbmp = BitmapFactory.decodeByteArray(profile_bg, 0, profile_bg.length, sBFOptions); if (profile_bgbmp != null) itemView.setImageViewBitmap(R.id.profile_bg, profile_bgbmp); } byte[] profile = statuses_styles.getBlob(2); if (profile != null) { Bitmap profilebmp = BitmapFactory.decodeByteArray(profile, 0, profile.length, sBFOptions); if (profilebmp != null) itemView.setImageViewBitmap(R.id.profile, profilebmp); } } else itemView = new RemoteViews(getPackageName(), R.layout.widget_item_noprofile); itemView.setTextViewText(R.id.friend_bg_clear, statuses_styles.getString(1)); itemView.setFloat(R.id.friend_bg_clear, "setTextSize", friend_textsize); itemView.setTextViewText(R.id.message_bg_clear, statuses_styles.getString(3)); itemView.setFloat(R.id.message_bg_clear, "setTextSize", messages_textsize); // set friends background byte[] friend_bg = statuses_styles.getBlob(14); if (friend_bg != null) { Bitmap friend_bgbmp = BitmapFactory.decodeByteArray(friend_bg, 0, friend_bg.length, sBFOptions); if (friend_bgbmp != null) itemView.setImageViewBitmap(R.id.friend_bg, friend_bgbmp); } // set messages background byte[] status_bg = statuses_styles.getBlob(11); if (status_bg != null) { Bitmap status_bgbmp = BitmapFactory.decodeByteArray(status_bg, 0, status_bg.length, sBFOptions); if (status_bgbmp != null) itemView.setImageViewBitmap(R.id.status_bg, status_bgbmp); } // set an image byte[] image_bg = statuses_styles.getBlob(15); byte[] image = statuses_styles.getBlob(16); if ((image_bg != null) && (image != null)) { Bitmap image_bgBmp = BitmapFactory.decodeByteArray(image_bg, 0, image_bg.length, sBFOptions); if (image_bgBmp != null) { Bitmap imageBmp = BitmapFactory.decodeByteArray(image, 0, image.length, sBFOptions); itemView.setImageViewBitmap(R.id.image_clear, image_bgBmp); itemView.setImageViewBitmap(R.id.image, imageBmp); } } itemView.setTextViewText(R.id.message, statuses_styles.getString(3)); itemView.setTextColor(R.id.message, messages_color); itemView.setFloat(R.id.message, "setTextSize", messages_textsize); itemView.setOnClickPendingIntent(R.id.item, PendingIntent.getActivity(SonetService.this, 0, Sonet.getPackageIntent(SonetService.this, StatusDialog.class) .setData(Uri.withAppendedPath( Statuses_styles.getContentUri(SonetService.this), Long.toString(statuses_styles.getLong(0)))), 0)); itemView.setTextViewText(R.id.friend, statuses_styles.getString(1)); itemView.setTextColor(R.id.friend, friend_color); itemView.setFloat(R.id.friend, "setTextSize", friend_textsize); itemView.setTextViewText(R.id.created, statuses_styles.getString(4)); itemView.setTextColor(R.id.created, created_color); itemView.setFloat(R.id.created, "setTextSize", created_textsize); // set icons byte[] icon = statuses_styles.getBlob(12); if (icon != null) { Bitmap iconbmp = BitmapFactory.decodeByteArray(icon, 0, icon.length, sBFOptions); if (iconbmp != null) itemView.setImageViewBitmap(R.id.icon, iconbmp); } views.addView(R.id.messages, itemView); count_status++; statuses_styles.moveToNext(); } if (hasbuttons && (page < statuses_styles.getCount())) { // there are more statuses to show, allow paging down views.setOnClickPendingIntent(R.id.page_down, PendingIntent.getService(SonetService.this, 0, Sonet.getPackageIntent(SonetService.this, SonetService.class) .setAction(ACTION_PAGE_DOWN) .setData(Uri.withAppendedPath(Widgets.getContentUri(SonetService.this), widget)) .putExtra(ACTION_PAGE_DOWN, page + 1), PendingIntent.FLAG_UPDATE_CURRENT)); } } statuses_styles.close(); if (hasbuttons && (page > 0)) views.setOnClickPendingIntent(R.id.page_up, PendingIntent.getService(SonetService.this, 0, Sonet.getPackageIntent(SonetService.this, SonetService.class).setAction(ACTION_PAGE_UP) .setData(Uri.withAppendedPath(Widgets.getContentUri(SonetService.this), widget)) .putExtra(ACTION_PAGE_UP, page - 1), PendingIntent.FLAG_UPDATE_CURRENT)); } Log.d(TAG, "update native widget: " + appWidgetId); mgr.updateAppWidget(appWidgetId, views); if (sNativeScrollingSupported) { Log.d(TAG, "trigger widget query: " + appWidgetId); try { // trigger query sNotifyAppWidgetViewDataChanged.invoke(mgr, appWidgetId, R.id.messages); } catch (NumberFormatException e) { Log.e(TAG, e.toString()); } catch (IllegalArgumentException e) { Log.e(TAG, e.toString()); } catch (IllegalAccessException e) { Log.e(TAG, e.toString()); } catch (InvocationTargetException e) { Log.e(TAG, e.toString()); } } } else if (updatesReady) { // Log.d(TAG, "notify updatesReady"); getContentResolver().notifyChange(Statuses_styles.getContentUri(SonetService.this), null); } else { AppWidgetManager.getInstance(SonetService.this).updateAppWidget(Integer.parseInt(widget), views); buildScrollableWidget(appWidgetId, scrollable, display_profile); } }