0
현재 진행중인 프로젝트에는 둥근 모서리가 필요합니다 (예 : 불행히도 아이폰의 복사본). 이미지가 다운로드 될 때 모서리가 둥글게 표시됩니다. 여기에디스크에 수정 된 비트 맵 저장
public class ImageRounder {
private Paint paint = new Paint();
private Canvas canvas;
private Rect rect;
private RectF rectF;
final int color = 0xff424242;
@Inject
public ImageRounder() {}
public synchronized Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
.getHeight(), Bitmap.Config.ARGB_8888);
canvas = new Canvas(output);
paint.reset();
rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
rectF = new RectF(rect);
float roundPx = pixels;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(Color.BLACK);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
}
나는 또한 내가 onces 이상을 다운로드하지 않아도 디스크에 이미지를 저장 ... 난 모서리를 둥글게하는 방법입니다. 이것은 내가
하드 말해 모서리
이 ... 저장하고 이미지@Override
public synchronized void saveImage(String id, Bitmap bitmap) throws FileNotFoundException {
FileOutputStream outputStream = context.openFileOutput(id, Context.MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
}
@Override
public synchronized Bitmap getImage(String id) throws FileNotFoundException {
return BitmapFactory.decodeStream(context.openFileInput(id));
}
나는 그것이 다음과 같습니다 디스크에서 이미지를 검색 할 때 문제가를 검색하는 방법입니다 반올림하지만 배경은 검은 색입니다. 이미지 뷰의 배경을 흰색과 투명하게 설정하려고했지만 모서리가 여전히 검은 색으로 표시됩니다.
왜이 사람인지 아시겠습니까?
이 작동하는 것 같다 사용해야합니다, 감사합니다! 그러나 나는 방금 WEBP를 발견했다, 그것은 PNG보다 어떤 이점을 가지고 있나? – jiduvah
잘 알고 있습니다.) WebP와 PNG에 대한 기사가 있습니다 (예 : [here] (http://www.vizworld.com/2010/10/image-comparisons-png-webp-hipix/)) – flav