Jak przekonwertować bitmapę na Drawable w Androidzie?
Jak przekonwertować obraz bitmapowy na Drawable ?
Dzięki, Farha
8 answers
Brzmi jakbyś chciał użyć BitmapDrawable
Z dokumentacji:
A
Drawable
który otacza bitmapę i może być wyłożone kafelkami, rozciągnięte lub wyrównane. Ty można utworzyćBitmapDrawable
z ścieżka do pliku, strumień wejściowy, przez Inflacja XML, lub zBitmap
obiekt.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-07-18 12:19:16
Try this to converts a Bitmap
type image to Drawable
Drawable d = new BitmapDrawable(getResources(), bitmap);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-04-15 13:41:19
Po zaobserwowaniu dużej liczby problemów z nieprawidłowym skalowaniem bitmap po przekonwertowaniu do BitmapDrawable
, ogólnym sposobem konwersji powinien być:
Drawable d = new BitmapDrawable(getResources(), bitmap);
Bez Resources reference
, bitmap
może nie renderować poprawnie, nawet jeśli jest poprawnie skalowany. Istnieje tu wiele pytań, które można by rozwiązać po prostu za pomocą tej metody, a nie prostego wywołania tylko z argumentem bitmap
.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-04-15 13:42:10
Oficjalna Bitmapdrawable Dokumentacja
Oto przykład jak przekonwertować bitmapę na drawable
Bitmap bitmap;
//Convert bitmap to drawable
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
imageView.setImageDrawable(drawable);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-01-19 08:41:57
Jeśli masz obraz bitmapowy i chcesz go użyć w drawable, jak
Bitmap contact_pic; //a picture to show in drawable
drawable = new BitmapDrawable(contact_pic);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-01-19 08:41:31
I used with context
//Convert bitmap to drawable
Drawable drawable = new BitmapDrawable(context.getResources(), bitmap);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-10-13 00:06:25
Po prostu zrób to:
private void setImg(ImageView mImageView, Bitmap bitmap) {
Drawable mDrawable = new BitmapDrawable(getResources(), bitmap);
mImageView.setDrawable(mDrawable);
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-07-23 16:55:43
Oto kolejny:
Drawable drawable = RoundedBitmapDrawableFactory.create(context.getResources(), bitmap);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-04-09 07:09:36