如何将上传图片(图片来自照片库)的形状更改为圆形
How to change the shape of an uploaded image (Image from photo gallery) into circular form
如何在 android eclipse 中将上传的图像(来自照片库的图像)的形状更改为圆形。
你是这样使用它的:
//this the button which allows you to access the gallery
pic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
gallery();
}
});
//this allows you select one image from gallery
public void gallery() {
intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 1);
}
//when you start activity for result and choose an image, the code will automatically continue here
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
Uri current_ImageURI = data.getData();
selectedImagePath = getPath(current_ImageURI);
image.setImageDrawable(RoundedBitmapDrawableFactory.create(getResources(),selectedImagePath));
}
}
}
public String getPath(Uri contentUri) {
// we have to check for sdk version because from lollipop the retrieval of path is different
if (Build.VERSION.SDK_INT < 21) {
// can post image
String[] proj = {MediaStore.Images.Media.DATA};
Cursor cursor = getActivity().getApplicationContext().getContentResolver().query(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} else {
String filePath = "";
String wholeID = DocumentsContract.getDocumentId(contentUri);
// Split at colon, use second item in the array
String id = wholeID.split(":")[1];
String[] column = {MediaStore.Images.Media.DATA};
// where id is equal to
String sel = MediaStore.Images.Media._ID + "=?";
Cursor cursor = getActivity().getContentResolver().
query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
column, sel, new String[]{id}, null);
int columnIndex = cursor.getColumnIndex(column[0]);
if (cursor.moveToFirst()) {
filePath = cursor.getString(columnIndex);
}
cursor.close();
return filePath;
}
}
现在有以下两个功能:
解码位图的样本大小(以进行正确的缩放)和其他从路径中提取位图也不再使用
圆形位图class不再使用
为了更好地理解,请使用此 link fr 参考:http://developer.android.com/reference/android/support/v4/graphics/drawable/RoundedBitmapDrawableFactory.html
如何在 android eclipse 中将上传的图像(来自照片库的图像)的形状更改为圆形。
你是这样使用它的:
//this the button which allows you to access the gallery
pic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
gallery();
}
});
//this allows you select one image from gallery
public void gallery() {
intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 1);
}
//when you start activity for result and choose an image, the code will automatically continue here
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
Uri current_ImageURI = data.getData();
selectedImagePath = getPath(current_ImageURI);
image.setImageDrawable(RoundedBitmapDrawableFactory.create(getResources(),selectedImagePath));
}
}
}
public String getPath(Uri contentUri) {
// we have to check for sdk version because from lollipop the retrieval of path is different
if (Build.VERSION.SDK_INT < 21) {
// can post image
String[] proj = {MediaStore.Images.Media.DATA};
Cursor cursor = getActivity().getApplicationContext().getContentResolver().query(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} else {
String filePath = "";
String wholeID = DocumentsContract.getDocumentId(contentUri);
// Split at colon, use second item in the array
String id = wholeID.split(":")[1];
String[] column = {MediaStore.Images.Media.DATA};
// where id is equal to
String sel = MediaStore.Images.Media._ID + "=?";
Cursor cursor = getActivity().getContentResolver().
query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
column, sel, new String[]{id}, null);
int columnIndex = cursor.getColumnIndex(column[0]);
if (cursor.moveToFirst()) {
filePath = cursor.getString(columnIndex);
}
cursor.close();
return filePath;
}
}
现在有以下两个功能: 解码位图的样本大小(以进行正确的缩放)和其他从路径中提取位图也不再使用
圆形位图class不再使用
为了更好地理解,请使用此 link fr 参考:http://developer.android.com/reference/android/support/v4/graphics/drawable/RoundedBitmapDrawableFactory.html