안드로이드 개발 질문/답변
(글 수 45,052)
사진붙여주는 앱 만들어야 하는데요,
사진별로 가로길이는 다 같다고 가정하고 세로로 길게 붙이고 싶은데 가능한지 알고싶어요...
그리고 연관된 코드 있으면 팁좀 알려주세요~ 감이 안잡히네요ㅠㅠ
2011.11.14 17:16:53
비트맵 2개 합치는 소스 입니다.
참고하세요.
private void combineImage(Bitmap first, Bitmap second, boolean isVerticalMode, String savePath){
Options option = new Options();
option.inDither = true;
option.inPurgeable = true;
Bitmap bitmap = null;
if(isVerticalMode)
bitmap = Bitmap.createScaledBitmap(first, first.getWidth(), first.getHeight()+second.getHeight(), true);
else
bitmap = Bitmap.createScaledBitmap(first, first.getWidth()+second.getWidth(), first.getHeight(), true);
Paint p = new Paint();
p.setDither(true);
p.setFlags(Paint.ANTI_ALIAS_FLAG);
Canvas c = new Canvas(bitmap);
c.drawBitmap(first, 0, 0, p);
if(isVerticalMode)
c.drawBitmap(second, 0, first.getHeight(), p);
else
c.drawBitmap(second, first.getWidth(), 0, p);
first.recycle();
second.recycle();
try{
FileOutputStream fos = new FileOutputStream(savePath);
bitmap.compress(CompressFormat.JPEG, 100, fos);
fos.close();
bitmap.recycle();
}
catch(Exception e){e.printStackTrace();}
}



2개 합친 크기의 비트맵 생성 후 캔버스에서 그려도 될테구요,.... 아니면 두 이미지가 세로로 있는 뷰를 그대로 캡쳐해버릴수도 있겠네요