1. Are you ready for the Galaxy S20? Here is everything we know so far!

Bitmap create

Discussion in 'Android Development' started by venom2124, Jan 6, 2014.

  1. venom2124

    venom2124 Newbie
    Thread Starter

    Okay I've been working on this app for about a week now and I've just about got everything worked out. The only problem I have left is once I take the picture I need to resize it, but I can't seem to figure out what I'm doing wrong. When I tried to use the BitmapFactory to get the file everything looks like it's working fine until it gets to the Bitmap.createScaledBitmap portion of the resized function. If force closes when it gets to that line. Any help with this resize function would be greatly appreciated.

    Code (Text):
    1.  
    2. webView.setWebChromeClient(new WebChromeClient() {
    3.             //Capture image with camera on Android > 3.0
    4.             @SuppressWarnings("unused")
    5.                public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
    6.             openFileChooser(uploadMsg);
    7.              }
    8.  
    9.             //Capture image with camera on Android 3.0+
    10.             @SuppressWarnings("unused")
    11.             public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
    12.                 openFileChooser(uploadMsg);
    13.             }
    14.  
    15.             //Capture image with camera on Android 4.1 to 4.3
    16.             public void openFileChooser(ValueCallback<Uri> uploadMsg) {
    17.                 mUploadMessage = uploadMsg;
    18.                 File imageStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Mobile311_Citizen");
    19.                 fullUrl = imageStorageDir + File.separator + "IMG_" + String.valueOf(System.currentTimeMillis()) + ".jpg";
    20.                 file = new File(fullUrl);
    21.                 Intent capture = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    22.                 capture.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
    23.                 MainActivity.this.startActivityForResult(capture, CAPTURE_RESULTCODE);
    24.                
    25.             }
    26.  
    Code (Text):
    1.  
    2. @Override
    3.      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    4.            // TODO Auto-generated method stub
    5.          super.onActivityResult(requestCode, resultCode, data);
    6.          if(resultCode == RESULT_OK){
    7.              resize(fullUrl);
    8.              if(null == this.mUploadMessage){
    9.                  this.mUploadMessage.onReceiveValue(null);
    10.              }else{
    11.                  ContentValues values = new ContentValues();
    12.                  values.put(MediaStore.Images.Media.DATA, fullUrl);
    13.                  this.mUploadMessage.onReceiveValue(this.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values));
    14.             }
    15.              this.mUploadMessage = null;
    16.          }
    17.      }
    18.  
    Code (Text):
    1.  
    2. private Bitmap resize(String path){
    3.         // create the options
    4.             BitmapFactory.Options opts = new BitmapFactory.Options();
    5.  
    6.         //just decode the file
    7.             opts.inJustDecodeBounds = true;
    8.             Bitmap bp = BitmapFactory.decodeFile(path, opts);
    9.  
    10.         //get the original size
    11.             int orignalHeight = opts.outHeight;
    12.             int orignalWidth = opts.outWidth;
    13.            
    14.             if(orignalWidth > 1000) {
    15.                 int x = orignalWidth / 2;
    16.                 int y = orignalHeight / 2;
    17.                 Bitmap scaled = Bitmap.createScaledBitmap(bp, x, y, true);
    18.                 bp.recycle();
    19.                 bp = scaled;
    20.                 }
    21.             return bp;
    22.     }
    23.  
     



    1. Download the Forums for Android™ app!


      Download

       
  2. venom2124

    venom2124 Newbie
    Thread Starter

    So I was able to figure out where the issue was today at work. I'll try and post the updated fixed code. The first thing I had to do was change the true to a false when it came to the opts.inJustDecodeBounds. The second thing I had to do was make sure that I was creating the new bitmap and saving it back to the sd card. Then I just had to provide that path as the file to be uploaded to the server.
     
Loading...
Similar Threads - Bitmap create
  1. Rhemsuda
    Replies:
    2
    Views:
    263
  2. matthewpederson
    Replies:
    0
    Views:
    194
  3. Dan Coleman
    Replies:
    0
    Views:
    253
  4. Michael Knight
    Replies:
    1
    Views:
    418
  5. pdkandroid
    Replies:
    1
    Views:
    300
  6. BlinkXIO
    Replies:
    1
    Views:
    361
  7. koshinohouse
    Replies:
    7
    Views:
    1,286
  8. 23tony
    Replies:
    1
    Views:
    1,146
  9. Onur Ozbek
    Replies:
    0
    Views:
    322
  10. Nagori
    Replies:
    9
    Views:
    819

Share This Page

Loading...