List of usage examples for android.graphics BitmapFactory decodeStream
@Nullable public static Bitmap decodeStream(@Nullable InputStream is, @Nullable Rect outPadding, @Nullable Options opts)
From source file:prince.app.sphotos.Gallery.UriTexture.java
public static int computeSampleSize(InputStream stream, int maxResolutionX, int maxResolutionY) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;//w ww. j a v a2s . com BitmapFactory.decodeStream(stream, null, options); int maxNumOfPixels = maxResolutionX * maxResolutionY; int minSideLength = Math.min(maxResolutionX, maxResolutionY) / 2; return Utils.computeSampleSize(options, minSideLength, maxNumOfPixels); }
From source file:com.cooliris.mediayemaha.UriTexture.java
private static int computeSampleSize(InputStream stream, int maxResolutionX, int maxResolutionY) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;/*from ww w . jav a 2 s.c om*/ BitmapFactory.decodeStream(stream, null, options); int maxNumOfPixels = maxResolutionX * maxResolutionY; int minSideLength = Math.min(maxResolutionX, maxResolutionY) / 2; return Utils.computeSampleSize(options, minSideLength, maxNumOfPixels); }
From source file:com.android.browser.DownloadTouchIcon.java
@Override public Void doInBackground(String... values) { mCursor = BrowserBookmarksAdapter.queryBookmarksForUrl(mContentResolver, mOriginalUrl, mUrl, true); if (mCursor != null && mCursor.getCount() > 0) { String url = values[0];//ww w . ja v a 2 s.c om AndroidHttpClient client = AndroidHttpClient.newInstance(mUserAgent); HttpGet request = new HttpGet(url); // Follow redirects HttpClientParams.setRedirecting(client.getParams(), true); try { HttpResponse response = client.execute(request); if (response.getStatusLine().getStatusCode() == 200) { HttpEntity entity = response.getEntity(); if (entity != null) { InputStream content = entity.getContent(); if (content != null) { Bitmap icon = BitmapFactory.decodeStream(content, null, null); storeIcon(icon); } } } } catch (IllegalArgumentException ex) { request.abort(); } catch (IOException ex) { request.abort(); } finally { client.close(); } } if (mCursor != null) { mCursor.close(); } return null; }
From source file:com.ibuildapp.romanblack.CataloguePlugin.utils.Utils.java
/** * Opens Bitmap from file//from w w w.j a va 2 s . co m * * @param fileName - file path * @return */ public static Bitmap proccessBitmap(String fileName, Bitmap.Config config, int widthLimit) { Bitmap bitmap = null; File tempFile = null; BitmapFactory.Options opts = new BitmapFactory.Options(); try { // decode image with appropriate options tempFile = new File(fileName); opts.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(tempFile), null, opts); } catch (Exception e) { } //Find the correct scale value. It should be the power of 2. int width = opts.outWidth, height = opts.outHeight; ; int scale = 1; while (true) { if (width / 2 <= widthLimit || height / 2 <= widthLimit) { break; } width /= 2; height /= 2; scale *= 2; } opts = new BitmapFactory.Options(); opts.inSampleSize = scale; opts.inPreferredConfig = config; try { System.gc(); bitmap = BitmapFactory.decodeStream(new FileInputStream(tempFile), null, opts); if (bitmap != null) { return bitmap; } } catch (Exception ex) { } catch (OutOfMemoryError e) { } try { Thread.sleep(300); } catch (InterruptedException e) { e.printStackTrace(); } try { System.gc(); bitmap = BitmapFactory.decodeStream(new FileInputStream(tempFile), null, opts); if (bitmap != null) { return bitmap; } } catch (Exception ex) { } catch (OutOfMemoryError ex) { } try { Thread.sleep(300); } catch (InterruptedException e) { e.printStackTrace(); } try { System.gc(); bitmap = BitmapFactory.decodeStream(new FileInputStream(tempFile), null, opts); } catch (Exception ex) { } catch (OutOfMemoryError ex) { } return bitmap; }
From source file:playn.android.AndroidAssetManager.java
private Bitmap decodeBitmap(InputStream is) { BitmapFactory.Options options = new BitmapFactory.Options(); ////www.j av a 2 s .c o m options.inDither = true; // Prefer the bitmap config we computed from the window parameter options.inPreferredConfig = AndroidPlatform.instance.preferredBitmapConfig; // Never scale bitmaps based on device parameters options.inScaled = false; return BitmapFactory.decodeStream(is, null, options); }
From source file:Main.java
private static Bitmap getMutableBitmap(InputStream is, Rect outPadding) { return BitmapFactory.decodeStream(is, outPadding, getMutableOption()); }
From source file:gov.nasa.arc.geocam.geocam.CameraPreviewActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Window and view properties requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.camera_preview); // Load bitmap from intent data and display in imageview mImageUri = getIntent().getData();//from w ww . j a v a2s . c o m try { mImageData = new JSONObject(getIntent().getExtras().getString("data")); } catch (JSONException e1) { Log.d(GeoCamMobile.DEBUG_ID, "Error unserializing JSON data from intent"); mImageData = new JSONObject(); } try { final BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inSampleSize = 4; InputStream in = getContentResolver().openInputStream(mImageUri); Bitmap bitmap = BitmapFactory.decodeStream(in, null, opts); //Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), mImageUri); ImageView imageView = (ImageView) findViewById(R.id.camera_preview_imageview); imageView.setAdjustViewBounds(true); imageView.setScaleType(ScaleType.CENTER_INSIDE); imageView.setImageBitmap(bitmap); } catch (FileNotFoundException e) { Log.d(GeoCamMobile.DEBUG_ID, "Error loading bitmap in CameraPreviewActivity"); } SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); String defaultNotes = settings.getString(GeoCamMobile.SETTINGS_DEFAULT_NOTES_KEY, ""); // Set default notes EditText notesText = (EditText) findViewById(R.id.camera_preview_edittext); notesText.setText(defaultNotes + " "); // Buttons mFireButton = (ImageButton) findViewById(R.id.camera_preview_fire_button); mFireButton.setImageDrawable(getResources().getDrawable(R.drawable.fire_icon_default)); mFireButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_PICK); intent.setClass(CameraPreviewActivity.this, FireIconActivity.class); startActivityForResult(intent, PICK_ICON_REQUEST); } }); final ImageButton deleteButton = (ImageButton) findViewById(R.id.camera_preview_delete_button); deleteButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { CameraPreviewActivity.this.showDialog(DIALOG_DELETE_PHOTO); } }); final ImageButton saveButton = (ImageButton) findViewById(R.id.camera_preview_save_button); saveButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { mImageNote = ((EditText) findViewById(R.id.camera_preview_edittext)).getText().toString(); Log.d(GeoCamMobile.DEBUG_ID, "Setting image note to: " + mImageNote); saveWithAnnotation(); } }); mForeground = new ForegroundTracker(this); }
From source file:com.pickr.tasks.PhotoLoader.java
private Bitmap loadBitmap(PhotoSize size, Display display) throws IOException { InputStream is = null;/*w ww . ja v a 2s . c om*/ try { if (BuildConfig.DEBUG) { LOGGER.d("Loading photo with size " + size.getWidth() + "x" + size.getHeight() + " for screen " + display.getWidth() + "x" + display.getHeight()); } URL url = size.getSource(); Bitmap bitmap = FlickrCache.getBitmapCache().get(url); if (bitmap == null) { is = url.openStream(); Options options = new Options(); options.inPurgeable = true; options.inInputShareable = true; options.inSampleSize = BitmapUtils.calculateInSampleSize(size.getWidth(), size.getHeight(), display.getWidth(), display.getHeight()); bitmap = BitmapFactory.decodeStream(is, null, options); FlickrCache.getBitmapCache().put(url, bitmap); } Message msg = mHandler.obtainMessage(PHOTO_URL, url); mHandler.sendMessage(msg); return bitmap; } finally { IOUtils.closeQuietly(is); } }
From source file:com.image.oom.ImageUtil.java
public static Bitmap getBitMap(String fileFullName, int width, int height) throws Exception { BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true;/*ww w .j a va2 s . c o m*/ FileInputStream fileInputStream = new FileInputStream(new File(fileFullName)); BitmapFactory.decodeFile(fileFullName, opts); int be = 1; if (height != 0) { be = (int) (opts.outHeight / (float) width); if (be <= 0) be = 1; } if (width != 0) { be = (int) (opts.outWidth / (float) width); if (be <= 0) be = 1; } opts.inSampleSize = be; opts.inJustDecodeBounds = false; final Bitmap bm = BitmapFactory.decodeStream(fileInputStream, null, opts); fileInputStream.close(); return bm; }
From source file:ir.rasen.charsoo.controller.image_loader.core.decode.BaseImageDecoder.java
/** * Decodes image from URI into {@link Bitmap}. Image is scaled close to incoming {@linkplain ImageSize target size} * during decoding (depend on incoming parameters). * * @param decodingInfo Needed data for decoding image * @return Decoded bitmap/*from ww w . j av a2 s . c o m*/ * @throws IOException if some I/O exception occurs during image reading * @throws UnsupportedOperationException if image URI has unsupported scheme(protocol) */ @Override public Bitmap decode(ImageDecodingInfo decodingInfo) throws IOException, JSONException { Bitmap decodedBitmap; ImageFileInfo imageInfo; InputStream imageStream = getImageStream(decodingInfo); if (imageStream == null) { L.e(ERROR_NO_IMAGE_STREAM, decodingInfo.getImageKey()); return null; } try { imageInfo = defineImageSizeAndRotation(imageStream, decodingInfo); imageStream = resetStream(imageStream, decodingInfo); Options decodingOptions = prepareDecodingOptions(imageInfo.imageSize, decodingInfo); decodedBitmap = BitmapFactory.decodeStream(imageStream, null, decodingOptions); } finally { IoUtils.closeSilently(imageStream); } if (decodedBitmap == null) { L.e(ERROR_CANT_DECODE_IMAGE, decodingInfo.getImageKey()); } else { decodedBitmap = considerExactScaleAndOrientatiton(decodedBitmap, decodingInfo, imageInfo.exif.rotation, imageInfo.exif.flipHorizontal); } return decodedBitmap; }