카메라로 부터 사진을 찍어 byte array 로 받은 수 drawable 로 변환시킨 뒤
ColorFilter 를 적용하여 이미지를 파일로 저장하려고 합니다.
오류는 없는데, ColorFilter 가 적용되지 않는 원본만 저장이 됩니다.
ColorFilter 에 의해 변경된 Drawable 은 어떻게 저장하면 되나요?
도와주세요...
Camera.PictureCallback mPicture = new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] bytes, Camera camera) {
mView.mRenderer.restartPreview();
String storageDir = Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/" + Environment.DIRECTORY_DCIM + "/Camera";
File dir = new File(storageDir);
if (!dir.exists()) dir.mkdir();
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String path = storageDir + "/IMG_" + timeStamp + ".jpg";
File file = new File(path);
try {
ColorMatrix matrix = new ColorMatrix(new float[] {
1, 0, 0, 0, mView.mRenderer.mTest,
0, 1, 0, 0, mView.mRenderer.mTest,
0, 0, 1, 0, mView.mRenderer.mTest,
0, 0, 0, 1, 0
});
Drawable image = new BitmapDrawable(BitmapFactory.decodeByteArray(bytes, 0, bytes.length));
image.setColorFilter(new ColorMatrixColorFilter(matrix));
Bitmap bitmap = ((BitmapDrawable)image).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bytedata = stream.toByteArray();
FileOutputStream fos = new FileOutputStream(file);
fos.write(bytedata);
fos.flush();
fos.close();
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri uri = Uri.parse("file://" + path);
intent.setData(uri);
sendBroadcast(intent);
}
catch (Exception e) {
Log.e("CheckLog", e.getMessage());
return;
}
}
};
위 코드에서 mView.mRenderer.mTest 는 시크바에 의해 변경되는 값 입니다.