List of usage examples for android.graphics BitmapFactory decodeStream
public static Bitmap decodeStream(InputStream is)
From source file:Main.java
public static Bitmap getImageFromAsset(Context ctx, String name) { try {/*from ww w .j a v a 2 s . com*/ return BitmapFactory.decodeStream(ctx.getResources().getAssets().open(name)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:Main.java
public static Bitmap fromFile(File file) throws FileNotFoundException { return BitmapFactory.decodeStream(new FileInputStream(file)); }
From source file:Main.java
public static Bitmap getBitmap(String s) { Bitmap bitmap = null;/* ww w . j ava 2 s . c o m*/ try { URL url = new URL(s); bitmap = BitmapFactory.decodeStream(url.openStream()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return bitmap; }
From source file:Main.java
/** * @Description input sream - > bitmap * @param iStream//from w w w .j a va2s. co m */ public static Bitmap InputStream2Bitmap(final InputStream iStream) { return BitmapFactory.decodeStream(iStream); }
From source file:Main.java
public static Bitmap getBitmap(Context context, String url) { Bitmap bitmap = null;/*w w w. j av a 2 s . com*/ try { bitmap = BitmapFactory.decodeStream(context.getAssets().open(url)); } catch (IOException e) { e.printStackTrace(); } return bitmap; }
From source file:Main.java
public static Bitmap decodeStream(InputStream is) throws IOException { Bitmap b = BitmapFactory.decodeStream(is); if (b == null) { throw new IOException("Failed to create bitmap, decodeStream() returned null"); }/*from w w w . jav a2s. c o m*/ return b; }
From source file:Main.java
public static Bitmap scaleToFillBitmap(Bitmap dst, InputStream is) { Bitmap src = BitmapFactory.decodeStream(is); float scaled = 1.0f; if ((float) dst.getWidth() / (float) src.getWidth() < (float) dst.getHeight() / (float) src.getHeight()) { scaled = (float) dst.getHeight() / (float) src.getHeight(); } else {//from w w w . j av a2 s . c o m scaled = (float) dst.getWidth() / (float) src.getWidth(); } Bitmap bmpScaled = Bitmap.createScaledBitmap(src, (int) Math.ceil(src.getWidth() * scaled), (int) Math.ceil(src.getHeight() * scaled), true); int offsetX = 0; int offsetY = 0; offsetX = bmpScaled.getWidth() - dst.getWidth() != 0 ? (bmpScaled.getWidth() - dst.getWidth()) / 2 : 0; offsetY = bmpScaled.getHeight() - dst.getHeight() != 0 ? (bmpScaled.getHeight() - dst.getHeight()) / 2 : 0; return Bitmap.createBitmap(bmpScaled, offsetX, offsetY, dst.getWidth(), dst.getHeight()); }
From source file:Main.java
public static Drawable inputStreamToDrawable(InputStream is) { Bitmap bm = BitmapFactory.decodeStream(is); return bitmapToDrawable(bm); }
From source file:Main.java
public static Bitmap loadScaledBitmap(Context context, String bitmapFilePath, int widthDp, int heightDp) throws IOException { //create movie icon Bitmap bitmap;//from w w w . java2 s . c o m bitmap = BitmapFactory.decodeStream(context.openFileInput(bitmapFilePath)); bitmap = Bitmap.createScaledBitmap(bitmap, widthDp, heightDp, true); return bitmap; }
From source file:Main.java
public static Bitmap getBmpByResId(Context context, int id) { InputStream isBackground = context.getResources().openRawResource(id); return BitmapFactory.decodeStream(isBackground); }