List of usage examples for android.graphics BitmapFactory decodeFileDescriptor
public static Bitmap decodeFileDescriptor(FileDescriptor fd)
From source file:com.netcompss.ffmpeg4android_client.BaseVideo.java
public String getFileNameByUri(Context context, Uri uri) { String fileName = "unknown";// default fileName Uri filePathUri = uri;//from ww w . j a va2 s .com if (uri.getScheme().toString().compareTo("content") == 0) { ParcelFileDescriptor parcelFileDescriptor; String filename = null; try { FileOutputStream fos = null; parcelFileDescriptor = context.getContentResolver().openFileDescriptor(uri, "r"); FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor(); Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor); String extr = Environment.getExternalStorageDirectory().toString(); File mFolder = new File(extr + "/CHURCH"); if (!mFolder.exists()) { mFolder.mkdir(); } else { mFolder.delete(); mFolder.mkdir(); } String s = "rough.png"; File f = new File(mFolder.getAbsolutePath(), s); filename = f.getAbsolutePath(); Log.d("f", filename); try { fos = new FileOutputStream(f); image.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } parcelFileDescriptor.close(); return filename; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if (uri.getScheme().compareTo("file") == 0) { fileName = filePathUri.getPath(); File fill = new File(fileName); if (fill.exists()) { Log.d("exitst", "exist"); ParcelFileDescriptor parcelFileDescriptor; String filename = null; FileOutputStream fos = null; Bitmap image = BitmapFactory.decodeFile(fileName); String extr = Environment.getExternalStorageDirectory().toString(); File mFolder = new File(extr + "/CHURCH"); if (!mFolder.exists()) { mFolder.mkdir(); } else { mFolder.delete(); mFolder.mkdir(); } String s = "rough.png"; File f = new File(mFolder.getAbsolutePath(), s); filename = f.getAbsolutePath(); Log.d("f", filename); try { fos = new FileOutputStream(f); image.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } else { Log.d("not file exitst", "not exist"); } Log.d("file", "file"); } else { fileName = filePathUri.getPath(); Log.d("else", "else"); } return fileName; }
From source file:com.netcompss.ffmpeg4android_client.BaseWizard.java
public static String getFileNameByUri(Context context, Uri uri) { String fileName = "unknown";// default fileName Uri filePathUri = uri;/*from w ww. jav a 2 s.com*/ if (uri.getScheme().toString().compareTo("content") == 0) { ParcelFileDescriptor parcelFileDescriptor; String filename = null; try { FileOutputStream fos = null; parcelFileDescriptor = context.getContentResolver().openFileDescriptor(uri, "r"); FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor(); Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor); String extr = Environment.getExternalStorageDirectory().toString(); File mFolder = new File(extr + "/CHURCH"); if (!mFolder.exists()) { mFolder.mkdir(); } else { mFolder.delete(); mFolder.mkdir(); } String s = "rough.png"; File f = new File(mFolder.getAbsolutePath(), s); filename = f.getAbsolutePath(); Log.d("f", filename); try { fos = new FileOutputStream(f); image.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } parcelFileDescriptor.close(); return filename; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if (uri.getScheme().compareTo("file") == 0) { fileName = filePathUri.getPath(); File fill = new File(fileName); if (fill.exists()) { Log.d("exitst", "exist"); ParcelFileDescriptor parcelFileDescriptor; String filename = null; FileOutputStream fos = null; Bitmap image = BitmapFactory.decodeFile(fileName); String extr = Environment.getExternalStorageDirectory().toString(); File mFolder = new File(extr + "/CHURCH"); if (!mFolder.exists()) { mFolder.mkdir(); } else { mFolder.delete(); mFolder.mkdir(); } String s = "rough.png"; File f = new File(mFolder.getAbsolutePath(), s); filename = f.getAbsolutePath(); Log.d("f", filename); try { fos = new FileOutputStream(f); image.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } else { Log.d("not file exitst", "not exist"); } Log.d("file", "file"); } else { fileName = filePathUri.getPath(); Log.d("else", "else"); } return fileName; }
From source file:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java
private static Bitmap getArtworkFromFile(Context context, long songid, long albumid) { Bitmap bm = null;/*w ww.ja v a 2 s. co m*/ byte[] art = null; String path = null; if (albumid < 0 && songid < 0) { throw new IllegalArgumentException("Must specify an album or a song id"); } try { if (albumid < 0) { Uri uri = Uri.parse("content://media/external/audio/media/" + songid + "/albumart"); ParcelFileDescriptor pfd = context.getContentResolver().openFileDescriptor(uri, "r"); if (pfd != null) { FileDescriptor fd = pfd.getFileDescriptor(); bm = BitmapFactory.decodeFileDescriptor(fd); } } else { Uri uri = ContentUris.withAppendedId(sArtworkUri, albumid); ParcelFileDescriptor pfd = context.getContentResolver().openFileDescriptor(uri, "r"); if (pfd != null) { FileDescriptor fd = pfd.getFileDescriptor(); bm = BitmapFactory.decodeFileDescriptor(fd); } } } catch (IllegalStateException | FileNotFoundException ex) { } if (bm != null) { mCachedBit = bm; } return bm; }