The image quality reduced when capture - java

I have finished the camera module for my text recognizer app, but the image quality is too low, the Text detector engine sometimes cant get any text from image. It still look good in preview, my phone is Pixel XL, so i think it not the camera problem. Maybe when i pass the image's bitmap to Text detector activity, it reduced the quality, how can i recover?
am using intent.putExtra to pass the bitmap, this is my code:
Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
#Override
public void onPictureTaken(byte[] data, Camera camera) {
Intent intent = new Intent(MainActivity.this, GetTextActivity.class);
intent.putExtra("key", data);
startActivity(intent);
}
};
and this is in the receiver:
byte[] byteArray = getIntent().getByteArrayExtra("key");
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
imgCaptured.setImageBitmap(bmp);
//text recognizer
TextRecognizer textRecognizer = new TextRecognizer.Builder(getApplicationContext()).build();
if (!textRecognizer.isOperational()) {
Log.w("MainActivity_capture", "Detector is not available");
} else {
Frame frame = new Frame.Builder().setBitmap(bmp).build();
SparseArray<TextBlock> items = textRecognizer.detect(frame);
StringBuilder sb = new StringBuilder();
for(int i=0;i<items.size();i++){
TextBlock item = items.valueAt(i);
sb.append(item.getValue());
sb.append("\n");
}
tvGetText.setText(sb);
}

Related

How can I add my application's shortcut to the homescreen like the one of 360 security

I want to create my app's shortcut/launcher icon on the homescreen like the one of 360 security and release an activity when user click's on the icon without entering in the app
private void addShortcut() {
//Adding shortcut for MainActivity
//on Home screen
Intent shortcutIntent = new Intent(getApplicationContext(), MainActivity.class);
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
shortcutIntent.putExtra(Constants.DEVICE_NO, mDevice.getFDeviceNo());
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, mDevice.getFName());
int defaultImageRes = Utils.getDeviceImage(mDevice.getFViewType());
int color = Color.RED;
Bitmap defaultBitmap = overlay(BitmapFactory.decodeResource(getResources(), defaultImageRes), color);
if (mDevice.isCustomImage() && !mDevice.getFImage().isEmpty()) {
File file = MyApplication.getImageLoader(this).getDiskCache().get(ImageUtils.getImageUrl(mDevice.getFImageName()));
}
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
if (bitmap != null) {
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, 128, 128, true);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, scaledBitmap);
} else {
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, defaultBitmap);
}
} else {
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, defaultBitmap);
}
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
Toast.makeText(this, R.string.added_to_home_screen, Toast.LENGTH_SHORT).show();
}

Bitmap received from camera has wrong orientation / rotated

I am using Camera intent to capture a photo on android, when intent from onActivityResult returns bitmap it has wrong orientation on some phones.
I know there are ways to fix this,but all the solutions I have seen talk about image stored in file.
What I am retrieving from intent is directly bitmap image. I want to know how I can get exif data of a bitmap and then correct its orientation. I repeat I have seen answers which deal with file and not bitmap, so please consider this before down voting.
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, Constants.CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
And result is as follows
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
How to get orientation and rotate it.
UPDATE
Exif is a file format that inserts some information data to JPEG.
https://www.media.mit.edu/pia/Research/deepview/exif.html
And Bitmap is data structior data holds row pixel data, no exif info.
So I think it is impossible to get exif info from Bitmap.
There is no method to get exif info.
https://developer.android.com/reference/android/graphics/Bitmap.html
ORIGINAL
I agree with #DzMobNadjib .
I think the info of rotation is only in exif.
To take exif, I recommend you to take following steps.
1. Start camera activity with file path.
See [Save the Full-size Photo] capture of this document.
You can start the camera activity with file path.The camera activity will save the image to the file path that you passed.
2. In 'onActivityResult', Follow this answer (as #DzMobNadjib suggested)
Your code will be like this:
(Sorry I'm not tested. Please read carefuly and follow the above answer)
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == Constants.CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
Uri uri = data.getData();
Bitmap bitmap = getAdjustedBitmap(uri);
}
}
}
private Bitmap getAdjustedBitmap(Uri uri) {
FileInputStream is = null;
try {
ExifInterface exif = new ExifInterface(uri.getPath());
int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
int rotationInDegrees = exifToDegrees(rotation);
Matrix matrix = new Matrix();
if (rotation != 0f) {
matrix.preRotate(rotationInDegrees);
}
is = new FileInputStream(new File(uri.getPath()));
Bitmap sourceBitmap = BitmapFactory.decodeStream(is);
int width = sourceBitmap.getWidth();
int height = sourceBitmap.getHeight();
return Bitmap.createBitmap(sourceBitmap, 0, 0, width, height, matrix, true);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
}
return null;
}
private static int exifToDegrees(int exifOrientation) {
if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) { return 90; }
else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) { return 180; }
else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) { return 270; }
return 0;
}

