我正在尝试在Android应用程序中更改Google Maps标记,因此尝试了这种方式:
mMap.addMarker(new MarkerOptions().position(player).title("player").icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher_foreground)));
但是它说我必须使用位图图像,我该怎么办?
FATAL EXCEPTION: main Process: com.example.crosilla.mappeprova2, PID: 18930
com.google.maps.api.android.lib6.common.apiexception.b: Failed to decode image. The provided image must be a Bitmap
答案 0 :(得分:0)
您的代码看起来还不错。尝试使用mipmap文件夹中的资源。
答案 1 :(得分:-1)
call this on button click:
startActivityForResult(Intent.createChooser(intent, "Select Picture"), RESULT_LOAD_IMAGE);
then :
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
dialog = new ProgressDialog(PhotoUpload.this);
dialog.setMessage("Please wait......");
dialog.setCancelable(false);
dialog.show();
Uri selectedImage = data.getData();
SharedPreferences sharedPreferences = getSharedPreferences("SavedPhoto", Context.MODE_PRIVATE);
Bitmap photo = null;
try {
photo = MediaStore.Images.Media.getBitmap(getContentResolver(), selectedImage);
} catch (IOException e) {
e.printStackTrace();
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
String encodedImage = Base64.encodeToString(b, Base64.DEFAULT);
byte[] decodedString = Base64.decode(encodedImage , Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
CircularImageView imageView = findViewById(R.id.profileimage);
imageView.setImageBitmap(decodedByte);
}
}