driven by a desire to use innovation and ingenuity to improve peoples' lives
technical humanism

Getting a bitmap from a view

Getting a bitmap from a view is very easy in Android (as long as it has already been laid out on the screen):

Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);

Then you can easily save it to the gallery or email/fb/whatever:

File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/mydirectory/myfilename.png");
FileOutputStream fio = new FileOutputStream(file, false);
bitmap.compress(CompressFormat.PNG, 100, fio);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT, "my subject");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
context.startActivity(Intent.createChooser(intent, context.getString(R.string.intentchooser_share_title)));

This entry was posted in Mobile, Software. Bookmark the permalink.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Facebook Twitter LinkedIn follow us