그래서이 이상한 문제가 있습니다. 9/10 배는 완벽하게 작동하지만 10 %는 전혀 작동하지 않습니다.Android 이미지 뷰 비트 맵 저장
단순히 확대/축소 할 수있는 ImageView가 있습니다. 그 위대한 작품 - 그럼 나는 전화 자체에 imageView 저장하려고합니다. 이것은 대부분의 경우 작동하지만, 때로는 이미지를 검은 색 화면으로 저장합니다 ... 실제로 ImageView에 표시되는 것이 아닙니다.
다음은 이미지 뷰를 저장하는 내 코드입니다 :
protected void saveZoomedImage(){
//create ImageView Bitmap
RelativeLayout tableContent;
tableContent=(RelativeLayout)findViewById(R.id.imgHolder);
tableContent.measure(MeasureSpec.makeMeasureSpec(tableContent.getLayoutParams().width, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(tableContent.getLayoutParams().height,MeasureSpec.EXACTLY));
tableContent.setDrawingCacheEnabled(true);
final Bitmap screenshot = Bitmap.createBitmap(tableContent.getDrawingCache());
tableContent.setDrawingCacheEnabled(true);
//save file
File folder = new File(Environment.getExternalStorageDirectory() + "/thedir");
if(!folder.exists()){
folder.mkdir();
}
String exsistingFileName=Environment.getExternalStorageDirectory().getAbsolutePath() + "/thedir";
FileOutputStream fos = null;
try {
fos = new FileOutputStream(exsistingFileName + "/image.jpg");
screenshot.compress(Bitmap.CompressFormat.JPEG, 90, fos);
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
이 파일의 벌금을 절약 할 수 있지만,이 시대의 작은 % 시대에 어떤 이유로 이미지를 캡처하지 않습니다처럼 그냥 보인다.
장치 설정을이동> 장치> 응용 프로그램> 응용 프로그램 관리자>의 "응용 프로그램"> 권한> :
public static String saveImageInExternalCacheDir(Context context, Bitmap bitmap, String myfileName) {
String fileName = myfileName.replace(' ', '_') + getCurrentDate().toString().replace(' ', '_').replace(":", "_");
String filePath = (context.getExternalCacheDir()).toString() + "/" + fileName + ".jpg";
try {
FileOutputStream fos = new FileOutputStream(new File(filePath));
bitmap.compress(Bitmap.CompressFormat.JPEG, 85, fos);
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
return filePath;
}
'tableContent.setDrawingCacheEnabled (true); '를 두 번 호출합니다. 두 번째로 거짓이라고 했니? – CodeMonkey
ah yes lol- 그게 문제를 일으킬 수 있다고 생각하세요? – user3267847
잘 모르겠습니다. 가능하다고 생각합니다. 그것은 나에게 돋보이는 유일한 것입니다. 10 번째 오류 메시지가 나타나면 게시물을 편집하여 추가하면 도움이됩니다. – CodeMonkey