LIBGDX, ANDROID: deadlock killing app when when returning captured picture

I have been trying for the past two or three days to build a program that allows the user to take a picture using the native camera or pick one from the gallery. After, getting a picture from either method, the picture is returned to the core libgdx project for processing. Picking from the gallery works like a charm. And the take a picture method, if returned as thumbnail it works perfectly.
However, I would like use a resized photo instead of a thumbnail. The application keeps crashing with "AndroidGraphics: deadlock kill" error. Code speaks louder than words.
public void takePicture() {
selectedImagePath = null;
selectedByteArray = null;
/* when thumbnail
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if(intent.resolveActivity(getPackageManager())!=null) {
startActivityForResult(intent, SELECT_TAKEPICTURE_CODE);
}
*/
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = timeStamp + ".jpg";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
pictureImagePath = storageDir.getAbsolutePath() + "/" + imageFileName;
File file = new File(pictureImagePath);
Uri outputFileUri = Uri.fromFile(file);
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(cameraIntent, SELECT_TAKEPICTURE_CODE);
}
Handling the activity.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode==RESULT_CANCELED||data==null) {
didUserCancel = true;
}
/* Also for the thumbnail use
if (requestCode == SELECT_TAKEPICTURE_CODE&&resultCode==RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
selectedByteArray = convertBitmapToByteArray(imageBitmap);
}
*/
if (requestCode == SELECT_TAKEPICTURE_CODE&&resultCode==RESULT_OK) {
File imgFile = new File(pictureImagePath);
if (imgFile.exists()) {
pictureCaptured = true;
}
}
}
Three helper methods
private Bitmap scaleDownBitmap(Bitmap realImage, float maxImageSize, boolean filter) {
float ratio = Math.min( maxImageSize / (float)realImage.getWidth(),
maxImageSize / (float)realImage.getHeight());
int width = Math.round( ratio * (float)realImage.getWidth());
int height = Math.round( ratio * (float)realImage.getHeight());
Bitmap newBitmap = Bitmap.createScaledBitmap(realImage, width, height, filter);
return newBitmap;
}
private byte[] convertBitmapToByteArray(Bitmap bmp, int quality) {
if(quality>100)
quality = 100;
if(quality<0)
quality = 0;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, quality, stream);
byte[] byteArray = stream.toByteArray();
return byteArray;
}
#Override
public byte[] getCapturedPictureAsByteArray(float imageSize, boolean smoothFilter, int quality) {
Bitmap bitmap = getBitmapFromPath(pictureImagePath);
Bitmap scaledDownBitmap = scaleDownBitmap(bitmap, imageSize, smoothFilter);
selectedByteArray = convertBitmapToByteArray(scaledDownBitmap, quality);
return selectedByteArray;
}
Now for a rough version of the code on the core Game side:
if(gameMode==GameMode.setTextureFromCapturedPicture) {
float imageSize = 100; boolean smoothFilter = true; int quality = 10;
texture = byteArrayToTexture(rootApp.galleryOpener.getCapturedPictureAsByteArray(imageSize, smoothFilter, quality));
gameMode = GameMode.play;
}
For converting from byte[] to texture.
private Texture byteArrayToTexture(byte[] bytes) {
try {
Pixmap pmap =new Pixmap(bytes, 0, bytes.length);
Texture tex =new Texture(pmap);
return tex;
} catch(Exception e) {
e.printStackTrace();
}
return null;
}
The error is I take a picture it takes me back to the libgdx's previous screen (in my case the menu screen). When I search the phone's Gallery I find that picture and can view it without issues. Furthermore, when I run my Game again, and chose that lastly picked picture, it works :s
The saddest part is that the error cannot be generated repeatedly. It just crashes. However, the most frequent errors I am getting are
com.*.*.game/Zygote: v2
com.*.*.game E/Zygote: accessInfo : 0
OR
com.*.*.game waiting for pause synchronization took too long; assuming deadlock and killing
The way I do it is this; Tell the intent where you want to store the image from the camera, otherwise nothing is stored:
File file = new File(Environment.getExternalStorageDirectory() + IMAGE_FOLDER + File.separator + "temp_image.jpg");
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
takePictureIntent.putExtra(PhotoStatics.OUTPUT_FORMAT, Bitmap.CompressFormat.JPEG.toString());
startActivityForResult(takePictureIntent, PhotoStatics.REQUEST_IMAGE_CAPTURE);
And then we listen for when the photo is done, and grab it from the place we told the camera to store the image...
#Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
//System.out.println("onActivityResult = " + requestCode + " " + resultCode + " " + intent.getAction());
// Photo incoming
if (requestCode == PhotoStatics.REQUEST_IMAGE_CAPTURE) {
if (resultCode == RESULT_OK) { // check if we have something to work with
File file = new File(Environment.getExternalStorageDirectory() + IMAGE_FOLDER + File.separator + "temp_image.jpg");
Uri image_uri = Uri.fromFile(file); // get where the temp is stored
Bitmap imageBitmap = BitmapFactory.decodeFile(image_uri.getPath());
}
}
}
Does this make sense to you?
// Static Globals
public static final String TEMP_IMAGE = "temp_image";
public static final String OUTPUT_FORMAT = "outputFormat";
public static final String IMAGE_FOLDER = "/these_pictures"; // don't forget the / at the beginning.
public static final int REQUEST_IMAGE_CAPTURE = 12; // just internal use.
public static final String IMAGE_TYPE = ".jpg";

