簡體   English   中英

在android中將圖像轉換為位圖

[英]converting image to bitmap in android

我想從手機的 SD 卡中選擇一張圖片。 我正在使用下面的代碼來選擇並顯示在我的活動中

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

它工作正常,但我想將此圖像轉換為Bitmap ,我有圖像路徑和 URI。

在這種情況下如何將圖像轉換為位圖? 請幫助我,提前致謝。

使用此代碼

Bitmap bmp=BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),uri);
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageBitmap(bitmap);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM