I'm taking a picture, when I take it with the rear camera, no problem. But when I choose Front Camera, my thumb is all black.
In my logcat, I have this :
Failed to create thumbnail, removing original android
I'm using the built-in camera app. I should suspect that I need to develop my own camera app, but I remember I could use front camera when using a PhoneGap App.
Here is my code :
To start Intent :
imageFileUri = getContentResolver().insert(
Media.EXTERNAL_CONTENT_URI, new ContentValues());
Intent i = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
imageFileUri);
startActivityForResult(i, code);
To save Pic :
if (resultCode == RESULT_OK) {
// getGPSFixAndUpload(TAKE_PIC_INI);
action = TAKE_PIC_INI;
picName = getPicName(action, 0, 0, 0);
SavePic sp = new SavePic(ctx, imageFileUri, picName, action);
sp.execute();
// Class SavePic
@Override
protected Bitmap doInBackground(Void... params) {
if (mAction == TAKE_PIC_INI || mAction == TAKE_PIC_FIN) {
bmp = ImageUtils.uri2Bitmap(ctx, imageFileUri);
ImageUtils.saveImageToExternalCacheStorage(ctx, bmp, picName);
}
return bmp;
}
public static Bitmap uri2Bitmap(Context ctx, Uri imageFileUri) {
// int dw = 1200;
// int dh = 1200;
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inJustDecodeBounds = true;
Bitmap bmp = null;
Bitmap rotatedBitmap = null;
try {
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = 2; // To reduce memory consumation. The only risk
// is to have a small preview.
InputStream is = ctx.getContentResolver().openInputStream(
imageFileUri);
// OutputStream outStream =
// ctx.getContentResolver().openOutputStream(imageFileUri);
bmp = BitmapFactory.decodeStream(is, null, o2);
// No need to close inputStream, because we don't open it ourselves
int imageHeight = o2.outHeight;
int imageWidth = o2.outWidth;
// String imageType = o2.outMimeType;
// Rotate Bitmap
Matrix matrix = new Matrix();
matrix.postRotate(90);
rotatedBitmap = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(),
bmp.getHeight(), matrix, true);
bmp.recycle();
// Get Screen Dimension
WindowManager wm = (WindowManager) ctx
.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int screenWidth = size.x;
float factor = imageWidth / screenWidth;
int height = Math.round(imageHeight / factor);
// We display the image adapted to display width
rotatedBitmap = getResizedBitmap(rotatedBitmap, screenWidth, height);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return rotatedBitmap;
}
public static void saveImageToExternalCacheStorage(Context context,
Bitmap image, String fileName) {
String fullPath = context.getExternalCacheDir().getAbsolutePath();
Log.e("path", fullPath);
try {
File dir = new File(fullPath);
if (!dir.exists()) {
dir.mkdirs();
}
OutputStream fOut = null;
File file = new File(fullPath, fileName);
file.createNewFile();
fOut = new FileOutputStream(file);
image.compress(Bitmap.CompressFormat.JPEG, 80, fOut);
fOut.flush();
fOut.close();
MediaStore.Images.Media.insertImage(context.getContentResolver(),
(String)file.getAbsolutePath(), file.getName(), file.getName());
} catch (Exception e) {
Log.e("saveToExternalStorage()", "problem");
Log.e("log", e.toString());
}
}
Any Idea???