BitmapFactory decodeStream - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for BitmapFactory decodeStream method.

This code example shows how to use the following methods:decodeStream, readUTF, close
        BufferedInputStream b = null;
        DataInputStream d = null;
        try { 
            f = new FileInputStream(filePath);
            b = new BufferedInputStream(f, BUFSIZE);
            d = new DataInputStream(b);
            Uri uri = Uri.parse(d.readUTF());
            Bitmap thumb = BitmapFactory.decodeStream(d);
            setData(uri, thumb);
            d.close();
        } catch (IOException e) {
            return false; 
        } finally { 
            MenuHelper.closeSilently(f);
            MenuHelper.closeSilently(b);
            MenuHelper.closeSilently(d);
        } 
        return true; 
    } 
 
    public void updateDisplayIfNeeded() { 
8
CodeRank
This code example shows how to use the following methods:decodeStream
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
 
        BufferedInputStream stream = null;
        try { 
            stream = new BufferedInputStream(new FileInputStream(file));
            BitmapFactory.decodeStream(stream, null, options);
        } catch (FileNotFoundException e) {
            Log.e("HtmlImage.setSampleSize", e);
        } finally { 
            IOUtils.closeQuietly(stream);
        } 
 
        int scale = 1;
        if (options.outHeight > maxHeight || options.outWidth > maxWidth) {
            scale = Math.max(options.outHeight / maxHeight, options.outWidth / maxWidth);
        } 
        bfOptions.inSampleSize = scale;
    } 
 
