Daniel,

In my case, the large image is read from storage resized then saved to
storage.

Dave Truby
 On Apr 12, 2015 12:37 AM, "Daniel Chacon" <cuban...@gmail.com> wrote:

> So what you are doing is resizing before or after being saved or uploaded?
>
> On Sat, Apr 11, 2015 at 6:59 AM, Dave Truby <detr...@gmail.com> wrote:
>
>> Dan,
>>
>> I am doing the following in my Over Time app. Maybe it helps you.
>>
>>
>> File aThumbnail = new File(pDir, TbsFile.THUMBNAIL_FILENAME);
>>
>> final float aRatio = (float) pPictureWidth / (float) pPictureHeight;
>>
>>  final int aThumbnailWidth = Math.round(pThumbnailHeight * aRatio);
>>
>> final BitmapFactory.Options anOptions = new BitmapFactory.Options();
>>
>>  anOptions.inJustDecodeBounds = false;
>>
>>  anOptions.inSampleSize = this.calculateInSampleSize(pPictureWidth,
>> pPictureHeight, aThumbnailWidth, pThumbnailHeight);
>>
>> Bitmap aBitmap =
>> BitmapFactory.decodeFile(pImageToMakeThumbnail.getAbsolutePath(),
>> anOptions);
>>
>> Bitmap aScaledBitmap = Bitmap.createScaledBitmap(aBitmap,
>> aThumbnailWidth, pThumbnailHeight, true);
>>
>>   this.saveThumbnail(pContext, aThumbnail, aScaledBitmap);
>>
>>    aScaledBitmap.recycle();
>>
>>   }
>>
>>  private int calculateInSampleSize(final int pPictureWidth, final int
>> pPictureHeight,
>>
>>  final int pThumbnailWidth, final int pThumbnailHeight) {
>>
>>  int aInSampleSize = 1;
>>
>>  if (pPictureHeight > pThumbnailHeight || pPictureWidth >
>> pThumbnailWidth) {
>>
>>  final int aHeightRatio = Math.round((float) pPictureHeight / (float)
>> pThumbnailHeight);
>>
>> final int aWidthRatio = Math.round((float) pPictureWidth / (float)
>> pThumbnailWidth);
>>
>>  aInSampleSize = aHeightRatio < aWidthRatio ? aHeightRatio : aWidthRatio;
>>
>>  }
>>
>>  return aInSampleSize;
>>
>> }
>>
>>  private void saveThumbnail(final Context pContext, final File
>> pThumbnail, final Bitmap pScaledBitmap) {
>>
>>  boolean isCreated = false;
>>
>>  FileOutputStream anOutputStream = null;
>>
>>  try {
>>
>>  anOutputStream = new FileOutputStream(pThumbnail);
>>
>> pScaledBitmap.compress(Bitmap.CompressFormat.JPEG,
>>
>>   TbsCreateThumbnailAsyncTask.JPEG_COMPRESSION, anOutputStream);
>>
>>  isCreated = true;
>>
>>  } catch (IOException anIoEx) {
>>
>>  this.error("saveThumbnail()", anIoEx);
>>
>>  } catch (Exception anEx) {
>>
>>  this.error("saveThumbnail()", anEx);
>>
>>  } finally {
>>
>>  if (null != anOutputStream) {
>>
>>   try {
>>
>>   anOutputStream.close();
>>
>>   } catch (IOException e) {
>>
>>   // nothing
>>
>>   }
>>
>>  }
>>
>>  if (isCreated) {
>>
>>   MediaScannerConnection.scanFile(pContext,
>>
>>    new String[] { pThumbnail.getAbsolutePath() }, null,
>>
>>    new MediaScannerConnection.OnScanCompletedListener() {
>>
>>    @Override
>>
>>    public void onScanCompleted(final String pPath, final Uri pUri) {
>>
>>     TbsCreateThumbnailAsyncTask.this.info("onScanCompleted()", "Scanned
>> thumbnail " + pPath + TbsLog.PERIOD);
>>
>>    }
>>
>>    });
>>
>>  }
>>
>>  }
>>
>> }
>>
>>
>> On Friday, April 10, 2015 at 5:27:42 PM UTC-4, Dan Cha wrote:
>>>
>>> So ive been reading a few posts some using Bitmap.createScaledBitmap,
>>> some using .compress feature and each one i try, never throws an exception
>>> or error, but file never gets resized.
>>>
>>> I found this routine, but it doesnt do anything as far as the image
>>> taken. So basically within my app i allow the user to take a pic to attach
>>> to the submission.
>>> When you take the image, it displays a thumbnail on the screen, at this
>>> point the image is already saved to the phones gallery.
>>> I need to resize it (without changing the proportions) to make sure that
>>> the image is no larger than 200px wide or high because once you submit the
>>> form, im uploading the image to our server.
>>>
>>> public Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) {
>>>     int width = bm.getWidth();
>>>     int height = bm.getHeight();
>>>     float scaleWidth = ((float) newWidth) / width;
>>>     float scaleHeight = ((float) newHeight) / height;
>>>     // CREATE A MATRIX FOR THE MANIPULATION
>>>     Matrix matrix = new Matrix();
>>>     // RESIZE THE BIT MAP
>>>     matrix.postScale(scaleWidth, scaleHeight);
>>>
>>>     // "RECREATE" THE NEW BITMAP
>>>     Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, 
>>> matrix, false);
>>>     return resizedBitmap;}
>>>
>>>
>>> When the user clicks the image button on the screen, the camera opens and 
>>> allows them to take the pic, ive tried to call the above routine within 
>>> this event after everything so that i know the file is created and exists.
>>>
>>>
>>> Here is the event for that:
>>>
>>>     private ImageButton.OnClickListener takePicture_Button_listener = new 
>>> ImageButton.OnClickListener()
>>>     {
>>>         public void onClick(View v)
>>>         {
>>>             StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
>>>                     .detectDiskReads()
>>>                     .detectDiskWrites()
>>>                     .detectNetwork()
>>>                     .penaltyLog()
>>>                     .build());
>>>             // create Intent to take a picture and return control to the 
>>> calling application
>>>             Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
>>>
>>>             //User fileUri for full path to image taken.
>>>             fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a 
>>> file to save the image
>>>             fname = 
>>> fileUri.toString().substring(fileUri.toString().lastIndexOf("/")+1);
>>>             intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the 
>>> image file name
>>>
>>>             // start the image capture Intent
>>>             startActivityForResult(intent, 
>>> CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
>>>         }
>>>     };
>>>
>>>
>>> Ive tried to use it here after the previewCapturedImage routine is called 
>>> and ive even tried the currently commented out code seen below and neither 
>>> modify the file.
>>>
>>>
>>>     protected void onActivityResult(int requestCode, int resultCode, Intent 
>>> data)
>>>     {
>>>         if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE && 
>>> resultCode == RESULT_OK)
>>>         {
>>>             previewCapturedImage();
>>>             //Bitmap bitmap = BitmapFactory.decodeFile(fileUri.getPath());
>>>             //getResizedBitmap(bitmap,200,200);
>>>         }
>>>         else if (resultCode == RESULT_CANCELED)
>>>         {
>>>         // User cancelled the image capture
>>>             Toast.makeText(this, "Image Capture Cancelled:\n" +
>>>                     data.getData(), Toast.LENGTH_LONG).show();
>>>         }
>>>         else
>>>         {
>>>         // Image capture failed, advise user
>>>             Toast.makeText(this, "Image Capture Failed:\n" +
>>>                     data.getData(), Toast.LENGTH_LONG).show();
>>>         }
>>>     }
>>>
>>>
>>> Where can i properly resize the image, either during or after its taken so 
>>> that the actual image stored on the device is within my size requirements 
>>> and file size, currently since its not resizing its creating a 4mb file 
>>> which takes forever to upload and has some huge dimensions(5213x2988) I 
>>> just need to make sure that the full size image is no larger than 200px 
>>> width or height, it obvisously needs to keep its proportions, but the max 
>>> cant be any larger than 200px
>>>
>>>  --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to android-developers@googlegroups.com
>> To unsubscribe from this group, send email to
>> android-developers+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Android Developers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to android-developers+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "Android Developers" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/android-developers/pnv77NjKI5c/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> android-developers+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to