I want to open the android camera without saving the picture to gallery

I want the picture to go straight to the ImageView without saving it to gallery if possible. As shown in the screenshot, it will ask to save everytime and will save straight to the gallery. Can this be achieved, or will I have to make my own ImageView camera?
public class Main extends Activity {
ImageView ivPhoto;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ivPhoto = (ImageView) findViewById(R.id.ivPic);
}
public void TakePhoto(View v){
Intent camIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(camIntent,0);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==0){
Bitmap camImage = (Bitmap) data.getExtras().get("data");
ivPhoto.setImageBitmap(camImage);
}
}
Finally got what I wanted. Thanks guys
public class Main extends Activity {
ImageView ivPhoto;
File myFilesDir;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ivPhoto = (ImageView) findViewById(R.id.ivPic);
myFilesDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/com.example.project/files");
System.out.println (myFilesDir);
myFilesDir.mkdirs();
}
public void TakePhoto(View v){
Intent camIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
camIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(myFilesDir.toString()+"/temp.jpg")));
startActivityForResult(camIntent, 0);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==0){
try {
Bitmap cameraBitmap;
cameraBitmap = BitmapFactory.decodeFile(myFilesDir + "/temp.jpg");
Bitmap.createBitmap(cameraBitmap);
ivPhoto.setImageBitmap(cameraBitmap);
}
catch(Exception e){
e.printStackTrace();
}
}
}
}
From my understanding you don't want this to be showing up by any media scanner, like the gallery application. What you should actually do is not store it in a root directory like pictures or sdcard, but store it in your applications data folder in the sdcard in Android/data/package/.
You can get this using: http://developer.android.com/reference/android/content/Context.html#getExternalFilesDir(java.lang.String)
File myFilesDir = getExternalFilesDir(null);
OR
File myFilesDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
Note that it will only work on API versions 8 or above.
If you don't want to use the function you can simply just use:
File myFilesDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + packageName + "/files");
myFilesDir.mkdirs();
Use my Code. I am taking a picture using camera intent and before saving it to gallery , it is showed to the user with a Save and Cancel Button :-
Call Camera Intent :-
String SD_CARD_TEMP_DIR = Environment.getExternalStorageDirectory() + File.separator +CommonFunction.getDateTime()+".jpg"; // Get File Path
Intent takePictureFromCameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
takePictureFromCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(SD_CARD_TEMP_DIR)));
startActivityForResult(takePictureFromCameraIntent, 123);
onActivityResult : -
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_RESULT)
{
if (resultCode == Activity.RESULT_OK)
{
String galleryImatePath = SD_CARD_TEMP_DIR; // make SD_CARD_TEMP_DIR Global so that you can access it here from camera intent or pass it in put Extra method and retrieve it here
File f = new File(galleryImatePath);
try {
Bitmap cameraBitmap = null;
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = false;
bmOptions.inPurgeable = true;
bmOptions.inBitmap = cameraBitmap;
bmOptions.inMutable = true;
cameraBitmap = BitmapFactory.decodeFile(galleryImatePath,bmOptions);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
cameraBitmap.compress(Bitmap.CompressFormat.JPEG, 50, bos);
//To Rotate image Code
ExifInterface exif = new ExifInterface(galleryImatePath);
float rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
System.out.println(rotation);
float rotationInDegrees = exifToDegrees(rotation);
System.out.println(rotationInDegrees);
Matrix matrix = new Matrix();
matrix.postRotate(rotationInDegrees);
final Bitmap rotatedBitmap = Bitmap.createBitmap(cameraBitmap , 0, 0, cameraBitmap.getWidth(), cameraBitmap.getHeight(), matrix, true);
FileOutputStream fos=new FileOutputStream(galleryImatePath);
rotatedBitmap.compress(Bitmap.CompressFormat.JPEG, 50, fos);
fos.write(bos.toByteArray());
cameraBitmap.recycle();
System.gc();
fos.flush();
fos.close();
// To set image in imageview in dialog
Capdialog = new Dialog(AddToDo.this,android.R.style.Theme_NoTitleBar_Fullscreen);
Capdialog.setContentView(R.layout.captiondialog);
Capdialog.setCancelable(false);
TextView cancel = (TextView) Capdialog
.findViewById(R.id.cancel);
TextView done = (TextView) Capdialog.findViewById(R.id.done);
Capdialog.getWindow().setSoftInputMode (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
ImageView img = (ImageView) Capdialog.findViewById(R.id.image);
img.setImageBitmap(rotatedBitmap);
}
catch(Exception e){}
}
}
}
implement your done and cancel on click listener - what you want to do in them.
My code will capture your image, rotate it in the right direction irrespective of camera rotation and show it to you in a dialog before saving it
Google provided a tutorial on this exact topic: Controlling the Camera

