List of usage examples for android.media ThumbnailUtils extractThumbnail
public static Bitmap extractThumbnail(Bitmap source, int width, int height)
From source file:com.vishwa.pinit.MainActivity.java
private void loadMapWhenOnline() { setUpMapIfNeeded();//from w w w. j av a2 s .c o m if (mMemoryCache.get("defaultPhoto") == null) { Bitmap defaultPhoto = ThumbnailUtils.extractThumbnail( BitmapFactory.decodeResource(getResources(), R.drawable.default_image), 100, 100); mMemoryCache.put("defaultPhoto", defaultPhoto); } LoadCurrentUserPhotoTask loadUserPhotoTask = new LoadCurrentUserPhotoTask(); loadUserPhotoTask.execute(); mMap.setOnCameraChangeListener(new OnCameraChangeListener() { @Override public void onCameraChange(CameraPosition position) { if (!PinItUtils.isOnline(getApplicationContext())) { PinItUtils.createAlert("Internet connection not found.", "Connect to the Internet and press the refresh button at the top", MainActivity.this); mHasInternet = false; hideNonRefreshMenuItems(); mMap.getUiSettings().setAllGesturesEnabled(false); mMap.getUiSettings().setZoomControlsEnabled(false); mMap.getUiSettings().setZoomGesturesEnabled(false); } else if (mMapEditMode == MapEditMode.DEFAULT_MODE) { mHasInternet = true; LatLngBounds mapBounds = mMap.getProjection().getVisibleRegion().latLngBounds; LatLng southwest = mapBounds.southwest; LatLng northeast = mapBounds.northeast; Iterator<Marker> iterator = mMarkerList.iterator(); while (iterator.hasNext()) { Marker marker = iterator.next(); if (!mapBounds.contains(marker.getPosition())) { if (mFocusedMarker != null) { if (marker.getId().equals(mFocusedMarker.getId())) { mFocusedMarker.hideInfoWindow(); hideNoteEditButtons(); mFocusedMarker = null; } } Note note = mNoteStore.get(marker.getId()); mNoteStore.remove(marker.getId()); mReverseNoteStore.remove(note.getNoteId()); marker.remove(); iterator.remove(); } } if (mMapViewMode == MapViewMode.YOUR_NOTES) { LatLngTuple tuple = new LatLngTuple(southwest, northeast); LoadNotesTask currentUserNotesTask = new LoadNotesTask(tuple, true); currentUserNotesTask.execute(); } else { LatLngTuple tuple = new LatLngTuple(southwest, northeast); LoadNotesTask currentUserNotesTask = new LoadNotesTask(tuple, false); currentUserNotesTask.execute(); } } } }); }
From source file:com.sythealth.fitness.util.Utils.java
public static Bitmap getThumbnailBitmap(String pathName) { // DisplayImageOptions options = new DisplayImageOptions.Builder(); BitmapFactory.Options opts = new BitmapFactory.Options(); ///*ww w .jav a2 s .c om*/ opts.inTempStorage = new byte[100 * 1024]; // opts.inPreferredConfig = Bitmap.Config.RGB_565; opts.inPurgeable = true; //size?1/4 inSampleSize ? opts.inSampleSize = 4; opts.inInputShareable = true; Bitmap bitmap = BitmapFactory.decodeFile(pathName, opts); bitmap = ThumbnailUtils.extractThumbnail(bitmap, 135, 135); return bitmap; }
From source file:ca.ualberta.cmput301w14t08.geochan.fragments.EditFragment.java
/** * Overriden method from Fragment. Sets the image and thumbnail in the comment being * edited to the user selected image. Is called automatically after the user * returns from selecting an image from either the camera or photo gallery. * /*from w w w. j a v a 2 s . co m*/ * @param requestCode The request code supplied to startActivityForResult. * @param resultCode The result code returned by the activity. * @param data The data returned by the activity. */ @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Bitmap image = null; if (resultCode == Activity.RESULT_OK) { if (requestCode == ImageHelper.REQUEST_CAMERA) { Bitmap imageBitmap = null; try { imageBitmap = BitmapFactory.decodeStream( getActivity().getContentResolver().openInputStream(Uri.fromFile(imageFile))); } catch (FileNotFoundException e) { Toaster.toastShort("Error. Could not load image."); } image = scaleImage(imageBitmap); } else if (requestCode == ImageHelper.REQUEST_GALLERY) { Bitmap imageBitmap = null; try { imageBitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), data.getData()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } image = scaleImage(imageBitmap); } } editComment.setImage(image); Bitmap imageThumb = ThumbnailUtils.extractThumbnail(image, 100, 100); editComment.setImageThumb(imageThumb); }
From source file:com.pavlospt.rxfile.RxFile.java
public static Observable<Bitmap> getThumbnailFromPath(String filePath) { final Bitmap sourceBitmap = BitmapFactory.decodeFile(filePath); return Observable.fromCallable(new Func0<Bitmap>() { @Override//from w w w .j a v a 2 s . c o m public Bitmap call() { return ThumbnailUtils.extractThumbnail(sourceBitmap, sourceBitmap.getWidth(), sourceBitmap.getHeight()); } }); }
From source file:ca.ualberta.cmput301w14t08.geochan.fragments.PostFragment.java
/** * Handles the return from the camera activity * //from w w w . j a v a 2s. c o m * @param requestCode Type of activity requested * @param resultCode Code indicating activity success/failure * @param data Image data associated with the camera activity */ public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { if (requestCode == ImageHelper.REQUEST_CAMERA) { Bitmap imageBitmap = null; try { imageBitmap = BitmapFactory.decodeStream( getActivity().getContentResolver().openInputStream(Uri.fromFile(imageFile))); } catch (FileNotFoundException e) { Toaster.toastShort("Error. Could not load image."); } Bitmap squareBitmap = ThumbnailUtils.extractThumbnail(imageBitmap, 100, 100); image = scaleImage(imageBitmap); imageThumb = squareBitmap; Bundle bundle = getArguments(); bundle.putParcelable("IMAGE_THUMB", imageThumb); bundle.putParcelable("IMAGE_FULL", image); } else if (requestCode == ImageHelper.REQUEST_GALLERY) { Bitmap imageBitmap = null; try { imageBitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), data.getData()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Bitmap squareBitmap = ThumbnailUtils.extractThumbnail(imageBitmap, 100, 100); image = scaleImage(imageBitmap); imageThumb = squareBitmap; Bundle bundle = getArguments(); bundle.putParcelable("IMAGE_THUMB", imageThumb); bundle.putParcelable("IMAGE_FULL", image); } } }
From source file:us.theparamountgroup.android.inventory.EditorActivity.java
/** * Get user input from editor and save pet into database. *///from ww w .ja v a 2 s . co m private void saveShell() { int THUMBSIZE = 75; byte[] thumbImage = null;// byte array variable used to store in data base String photoString; // Read from input fields // Use trim to eliminate leading or trailing white space and convert to a string String nameString = mNameEditText.getText().toString().trim(); String colorString = mColorEditText.getText().toString().trim(); String quantityString = mQuantityTextView.getText().toString().trim(); String priceString = mPriceEditText.getText().toString().trim(); /* check to see if an image taken with the camera or chosen from the device */ if (mUri != null) { photoString = mUri.toString(); // if there is an image make a corresponding thumbnail bitmap image size 75x75 Bitmap bitThumbImage = ThumbnailUtils.extractThumbnail(mBitmap, THUMBSIZE, THUMBSIZE); // convert thumbnail bitmap to byte array thumbImage = getBytes(bitThumbImage); } else { photoString = ""; } // Check if this is supposed to be a new shell // and check if all the fields in the editor are blank if (mCurrentShellUri == null && TextUtils.isEmpty(nameString) || TextUtils.isEmpty(colorString) || TextUtils.isEmpty(photoString) || TextUtils.isEmpty(priceString) || TextUtils.isEmpty(quantityString)) { // Since no fields were modified, we can return early without creating a new shell. // No need to create ContentValues and no need to do any ContentProvider operations. Toast.makeText(this, "All fields must be filled.\n\n Shell Was Not Saved", Toast.LENGTH_LONG).show(); Intent i = getIntent(); finish(); startActivity(i); return; } int quantity = 0; if (!TextUtils.isEmpty(quantityString)) { quantity = Integer.parseInt(quantityString); } double price = 0.0; if (!TextUtils.isEmpty(priceString)) { price = Double.parseDouble(priceString); } // Create a ContentValues object where column names are the keys, // and pet attributes from the editor are the values. ContentValues values = new ContentValues(); values.put(ShellContract.ShellEntry.COLUMN_SHELL_NAME, nameString); values.put(ShellContract.ShellEntry.COLUMN_SHELL_COLOR, colorString); values.put(ShellContract.ShellEntry.COLUMN_SHELL_HOLE, mHole); values.put(ShellContract.ShellEntry.COLUMN_SHELL_TYPE, mType); values.put(ShellContract.ShellEntry.COLUMN_SHELL_PHOTO, photoString); values.put(ShellContract.ShellEntry.COLUMN_SHELL_QUANTITY, quantity); values.put(ShellContract.ShellEntry.COLUMN_SHELL_PRICE, price); values.put(ShellContract.ShellEntry.COLUMN_SHELL_THUMBNAIL, thumbImage); // Determine if this is a new or existing shell by checking if mCurrentShellUri is null or not if (mCurrentShellUri == null) { // This is a NEW shell, so insert a new shell into the provider, // returning the content URI for the new shell. Uri newUri = getContentResolver().insert(ShellContract.ShellEntry.CONTENT_URI, values); // Show a toast message depending on whether or not the insertion was successful. if (newUri == null) { // If the new content URI is null, then there was an error with insertion. Toast.makeText(this, getString(R.string.editor_insert_pet_failed), Toast.LENGTH_SHORT).show(); } else { // Otherwise, the insertion was successful and we can display a toast. Toast.makeText(this, getString(R.string.editor_insert_pet_successful), Toast.LENGTH_SHORT).show(); } } else { // Otherwise this is an EXISTING shell, so update the shell with content URI: mCurrentShellUri // and pass in the new ContentValues. Pass in null for the selection and selection args // because mCurrentShellUri will already identify the correct row in the database that // we want to modify. int rowsAffected = getContentResolver().update(mCurrentShellUri, values, null, null); // Show a toast message depending on whether or not the update was successful. if (rowsAffected == 0) { // If no rows were affected, then there was an error with the update. Toast.makeText(this, getString(R.string.editor_update_pet_failed), Toast.LENGTH_SHORT).show(); } else { // Otherwise, the update was successful and we can display a toast. Toast.makeText(this, getString(R.string.editor_update_pet_successful), Toast.LENGTH_SHORT).show(); } } }
From source file:com.uzmap.pkg.uzmodules.UIMediaScanner.UIMediaScanner.java
public String createThumbPath(String orgPath) { int degree = BitmapToolkit.readPictureDegree(orgPath); Bitmap srcBitmap = BitmapFactory.decodeFile(orgPath); if (srcBitmap == null) { return null; }/*from w w w .j a va2 s . c o m*/ Bitmap createdBitmap = ThumbnailUtils.extractThumbnail(srcBitmap, 157, 157); if (degree != 0) { createdBitmap = BitmapToolkit.rotaingImageView(degree, createdBitmap); } String realPathStr = SDCARD_PATH + "/DCIM/.thumbnails_for_me"; File realPath = new File(realPathStr); if (!realPath.exists()) { realPath.mkdirs(); } File imagePath = new File(realPath, Util.stringToMD5(orgPath) + ".jpg"); /* replace the old ThunmbNail image */ FileOutputStream outStream; try { outStream = new FileOutputStream(imagePath); createdBitmap.compress(Bitmap.CompressFormat.JPEG, 80, outStream); } catch (FileNotFoundException e) { e.printStackTrace(); } return imagePath.getAbsolutePath(); }
From source file:org.appcelerator.titanium.TiBlob.java
@Kroll.method public TiBlob imageAsThumbnail(Number size, @Kroll.argument(optional = true) Number borderSize, @Kroll.argument(optional = true) Number cornerRadius) { Bitmap img = getImage();/*from ww w . j a va 2s.co m*/ if (img == null) { return null; } int thumbnailSize = size.intValue(); Bitmap imageThumbnail = ThumbnailUtils.extractThumbnail(img, thumbnailSize, thumbnailSize); float border = 1f; if (borderSize != null) { border = borderSize.floatValue(); } float radius = 0f; if (cornerRadius != null) { radius = cornerRadius.floatValue(); } if (border == 0 && radius == 0) { return blobFromImage(imageThumbnail); } Bitmap imageThumbnailBorder = TiImageHelper.imageWithRoundedCorner(imageThumbnail, radius, border); return blobFromImage(imageThumbnailBorder); }
From source file:com.owncloud.android.datamodel.ThumbnailsCacheManager.java
public static String addAvatarToCache(String accountName, byte[] avatarData, int dimension) { final String imageKey = "a_" + accountName; Bitmap bitmap = BitmapFactory.decodeByteArray(avatarData, 0, avatarData.length); bitmap = ThumbnailUtils.extractThumbnail(bitmap, dimension, dimension); // Add avatar to cache if (bitmap != null) { addBitmapToCache(imageKey, bitmap); }/*w ww .j av a 2s . c o m*/ return imageKey; }
From source file:org.openmrs.mobile.activities.addeditpatient.AddEditPatientFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == IMAGE_REQUEST && resultCode == Activity.RESULT_OK) { patientPhoto = getPortraitImage(output.getPath()); Bitmap bitmap = ThumbnailUtils.extractThumbnail(patientPhoto, patientImageView.getWidth(), patientImageView.getHeight()); patientImageView.setImageBitmap(bitmap); patientImageView.invalidate();//from w ww.jav a 2s. c o m } }