Mysql
 sql >> डेटाबेस >  >> RDS >> Mysql

एकाधिक फ़ोटो लेने के लिए Android कैमरा

सहेजने से पहले स्क्रीन पर छवि दिखाएं:

मेरे कोड का प्रयोग करें। मैं कैमरे के इरादे का उपयोग करके एक तस्वीर ले रहा हूं और इसे गैलरी में सहेजने से पहले, यह उपयोगकर्ता को सहेजें और रद्द करें बटन के साथ दिखाया जाता है:- कैमरा इरादा कॉल करें:-

// 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){}
      }
 }
}

अपने किए को लागू करें और क्लिक श्रोता पर रद्द करें - आप उनमें क्या करना चाहते हैं। मेरा कोड आपकी छवि को कैप्चर करेगा, कैमरा घुमाए जाने के बावजूद इसे सही दिशा में घुमाएगा और इसे सहेजने से पहले आपको एक संवाद में दिखाएगा

यह कोड आपकी इमेज को डीबी में स्टोर करेगा। आपको इमेज को स्टोर करने के लिए "ब्लॉब" का उपयोग करना होगा।

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() ;

}

डिवाइस कैमरे के लिए एक वैकल्पिक इरादा कार्रवाई है जो कैमरा को स्थिर छवि मोड में लॉन्च करती है और तब तक बाहर नहीं निकलती जब तक कि उपयोगकर्ता गतिविधि के साथ समाप्त नहीं हो जाता:

Intent intent = new Intent(
    MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
this.startActivity(intent);

ContentObserver के साथ प्रयुक्त यह वही था जो मुझे पूरा करने के लिए आवश्यक था। या इसे ActivityResult में हैंडल करें।

नोट :- यदि आप Android के लिए नए हैं, तो यह आपके लिए अभी समझना बहुत कठिन है। कृपया पहले Google पर Android दस्तावेज़ पढ़ें और ट्यूटोरियल पढ़ें। बेसिक ऐप बनाएं। पहले जानें




  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. WebApp (Tomcat-jdbc) पूल किया गया DB कनेक्शन परित्याग अपवाद फेंक रहा है

  2. MySQL PHP असंगति

  3. मैसकल डेटाबेस में मास डेटा डालने का सबसे तेज़ तरीका

  4. MySQL क्वेरी टाइमिंग आउट:(70100):क्वेरी निष्पादन बाधित हो गया था

  5. MySQL डेटाबेस से BLOB इमेज पढ़ना