List of usage examples for android.graphics BitmapFactory decodeStream
public static Bitmap decodeStream(InputStream is)
From source file:Main.java
public static int loadTexture(String s) { Bitmap img;/*from w w w . ja v a 2 s . c o m*/ try { img = BitmapFactory.decodeStream(context.getAssets().open(s)); } catch (IOException e) { return 0; } int tex[] = new int[1]; GLES20.glGenTextures(1, tex, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex[0]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, img, 0); GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR_MIPMAP_LINEAR); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); img.recycle(); return tex[0]; }
From source file:Main.java
private static void shareAct(Activity act, String fileName, String text) { Uri uri = null;/*from ww w .j a v a2s . c o m*/ try { FileInputStream input = act.openFileInput(fileName); Bitmap bitmap = BitmapFactory.decodeStream(input); uri = Uri.parse(MediaStore.Images.Media.insertImage(act.getContentResolver(), bitmap, null, null)); input.close(); } catch (Exception e) { e.printStackTrace(); } Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.setType("image/jpeg"); act.startActivity(Intent.createChooser(shareIntent, act.getTitle())); }
From source file:Main.java
public static Bitmap downloadImage(String urlStr) throws IOException { URL url = new URL(urlStr); URLConnection connection = url.openConnection(); BufferedInputStream bis = new BufferedInputStream(connection.getInputStream()); Bitmap result = BitmapFactory.decodeStream(bis); bis.close();// w ww . j a v a 2 s . c om return result; }
From source file:Main.java
public static Bitmap getBitmapFromUri(Context context, Uri uri) throws FileNotFoundException { final InputStream imageStream = context.getContentResolver().openInputStream(uri); try {/*ww w .ja v a2 s . com*/ return BitmapFactory.decodeStream(imageStream); } finally { Closeables.closeQuietly(imageStream); } }
From source file:Main.java
public static Bitmap getImageFromAssetsFile(Context context, String fileName) { Bitmap image = null;// ww w . j a v a 2 s . c o m AssetManager am = context.getResources().getAssets(); try { InputStream is = am.open(fileName); image = BitmapFactory.decodeStream(is); is.close(); } catch (IOException e) { e.printStackTrace(); } return image; }
From source file:Main.java
public static Bitmap getBitmap(String biturl) { Bitmap bitmap = null;/*from w ww . ja va 2 s. c om*/ try { URL url = new URL(biturl); URLConnection conn = url.openConnection(); InputStream in = conn.getInputStream(); bitmap = BitmapFactory.decodeStream(new BufferedInputStream(in)); } catch (Exception e) { e.printStackTrace(); } return bitmap; }
From source file:Main.java
public static Bitmap getFromAsserts(Context context, String assertName) { InputStream inputStream = null; Bitmap bitmap = null;//from w w w . j a va 2s . c o m try { inputStream = context.getAssets().open(assertName); bitmap = BitmapFactory.decodeStream(inputStream); } catch (IOException e) { e.printStackTrace(); } finally { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } finally { return bitmap; } } }
From source file:Main.java
public static ImageView getImageViewFromUrl(String imageUrl, Activity activity, int viewId) { try {// ww w. ja v a 2 s . com ImageView i = (ImageView) activity.findViewById(viewId); Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(imageUrl).getContent()); i.setImageBitmap(bitmap); return i; } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static Bitmap getBitmapFromWeb(String imageURL) { Bitmap bitmap = null;//w w w. j a va2s .c o m if (imageURL != null && imageURL.compareTo("null") != 0) { try { InputStream in = new URL(DOMAIN + imageURL).openStream(); bitmap = BitmapFactory.decodeStream(in); } catch (Exception e) { e.printStackTrace(); } } return bitmap; }
From source file:Main.java
public static Bitmap readBitmapFromFile(Context context, String imageName) { Bitmap bitmap = null;/*from w w w . j a va 2 s. c o m*/ try { //read avatar file FileInputStream fileInputStream = context.openFileInput(imageName); bitmap = BitmapFactory.decodeStream(fileInputStream); fileInputStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return bitmap; }