【发布时间】:2014-05-20 11:33:59
【问题描述】:
我正在尝试将 imageview 转换为 60px 圆形图像,但它没有发生...
我正在尝试的方式是......
File imgFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
"MyCameraApp" + File.separator + "profile_" + userId + ".jpg");
if(imgFile.exists()){
Bitmap correctBmp=null;
ExifInterface exif;
try {
exif = new ExifInterface(imgFile.getPath());
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
int angle = 0;
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
angle = 90;
}
else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
angle = 180;
}
else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
angle = 270;
}
Matrix mat = new Matrix();
mat.postRotate(90);
Bitmap bmp1 = BitmapFactory.decodeStream(new FileInputStream(imgFile), null, null);
/* correctBmp = Bitmap.createBitmap(bmp1, 0, 0, bmp1.getWidth(), bmp1.getHeight(), mat, true);*/
correctBmp = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
Canvas canvas = new Canvas(correctBmp);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(bmp1, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
canvas.drawRoundRect((new RectF(0.0f, 0.0f, bmp1.getWidth(), bmp1.getHeight())), 10, 10, paint);
profileImage.setImageBitmap(correctBmp);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
它正在加载矩形形状的图像,我该怎么办?
请帮忙...
【问题讨论】:
-
为什么不用xml android:background给图片添加圆形背景
-
这不是一个好主意,实际上我这样做了,但没有变得更好看...@IllegalArgument
-
如果您知道图像的高度,我请求使用椭圆形并提供半径,然后您可以指定图像高度的一半的角半径这样做不需要任何 java 代码,所以我认为它值得一枪
-
好的,我明白了,谢谢@Illegal Argument
标签: android bitmap android-canvas