List of usage examples for android.graphics Matrix postScale
public boolean postScale(float sx, float sy)
From source file:com.ifoer.util.NetPOSPrinter.java
public Bitmap zoomBitmap(Bitmap target) { int width = target.getWidth(); int height = target.getHeight(); Matrix matrix = new Matrix(); matrix.postScale(384.0f / ((float) width), ((float) ((height * PRINT_WIDTH) / width)) / ((float) height)); return Bitmap.createBitmap(target, 0, 0, width, height, matrix, true); }
From source file:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java
static void setBackground(View v, Bitmap bm) { if (bm == null) { v.setBackgroundResource(0);//from ww w .j a va 2 s .c o m return; } int vwidth = v.getWidth(); int vheight = v.getHeight(); int bwidth = bm.getWidth(); int bheight = bm.getHeight(); float scalex = (float) vwidth / bwidth; float scaley = (float) vheight / bheight; float scale = Math.max(scalex, scaley) * 1.3f; Bitmap.Config config = Bitmap.Config.ARGB_8888; Bitmap bg = Bitmap.createBitmap(vwidth, vheight, config); Canvas c = new Canvas(bg); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setFilterBitmap(true); ColorMatrix greymatrix = new ColorMatrix(); greymatrix.setSaturation(0); ColorMatrix darkmatrix = new ColorMatrix(); darkmatrix.setScale(.3f, .3f, .3f, 1.0f); greymatrix.postConcat(darkmatrix); ColorFilter filter = new ColorMatrixColorFilter(greymatrix); paint.setColorFilter(filter); Matrix matrix = new Matrix(); matrix.setTranslate(-bwidth / 2, -bheight / 2); // move bitmap center to origin matrix.postRotate(10); matrix.postScale(scale, scale); matrix.postTranslate(vwidth / 2, vheight / 2); // Move bitmap center to view center c.drawBitmap(bm, matrix, paint); v.setBackgroundDrawable(new BitmapDrawable(bg)); }
From source file:com.ibuildapp.romanblack.CouponPlugin.CouponAdapter.java
/** * Decode rss item image thad storing in given file * @param imagePath - image file path//from www . jav a 2 s . c o m * @return decoded image Bitmap */ private Bitmap decodeImageFile(String imagePath) { try { File file = new File(imagePath); //Decode image size BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(file), null, opts); //Find the correct scale value. It should be the power of 2. int width = opts.outWidth, height = opts.outHeight; int scale = 1; while (true) { if (width / 2 < imageWidth || height / 2 < imageHeight) { break; } width /= 2; height /= 2; scale *= 2; } //Decode with inSampleSize opts = new BitmapFactory.Options(); opts.inSampleSize = scale; Bitmap bitmap = BitmapFactory.decodeStream(new FileInputStream(file), null, opts); int x = 0, y = 0, l = 0; if (width > height) { x = (int) (width - height) / 2; y = 0; l = height; } else { x = 0; y = (int) (height - width) / 2; l = width; } float matrixScale = (float) (imageWidth - 4) / (float) l; Matrix matrix = new Matrix(); matrix.postScale(matrixScale, matrixScale); return Bitmap.createBitmap(bitmap, x, y, l, l, matrix, true); } catch (Exception e) { } return null; }
From source file:org.zywx.wbpalmstar.plugin.uexscrawl.PhotoScrawlActivity.java
public Bitmap compressionFiller(Bitmap bitmap, View contentView) { float scale = 0f; int bitmapHeight = bitmap.getHeight(); int bitmapWidth = bitmap.getWidth(); scale = bitmapHeight > bitmapWidth ? contentView.getHeight() / (bitmapHeight * 1f) : mScreenWidth / (bitmapWidth * 1f); Bitmap resizeBmp;//ww w . ja v a 2s. co m if (scale != 0) { int bitmapheight = bitmap.getHeight(); int bitmapwidth = bitmap.getWidth(); Matrix matrix = new Matrix(); matrix.postScale(scale, scale); // ? resizeBmp = Bitmap.createBitmap(bitmap, 0, 0, bitmapwidth, bitmapheight, matrix, true); } else { resizeBmp = bitmap; } return resizeBmp; }
From source file:nl.creativeskills.cordova.imageresize.ImageResize.java
public Bitmap getResizedBitmap(Bitmap bm, float widthFactor, float heightFactor) { int width = bm.getWidth(); int height = bm.getHeight(); // create a matrix for the manipulation Matrix matrix = new Matrix(); // resize the bit map matrix.postScale(widthFactor, heightFactor); // recreate the new Bitmap Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false); LOG.d(TAG, "Width: " + widthFactor + ", height:" + heightFactor); return resizedBitmap; }
From source file:com.simadanesh.isatis.ScreenSlideActivity.java
public static Bitmap resizeImage(Bitmap bitmap, int w, int h) { Bitmap BitmapOrg = bitmap;//from ww w.j av a 2 s .c o m int width = BitmapOrg.getWidth(); int height = BitmapOrg.getHeight(); int newWidth = w; int newHeight = h; float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0, width, height, matrix, true); return resizedBitmap; }
From source file:com.example.photoremark.MainActivity.java
/** * ?//from ww w .ja v a 2 s. c om * * @param filepath ? * @param options BitmapFactory.Options * @return */ public Bitmap scalePicture(String filepath, BitmapFactory.Options options, int screenWidth, int scaleHeight) { // ? int rotate = getPictureDegree(filepath); Bitmap bm = null; try { bm = BitmapFactory.decodeFile(filepath, options); } catch (OutOfMemoryError err) { } // ? if (bm != null) { int width = bm.getWidth(); int height = bm.getHeight(); // float scaleWidth = ((float) screenWidth) / width; Matrix matrix = new Matrix(); // matrix.postScale(scaleWidth, scaleWidth); // matrix.postRotate(rotate); bm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true); } return bm; }
From source file:org.apache.cordova.todataurl.ToDataURL.java
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackContext The callback id used when calling back into JavaScript. * @return True if the action was valid, false otherwise. *///from ww w.j av a 2s.c o m @Override public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException { Log.v(LOG_TAG, "Executing action: " + action); if ("getImageData".equals(action)) { try { // String encodedData = args.getString (0).replaceFirst ("^data:image/(png|jpg|jpeg);base64,", ""); // Log.i(LOG_TAG, "getImageData[" + encodedData.length () + "] = " + encodedData); byte[] data = Base64.decode( args.getString(0).replaceFirst("^data:image/(png|jpg|jpeg);base64,", ""), Base64.DEFAULT);// args.getArrayBuffer (0); /* int width = args.getInt (1); int height = args.getInt (2); */ String type = args.optString(1, "image/png"); int quality = args.optInt(2, 100); int orientation = args.optInt(3, 0); // Log.i(LOG_TAG, "getImageData[" + type + "][" + quality + "] = " + width + "x" + height); // Log.i(LOG_TAG, "getImageData[" + data.length + "] = " + data); Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length); /* bmp = Bitmap.createBitmap (width, height, Bitmap.Config.ARGB_8888); bmp.copyPixelsFromBuffer (ByteBuffer.wrap (data)); */ // Log.i(LOG_TAG, "getImageData::bmp = " + bmp); try { final Matrix bitmapMatrix = new Matrix(); switch (orientation) { case 1: break; // top left case 2: bitmapMatrix.postScale(-1, 1); break; // top right case 3: bitmapMatrix.postRotate(180); break; // bottom right case 4: bitmapMatrix.postRotate(180); bitmapMatrix.postScale(-1, 1); break; // bottom left case 5: bitmapMatrix.postRotate(90); bitmapMatrix.postScale(-1, 1); break; // left top case 6: bitmapMatrix.postRotate(90); break; // right top case 7: bitmapMatrix.postRotate(270); bitmapMatrix.postScale(-1, 1); break; // right bottom case 8: bitmapMatrix.postRotate(270); break; // left bottom default: break; // Unknown } // Create new bitmap. bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), bitmapMatrix, false); ByteArrayOutputStream out = new ByteArrayOutputStream(); bmp.compress((type.endsWith("jpeg") ? Bitmap.CompressFormat.JPEG : Bitmap.CompressFormat.PNG), quality, out); String dataURL = "data:" + type + ";base64," + Base64.encodeToString(out.toByteArray(), 0); // Log.i(LOG_TAG, "getImageData::dataURL = " + dataURL); PluginResult r = new PluginResult(PluginResult.Status.OK, dataURL); callbackContext.sendPluginResult(r); return true; } catch (Exception e) { // TODO: handle exception callbackContext.error("Create Bitmap Matrix"); PluginResult r = new PluginResult(PluginResult.Status.ERROR); callbackContext.sendPluginResult(r); return true; } } catch (IllegalArgumentException e) { callbackContext.error("Illegal Argument Exception"); PluginResult r = new PluginResult(PluginResult.Status.ERROR); callbackContext.sendPluginResult(r); return true; } /* PluginResult r = new PluginResult (PluginResult.Status.NO_RESULT); r.setKeepCallback (true); callbackContext.sendPluginResult (r); return true; */ } return false; }
From source file:com.aapbd.utils.image.CacheImageDownloader.java
private void scaleImage1(ImageView view) { // Get the ImageView and its bitmap final Drawable drawing = view.getDrawable(); if (drawing == null) { return; // Checking for null & return, as suggested in comments }//from w w w. j a v a2s. c om final Bitmap bitmap = ((BitmapDrawable) drawing).getBitmap(); // Get current dimensions AND the desired bounding box int width = bitmap.getWidth(); int height = bitmap.getHeight(); final int bounding = dpToPx(view.getContext(), 300); Log.i("Test", "original width = " + Integer.toString(width)); Log.i("Test", "original height = " + Integer.toString(height)); Log.i("Test", "bounding = " + Integer.toString(bounding)); // Determine how much to scale: the dimension requiring less scaling is // closer to the its side. This way the image always stays inside your // bounding box AND either x/y axis touches it. final float xScale = ((float) bounding) / width; final float yScale = ((float) bounding) / height; final float scale = (xScale <= yScale) ? xScale : yScale; Log.i("Test", "xScale = " + Float.toString(xScale)); Log.i("Test", "yScale = " + Float.toString(yScale)); Log.i("Test", "scale = " + Float.toString(scale)); // Create a matrix for the scaling and add the scaling data final Matrix matrix = new Matrix(); matrix.postScale(scale, scale); // Create a new bitmap and convert it to a format understood by the // ImageView final Bitmap scaledBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); width = scaledBitmap.getWidth(); // re-use height = scaledBitmap.getHeight(); // re-use final BitmapDrawable result = new BitmapDrawable(scaledBitmap); Log.i("Test", "scaled width = " + Integer.toString(width)); Log.i("Test", "scaled height = " + Integer.toString(height)); // Apply the scaled bitmap view.setImageDrawable(result); // Now change ImageView's dimensions to match the scaled image final LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams(); params.width = width; params.height = height; view.setLayoutParams(params); Log.i("Test", "done"); }
From source file:com.letsdoitworld.wastemapper.utils.ImageDownloader.java
public Bitmap rezise(Bitmap bitmapOrg) { int width = bitmapOrg.getWidth(); int height = bitmapOrg.getHeight(); int newWidth = 320; int newHeight = 240; // calculate the scale 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); Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true); // make a Drawable from Bitmap to allow to set the BitMap bitmapOrg.recycle();/*w w w .j ava 2s . c o m*/ return resizedBitmap; }