안드로이드 사진 여러장을 이미지뷰에 넣어 Rounding 처리 하는 방법에 대해 궁금합니다.
조회수 2335회
아래 코드로 Bitmap Round 처리는 하였지만 여러장의 Bitmap을 어떻게 처리해야 될지 감이 잡히질 않습니다.
```언어명(예. java, python, c, ruby) public static Bitmap getRoundBit(Bitmap bitmap , int borderColor) {
Canvas canvas;
Path path = new Path();
Paint paint = new Paint();
int Width = bitmap.getWidth();
int Height = bitmap.getHeight();
float radius = (Math.min(((float) Width), ((float) Height)) / 2);
Bitmap output = Bitmap.createBitmap(Width, Height,Bitmap.Config.ARGB_8888);
canvas = new Canvas(output);
path.addCircle(((float) Width - 1) / 2, ((float) Height - 1) / 2, radius, Path.Direction.CCW);
canvas.clipPath(path);
Bitmap tempBit = bitmap;
paint.setColor(Color.WHITE);
paint.setStrokeWidth(30);
paint.setStyle(Paint.Style.STROKE);
canvas.drawBitmap(tempBit, new Rect(0, 0, tempBit.getWidth(), tempBit.getHeight()), new Rect(0, 0, Width, targetHeight), paint);
canvas.drawCircle(((float) Width - 1) / 2, ((float) targetHeight - 1) / 2 , radius ,paint);
return output;
}
-
(•́ ✖ •̀)
알 수 없는 사용자
1 답변
-
public Bitmap resizeBitmapImage(Bitmap source, int maxResolution) { int width = source.getWidth(); int height = source.getHeight(); int newWidth = width; int newHeight = height; float rate = 0.0f; if(width > height) { if(maxResolution < width) { rate = maxResolution / (float) width; newHeight = (int) (height * rate); newWidth = maxResolution; } } else { if(maxResolution < height) { rate = maxResolution / (float) height; newWidth = (int) (width * rate); newHeight = maxResolution; } } return Bitmap.createScaledBitmap(source, newWidth, newHeight, true); } private Bitmap combineImage(Bitmap b1, Bitmap b2, Bitmap b3, Bitmap b4){ BitmapFactory.Options option = new BitmapFactory.Options(); option.inDither = true; option.inPurgeable = true; Bitmap bitmap = null; b1 = resizeBitmapImage(b1, 500); b2 = resizeBitmapImage(b2, 500); b3 = resizeBitmapImage(b3, 500); b4 = resizeBitmapImage(b4, 500); bitmap = Bitmap.createScaledBitmap(b1, b1.getWidth()+b1.getWidth(), b1.getHeight()+b1.getHeight(), true); Paint p = new Paint(); p.setDither(true); p.setFlags(Paint.ANTI_ALIAS_FLAG); Canvas c = new Canvas(bitmap); c.drawBitmap(b1, 0, 0, p); c.drawBitmap(b2, 0, b1.getHeight(), p); c.drawBitmap(b3, b1.getWidth(), 0, p); c.drawBitmap(b4,b1.getWidth(),b1.getHeight(),p); b1.recycle(); b2.recycle(); b3.recycle(); b4.recycle(); return bitmap; }
이미지 두개를 이어붙이는 예제를 보고 적절하게 수정해봤습니다. 보여주신 예에서 이미지 크기를 동일하게 맞출 필요를 느껴서 비트맵의 사이즈를 리사이징 시키는 메소드도 추가했습니다.
도움이 되셨으면 좋겠네요~
댓글 입력