List of usage examples for android.graphics BitmapFactory decodeFile
public static Bitmap decodeFile(String pathName, Options opts)
From source file:com.karura.framework.plugins.Capture.java
/** * Get the Image specific attributes/*from w w w . j a v a2 s. co m*/ * * @param filePath * path to the file * @param obj * represents the Media File Data * @return a JSONObject that represents the Media File Data * @throws JSONException */ private JSONObject getImageMetadata(String filePath, JSONObject obj) throws JSONException { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(getRealPathFromURI(Uri.parse(filePath), getActivity()), options); obj.put(HEIGHT_FIELD, options.outHeight); obj.put(WIDTH_FIELD, options.outWidth); return obj; }
From source file:com.cooliris.media.UriTexture.java
public static Bitmap createFromCache(long crc64, int maxResolution) { try {// w w w .j a v a 2 s . co m String file = null; Bitmap bitmap = null; final BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = false; options.inPreferredConfig = Bitmap.Config.ARGB_8888; options.inDither = true; options.inSampleSize = 1; options.inPurgeable = true; if (crc64 != 0) { file = createFilePathFromCrc64(crc64, maxResolution); bitmap = BitmapFactory.decodeFile(file, options); } return bitmap; } catch (Exception e) { return null; } }
From source file:com.cssweb.android.base.BaseActivity.java
private int initBitmap() { String[] menus = getCustMenus(); try {/*from w w w . j a v a 2 s. c o m*/ if (images == null) { initMenu(); } if (images != null) { for (String menu : menus) { String imagename = getImageNameFromItemName(images, menu); Bitmap bitmap = null; HashMap<String, Object> map = new HashMap<String, Object>(); if (imagename != null) { File file = new File(imagename); if (file.exists()) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 2; bitmap = BitmapFactory.decodeFile(imagename, options); map.put(String.valueOf(1), bitmap); map.put("itemname", menu); Config.mapBitmap.add(map); } else { } } } } } catch (Exception e) { e.printStackTrace(); return 10; } return menus.length; }
From source file:Main.java
/** * load the bitmap from SDCard with the imgW and imgH * * @param imgPath resource path//w ww.ja v a 2 s .c o m * @param imgH result image height * @param imgW result image width * @return result bitmap */ public static Bitmap loadHugeBitmapFromSDCard(String imgPath, int imgH, int imgW) { Log.d(TAG, "imgH:" + imgH + " imgW:" + imgW); BitmapFactory.Options options = new BitmapFactory.Options(); //preload set inJustDecodeBounds true, this will load bitmap into memory options.inJustDecodeBounds = true; //options.inPreferredConfig = Bitmap.Config.ARGB_8888;//default is Bitmap.Config.ARGB_8888 BitmapFactory.decodeFile(imgPath, options); //get the image information include: height and width int height = options.outHeight; int width = options.outWidth; String mimeType = options.outMimeType; Log.d(TAG, "width:" + width + " height:" + height + " mimeType:" + mimeType); //get sample size int sampleSize = getScaleInSampleSize(width, height, imgW, imgH); options.inSampleSize = sampleSize; // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; Log.d(TAG, "memory size:" + getBitmapSizeInMemory(width / sampleSize, height / sampleSize)); Bitmap bitmap = BitmapFactory.decodeFile(imgPath, options); return bitmap; }
From source file:com.lightbox.android.bitmap.BitmapUtils.java
public static Bitmap decodeFile(String pathName, int maxWidth, int maxHeight) { Options options = new Options(); options.inJustDecodeBounds = true;/* w ww . j av a2 s . c o m*/ int sampleSize = 1; options.inSampleSize = sampleSize; BitmapFactory.decodeFile(pathName, options); if (maxWidth < options.outWidth || maxHeight < options.outHeight) { int sampleSizeW = (int) FloatMath.ceil((float) options.outWidth / maxWidth); int sampleSizeH = (int) FloatMath.ceil((float) options.outHeight / maxHeight); sampleSize = Math.max(sampleSizeW, sampleSizeH); options.inSampleSize = sampleSize; } options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(pathName, options); }
From source file:com.ritul.truckshare.RegisterActivity.DriverLicenseActivity.java
protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == Utility.GALLERY_PICTURE && data != null) { isImage = true;/*from w w w .j av a2 s . co m*/ // data contains result // Do some task Image_Selecting_Task(data); Uri selectedImage = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = DriverLicenseActivity.this.getContentResolver().query(selectedImage, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); selectedpath = cursor.getString(columnIndex); cursor.close(); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 8; final Bitmap bitmap = BitmapFactory.decodeFile(selectedpath, options); convertimagetobyte(); imagedata = Base64.encodeToString(imageByte, Base64.DEFAULT); } else if (requestCode == Utility.CAMERA_PICTURE && data != null) { isImage = true; // Do some task //Image_Selecting_Task(data); if (requestCode == Utility.CAMERA_PICTURE && resultCode == RESULT_OK && data != null) { Bitmap photo = (Bitmap) data.getExtras().get("data"); preview.setImageBitmap(photo); Bitmap bitmap = ((BitmapDrawable) preview.getDrawable()).getBitmap(); imagedata = Base64.encodeToString(getBytesFromBitmap(bitmap), Base64.DEFAULT); } } }
From source file:es.eucm.eadandroid.homeapp.repository.resourceHandler.RepoResourceHandler.java
/** * Gets the list of saved games from its folder *///from w ww.ja v a 2 s.c om public static LoadGamesArray getexpandablelist() { LoadGamesArray info = new LoadGamesArray(); String[] games = null; Bitmap[] screen_shots = null; if (!new File(Paths.eaddirectory.SAVED_GAMES_PATH).exists()) { new File(Paths.eaddirectory.SAVED_GAMES_PATH).mkdir(); } else { File gamesfolders = new File(Paths.eaddirectory.SAVED_GAMES_PATH); games = gamesfolders.list(new EADFileFilter()); if (games.length > 0) { for (int i = 0; i < games.length; i++) { File gamefolder = new File(Paths.eaddirectory.SAVED_GAMES_PATH + games[i] + "/"); String files[] = gamefolder.list(new TxtFilter()); String screen_shots_bitmaps[] = gamefolder.list(new PNGFilter()); screen_shots = new Bitmap[files.length]; for (int j = 0; j < files.length; j++) { if (screen_shots_bitmaps.length > j && screen_shots_bitmaps[j] != null) { Log.e("Path", screen_shots_bitmaps[j]); screen_shots[j] = BitmapFactory.decodeFile( Paths.eaddirectory.SAVED_GAMES_PATH + games[i] + "/" + screen_shots_bitmaps[j], null); } info.addGame(games[i], files[j], screen_shots[j]); } } } } return info; }
From source file:org.ueu.uninet.it.IragarkiaBidali.java
public void decodeFile(final String filePath) { // Decode image size if (bitmap != null) { bitmap.recycle();/* w w w. j a v a 2s . co m*/ } BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeFile(filePath, o); // The new size we want to scale to final int REQUIRED_SIZE = 1024; // Find the correct scale value. It should be the power of 2. int width_tmp = o.outWidth, height_tmp = o.outHeight; int scale = 1; while (true) { if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE) break; width_tmp /= 2; height_tmp /= 2; scale *= 2; } // Decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = scale; bitmap = BitmapFactory.decodeFile(filePath, o2); imgView.setImageBitmap(bitmap); imgView.setVisibility(View.VISIBLE); }
From source file:com.miz.functions.MizLib.java
/** * Returns a custom theme background image as Bitmap. * @param height//from www .j a v a 2 s .c o m * @param width * @return Bitmap with the background image */ public static Bitmap getCustomThemeBackground(int height, int width, String url) { try { BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Config.RGB_565; options.inDither = true; Bitmap bm = BitmapFactory.decodeFile(url, options); float scaleWidth = bm.getWidth() / ((float) width); float scaleHeight = bm.getHeight() / ((float) height); if (scaleWidth > scaleHeight) bm = Bitmap.createScaledBitmap(bm, (int) (bm.getWidth() / scaleHeight), (int) (bm.getHeight() / scaleHeight), true); else bm = Bitmap.createScaledBitmap(bm, (int) (bm.getWidth() / scaleWidth), (int) (bm.getHeight() / scaleWidth), true); bm = Bitmap.createBitmap(bm, (bm.getWidth() - width) / 2, (bm.getHeight() - height) / 2, width, height); return bm; } catch (Exception e) { return null; } }