Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

converting image to bitmap in android

Tags:

android

bitmap

i want to choose a picture from SD card of the mobile. i am using below code to choose and to display in my activity

Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
Uri uri = Uri.parse(selectedImagePath);
uploadimage.setImageURI(uri);

It is working fine, but I want to convert this image into Bitmap, I have image path and URI.

How to convert image to Bitmap in this case? Please help me, thanks in advance.

like image 552
Abhi Avatar asked Aug 04 '11 06:08

Abhi


People also ask

What is a bitmap in Android?

A bitmap is simply a rectangle of pixels. Each pixel can be set to a given color but exactly what color depends on the type of the pixel. The first two parameters give the width and the height in pixels. The third parameter specifies the type of pixel you want to use.

How do you change a drawable image from a resource to a bitmap?

This example demonstrates how do I convert Drawable to a Bitmap in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do I get bitmap from imageView?

Bitmap bm=((BitmapDrawable)imageView. getDrawable()). getBitmap(); Try having the image in all drawable qualities folders (drawable-hdpi/drawable-ldpi etc.)


1 Answers

use this code

Bitmap bmp=BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
like image 153
ilango j Avatar answered Nov 15 '22 07:11

ilango j