Android camera to take multiple photos [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
The problem class:
public class problem extends Activity {
ImageView iv;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.problem);
iv=(ImageView) findViewById(R.id.imageView1);
Button b=(Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
Bitmap bm=(Bitmap) data.getExtras().get("data");
iv.setImageBitmap(bm);
}
}
This is what I wanted to do:
Take multiple photos
show them in the screen
store them in the mysql databse.
I am new to android please tell me how to do that.I searched.But I could not find a answer.
From this code IT TAKE ONLY ONE PHOTO.
Show Image on Screen Before Saving :
Use my Code. I am taking a picture using camera intent and before saving it to gallery , it is showed to the user with a Save and Cancel Button :- Call Camera Intent :-
// This code is to call the camera intent. Basically it will start your camera. Put this code in a button or something
String SD_CARD_TEMP_DIR = Environment.getExternalStorageDirectory() + File.separator +CommonFunction.getDateTime()+".jpg"; // Get File Path
Intent takePictureFromCameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
takePictureFromCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(SD_CARD_TEMP_DIR)));
startActivityForResult(takePictureFromCameraIntent, 123);
onActivityResult : -
// This function is called when you come back to your activity after the intent has finished. Do read android documentation on Google. It will Help
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_RESULT)
{
if (resultCode == Activity.RESULT_OK)
{
String galleryImatePath = SD_CARD_TEMP_DIR; // make SD_CARD_TEMP_DIR Global so that you can access it here from camera intent or pass it in put Extra method and retrieve it here
File f = new File(galleryImatePath);
try {//This code will rotate your image if you have taken the image by rotating the camera
Bitmap cameraBitmap = null;
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = false;
bmOptions.inPurgeable = true;
bmOptions.inBitmap = cameraBitmap;
bmOptions.inMutable = true;
cameraBitmap = BitmapFactory.decodeFile(galleryImatePath,bmOptions);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
cameraBitmap.compress(Bitmap.CompressFormat.JPEG, 50, bos);
//To Rotate image Code
ExifInterface exif = new ExifInterface(galleryImatePath);
float rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
System.out.println(rotation);
float rotationInDegrees = exifToDegrees(rotation);
System.out.println(rotationInDegrees);
Matrix matrix = new Matrix();
matrix.postRotate(rotationInDegrees);
final Bitmap rotatedBitmap = Bitmap.createBitmap(cameraBitmap , 0, 0, cameraBitmap.getWidth(), cameraBitmap.getHeight(), matrix, true);
FileOutputStream fos=new FileOutputStream(galleryImatePath);
rotatedBitmap.compress(Bitmap.CompressFormat.JPEG, 50, fos);
fos.write(bos.toByteArray());
cameraBitmap.recycle();
System.gc();
fos.flush();
fos.close();
// To set image in imageview in dialog. This code will set your image in a custon dialog box "captiondialog". It will contain a full width and height imageview and two textviews - done and cancel. It is upto u what you want to define in the textview's click listener. For example, you can pass the storing image in database in the "Done" textview and "Cancel" textview will dismiss your captiondialog and you app will return to your activity
Capdialog = new Dialog(AddToDo.this,android.R.style.Theme_NoTitleBar_Fullscreen);
Capdialog.setContentView(R.layout.captiondialog);
Capdialog.setCancelable(false);
TextView cancel = (TextView) Capdialog
.findViewById(R.id.cancel);
TextView done = (TextView) Capdialog.findViewById(R.id.done);
Capdialog.getWindow().setSoftInputMode (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
ImageView img = (ImageView) Capdialog.findViewById(R.id.image);
img.setImageBitmap(rotatedBitmap);
}
catch(Exception e){}
}
}
}
implement your done and cancel on click listener - what you want to do in them. My code will capture your image, rotate it in the right direction irrespective of camera rotation and show it to you in a dialog before saving it
This code will store your image in DB.You have to use "blob" to store image.. Use This Code :-
public void insertImageInDb(int id , Bitmap img ) {
byte[] data = bos.toByteArray(); // Use This or the code in comments below
/* ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0, outputStream);
byte[] data = outputStream.toByteArray();*/
insertStatement_logo.bindLong(1, id);
insertStatement_logo.bindBlob(2, data);
insertStatement_logo.executeInsert();
insertStatement_logo.clearBindings() ;
}
There's an alternative intent action for the device camera that launches the camera in still image mode and does not exit until the user is finished with the activity:
Intent intent = new Intent(
MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
this.startActivity(intent);
Used with a ContentObserver this was exactly what I needed to accomplish. or Handle this in ActivityResult.
Note :- if you are new to android, this is too hard for you to understand now. Please read the android documentation first on google and read tutorials. Make basic apps. Learn first

Categories

Resources