8
CodeRank
This code example shows how to use the following methods:decodeStream
		decodeOptions.inJustDecodeBounds = true;
 
		InputStream in = null;
		try { 
			in = pAssetManager.open(pAssetPath);
			BitmapFactory.decodeStream(in, null, decodeOptions);
		} catch (final IOException e) {
			Debug.e("Failed loading Bitmap in AssetBitmapTextureAtlasSource. AssetPath: " + pAssetPath, e);
		} finally { 
			StreamUtils.close(in);
		} 
 
		return new AssetBitmapTextureAtlasSource(pAssetManager, pAssetPath, pTextureX, pTextureY, decodeOptions.outWidth, decodeOptions.outHeight);
	} 
 
	AssetBitmapTextureAtlasSource(final AssetManager pAssetManager, final String pAssetPath, final int pTextureX, final int pTextureY, final int pTextureWidth, final int pTextureHeight) {
		super(pTextureX, pTextureY, pTextureWidth, pTextureHeight);
 
		this.mAssetManager = pAssetManager;
		this.mAssetPath = pAssetPath;
8
CodeRank
This code example shows how to use the following methods:decodeStream
				URL aURL = new URL(url);
				URLConnection conn = aURL.openConnection();
 
				conn.connect();
 
				is = new BufferedInputStream(conn.getInputStream());
 
				return BitmapFactory.decodeStream(is);
			} catch (IOException e) {
				AphidLog.e(e, "Failed to load bitmap from url: " + url);
			} finally { 
				IO.close(is);
			} 
 
			return null; 
		} 
 
		@Override 
		protected void onPostExecute(Bitmap result) {
			if (isCancelled())
8
CodeRank
This code example shows how to use the following methods:decodeStream, readUTF, close
        BufferedInputStream b = null;
        DataInputStream d = null;
        try { 
            f = new FileInputStream(filePath);
            b = new BufferedInputStream(f, BUFSIZE);
            d = new DataInputStream(b);
            Uri uri = Uri.parse(d.readUTF());
            Bitmap thumb = BitmapFactory.decodeStream(d);
            setData(uri, thumb);
            d.close();
        } catch (IOException e) {
            return false; 
        } finally { 
            MenuHelper.closeSilently(f);
            MenuHelper.closeSilently(b);
            MenuHelper.closeSilently(d);
        } 
        return true; 
    } 
 
    public void updateDisplayIfNeeded(int duration) {
7
CodeRank
This code example shows how to use the following methods:decodeStream
		InputStream stream = openInputStream( context, uri );
		if( null == stream ) return null;
		 
		try { 
			// decode the bitmap via android BitmapFactory 
			bitmap = BitmapFactory.decodeStream( stream, null, options );
			IOUtils.closeSilently( stream );
 
			if ( bitmap != null ) {
				if( maxW > 0 && maxH > 0 ) {
					newBitmap = BitmapUtils.resizeBitmap( bitmap, maxW, maxH, orientation );
					if ( bitmap != newBitmap ) {
						bitmap.recycle();
					} 
					bitmap = newBitmap;
				} 
			} 
 
		} catch ( OutOfMemoryError error ) {
			IOUtils.closeSilently( stream );

7
CodeRank
This code example shows how to use the following methods:decodeStream, close
	 */ 
	public static Bitmap getBitmapByFile(File file) {
		FileInputStream fis = null;
		Bitmap bitmap =null; 
		try {  
			fis = new FileInputStream(file);
			bitmap = BitmapFactory.decodeStream(fis);
		} catch (FileNotFoundException e) {  
			e.printStackTrace();
		} catch (OutOfMemoryError e) {
			e.printStackTrace();
		} finally{ 
			try { 
				fis.close();
			} catch (Exception e) {}
		} 
		return bitmap;
	} 
	 
	/** 
7
CodeRank
This code example shows how to use the following methods:decodeStream, close, mark, reset
	    try { 
	        //Decode image size 
	        BitmapFactory.Options o = new BitmapFactory.Options();
	        o.inJustDecodeBounds = true;
 
	        BufferedInputStream bis = new BufferedInputStream(is);
	        bis.mark(Integer.MAX_VALUE);
	         
	        BitmapFactory.decodeStream(bis, null, o);
	        bis.reset();
	         
	        int scale = 1;
	        if (o.outHeight > desiredHeight || o.outWidth > desiredWidth) {
	            scale = (int)Math.pow(2, (int) Math.round(Math.log(Math.max(desiredHeight, desiredWidth) / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
	        } 
 
	        //Decode with inSampleSize 
	        BitmapFactory.Options o2 = new BitmapFactory.Options();
	        o2.inSampleSize = scale;
	        o2.inDither = true;

7
CodeRank
This code example shows how to use the following methods:decodeStream, close
 
				    BitmapFactory.decodeFile( image.getAbsolutePath(), options );
				    options.inSampleSize = getScale( options.outWidth, options.outHeight, (int) ( (float) options.outWidth * .70), (int) ( (float) options.outHeight * .70 ) );
				    options.inJustDecodeBounds=false;
				     
					InputStream is = new BufferedInputStream( new FileInputStream( image ) );
					Bitmap bitmap = BitmapFactory.decodeStream( is, null, options );
					is.close();
					 
					return new BitmapDrawable( mResources, bitmap );
				} catch( Exception e ) {
					Log.e( TAG, "create : error reading file" );
				} 
			} 
		} 
		 
		Log.v( TAG, "create : exit" );
		return super.create( key );
	} 
 
6
CodeRank
This code example shows how to use the following methods:decodeStream, readUTF, close
        BufferedInputStream b = null;
        DataInputStream d = null;
        try { 
            f = new FileInputStream(filePath);
            b = new BufferedInputStream(f, BUFSIZE);
            d = new DataInputStream(b);
            Uri uri = Uri.parse(d.readUTF());
            Bitmap thumb = BitmapFactory.decodeStream(d);
            setData(uri, thumb);
            d.close();
        } catch (IOException e) {
            return false; 
        } finally { 
            MenuHelper.closeSilently(f);
            MenuHelper.closeSilently(b);
            MenuHelper.closeSilently(d);
        } 
        return true; 
    } 
 
    public void updateDisplayIfNeeded(int duration) {
7
CodeRank

Related BitmapFactory decodeStream Questions & Answers:

Other BitmapFactory decodeStream Examples

43:	        }
44:	        stream = getContentResolver().openInputStream(data.getData());
45:	        bitmap = BitmapFactory.decodeStream(stream);
46:	
47:	        imageView.setImageBitmap(bitmap);

Read More

17:	    ImageView button = (ImageView) findViewById(R.id.image);
18:	    InputStream resource = getResources().openRawResource(R.drawable.dog);
19:	    Bitmap bitmap = BitmapFactory.decodeStream(resource);
20:	    button.setBackground(new MyRoundCornerDrawable(bitmap));
21:	  }

Read More

88:	            BitmapFactory.Options o = new BitmapFactory.Options();
89:	            o.inJustDecodeBounds = true;
90:	            BitmapFactory.decodeStream(new FileInputStream(f),null,o);
91:	 
92:	            //Find the correct scale value. It should be the power of 2.

Read More

306:				try {
307:					InputStream in = new java.net.URL(urldisplay).openStream();
308:					mIcon11 = BitmapFactory.decodeStream(in);
309:				} catch (Exception e) {
310:					Log.e("Error", e.getMessage());

Read More

51:				try {
52:					InputStream in = new java.net.URL(urldisplay).openStream();
53:					mIcon11 = BitmapFactory.decodeStream(in);
54:				} catch (Exception e) {
55:					Log.e("Error", e.getMessage());

Read More

decodeStream Method Overview
Decode an input stream into a bitmap.
See Code Examples for other Android BitmapFactory Methods: