외부 그림 디렉토리에 비트 맵을 저장하려고 할 때 문제가 있습니다. Bitmap.compress 함수를 사용하여 저장하면 비트 맵의 투명도가 손실되고 배경이 검은 색이됩니다. 그러나 비트 맵을 이미지 뷰로 전달하고 액티비티에 표시하면 이미지가 잘 보이고 투명하게됩니다. 저장하려고 할 때만 투명성이 검은 색으로 변합니다.비트 맵 저장시 투명도가 손실됩니다.
나는 두 비트 맵과 포터 듀플 모드를 사용하여 비트 맵에 경로를 그리고 그려진 경로의 그림 만 표시하고 다른 모든 픽셀은 잘 리거나 투명해야한다고 말해야합니다.
그래서 여기에서는 경로 비트 맵을 생성하기위한 함수이다 :
private void createPathBitmap(RectF rect, Bitmap bitmap, Path path) {
RectF tmpRect = new RectF(rect);
Bitmap src = Bitmap.createBitmap(bitmap, (int) tmpRect.left, (int) tmpRect.top, (int) tmpRect.width(), (int) tmpRect.height());
Bitmap dst = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(dst);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeWidth(mDisplayDensity * SnippetLayer.PATH_DIAMETER);
path.offset(-rect.left, -rect.top);
canvas.drawPath(path, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
RectF srcRect = new RectF(0, 0, rect.width(), rect.height());
canvas.drawBitmap(src, null, srcRect, paint);
BitmapManager.sBitmapSnippet = dst;
}
하고 여기에 외부 저장하는 비트 맵을 저장하는 방법이다 : 사진 경로 만에 도시
SimpleDateFormat dateFormat = new SimpleDateFormat("HH_mm_ss_dd_MM_yyyy");
File snippetFile = new File(picDir, fileName+"_"+dateFormat.format(new Date())+".png");
try {
FileOutputStream fileOutputStream = new FileOutputStream(snippetFile);
BitmapManager.sBitmapSnippet.setHasAlpha(true);
BitmapManager.sBitmapSnippet.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
및 바운딩 박스의 나머지는 검은 색이고 투명하지 않습니다. 모든 도움에 감사드립니다.
같은 문제가 발생합니다. 그걸 해결 했니? – Tooto
안녕하세요, 불행히도 아니지만, 내 PC에서 이미지를 복사하고 이미지 뷰어 프로그램을 열 때 그 이미지가 투명한 배경을 가지고 있다는 것을 알아 냈습니다 ... 아마도 Android의 사진 앱을 사용하면 배경이 검은 색이됩니다 ... – sNore
@sNore 이봐, 나는 같은 문제를 겪고있다. 너 해결 했니? –