Last active
August 29, 2015 14:17
-
-
Save fnk0/5d174d8743fcf76d78a4 to your computer and use it in GitHub Desktop.
Inflating view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| View v = LayoutInflater.from(activityContext).inflate(R.layout.fragment_share, null); | |
| v.setLayoutParams(new RelativeLayout.LayoutParams(2048, 1536)); | |
| LinearLayout shareLayout = (LinearLayout) v.findViewById(R.id.share_layout); | |
| shareLayout.setLayoutParams(new LinearLayout.LayoutParams(2048, 1536)); | |
| Bitmap b = PictureUtils.loadBitmapFromView(shareLayout); | |
| PictureUtils.saveBitmap(b, false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static Bitmap loadBitmapFromView(View v) { | |
| Bitmap b = Bitmap.createBitmap( v.getLayoutParams().width, v.getLayoutParams().height, Bitmap.Config.ARGB_8888); | |
| Canvas c = new Canvas(b); | |
| v.layout(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()); | |
| v.draw(c); | |
| return b; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static String saveBitmap(Bitmap bm, File mediaStorageDir, String fileName) { | |
| // Create a media file name | |
| File mediaFile = new File(mediaStorageDir.getPath() + File.separator + fileName); | |
| OutputStream fOutputStream = null; | |
| try { | |
| fOutputStream = new FileOutputStream(mediaFile); | |
| bm.compress(Bitmap.CompressFormat.JPEG, 90, fOutputStream); | |
| fOutputStream.flush(); | |
| fOutputStream.close(); | |
| return mediaFile.getPath(); | |
| } catch (Exception ex) { | |
| ex.printStackTrace(); | |
| return null; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment