List of usage examples for android.graphics Matrix postScale
public boolean postScale(float sx, float sy)
From source file:com.actionbarsherlock.internal.nineoldandroids.view.animation.AnimatorProxy.java
private void transformMatrix(Matrix m, View view) { final float w = view.getWidth(); final float h = view.getHeight(); final float sX = mScaleX; final float sY = mScaleY; if ((sX != 1.0f) || (sY != 1.0f)) { final float deltaSX = ((sX * w) - w) / 2f; final float deltaSY = ((sY * h) - h) / 2f; m.postScale(sX, sY); m.postTranslate(-deltaSX, -deltaSY); }//from w w w .ja va 2 s.c o m m.postTranslate(mTranslationX, mTranslationY); }
From source file:se.mah.k3.goransson.andreas.essemmesslib.Essemmess.java
/** * Resizes the bitmap to a smaller, squared, version. * /*from w ww .ja v a 2 s .c om*/ * @param bmp * @return */ private Bitmap getScaledBitmap(Bitmap bmp, int size) { int width = bmp.getWidth(); int height = bmp.getHeight(); /* Get the scale */ float scale_w = ((float) size) / width; float scale_h = ((float) size) / height; /* Transformation matrix */ Matrix matrix = new Matrix(); matrix.postScale(scale_w, scale_h); /* Get the new bitmap */ Bitmap resized = Bitmap.createBitmap(bmp, 0, 0, width, height, matrix, true); return resized; }
From source file:com.android.view.leg.ImageDetailActivityLeg.java
public Bitmap sBitmap(Bitmap b, int w, int h) { int width = b.getWidth(); int height = b.getHeight(); float scaleWidth = ((float) w) / width; float scaleHeight = ((float) h) / height; Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight);// return Bitmap.createBitmap(b, 0, 0, width, height, matrix, true); }
From source file:com.zhangyp.higo.drawingboard.fragment.SketchFragment.java
private void init(Bitmap bitmap) { float scaleRatio = 1; int width = bitmap.getWidth(); int height = bitmap.getHeight(); float screenRatio = 1.0f; float imgRatio = (float) height / (float) width; if (imgRatio >= screenRatio) { //?//from w ww. j av a2s. co m scaleRatio = (float) mScreenWidth / (float) height; } if (imgRatio < screenRatio) { scaleRatio = (float) mScreenWidth / (float) width; } Matrix matrix = new Matrix(); matrix.postScale(scaleRatio, scaleRatio); Bitmap dstbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); GPUImage gpuImage = new GPUImage(getActivity()); gpuImage.setFilter(new GPUImageSketchFilter()); final Bitmap grayBmp = gpuImage.getBitmapWithFilterApplied(dstbmp); ivBg.setImageBitmap(grayBmp); mSketchView.getBackground().setAlpha(150); ivBgColor.setImageBitmap(dstbmp); ObjectAnimator alpha = ObjectAnimator.ofFloat(ivBgColor, "alpha", 1.0f, 0.0f); alpha.setDuration(2000).start(); btShowBg.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ObjectAnimator alpha = ObjectAnimator.ofFloat(ivBgColor, "alpha", 0.0f, 1.0f); alpha.setDuration(1000).start(); } }); btShowBgGray.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ObjectAnimator alpha = ObjectAnimator.ofFloat(ivBgColor, "alpha", 1.0f, 0.0f); alpha.setDuration(1000).start(); } }); }
From source file:com.mibr.android.intelligentreminder.INeedToo.java
public static BitmapDrawable scaleTo(BitmapDrawable bmd, float newSize) { Bitmap bm = bmd.getBitmap();//ww w . j av a 2s. c om int width = bm.getWidth(); float scale = (float) (newSize / (float) width); Matrix matrix = new Matrix(); matrix.postScale(scale, scale); Bitmap bmNew = Bitmap.createBitmap(bm, 0, 0, width, width, matrix, true); return new BitmapDrawable(bmNew); }
From source file:org.ros.android.rviz_for_android.drawable.loader.ColladaLoader.java
private Map<String, ETC1Texture> getTextures(String prefix) { Map<String, ETC1Texture> retval = new HashMap<String, ETC1Texture>(); String filesDirectory = serverConnection.getContext().getFilesDir().toString() + "/"; // Find which types of acceptable textures are present (diffuse, bump, etc) for (textureType t : textureType.values()) { if (attributeExists("/COLLADA/library_effects/", t.toString(), "texture/@texture")) { String texPointer = super.existResult; String filename = null; // If the image library has an image with texPointer's ID, use that // otherwise, follow the pointer trail if (attributeExists("/COLLADA/library_images/image[@id='" + texPointer + "']/init_from")) { filename = super.existResult; Log.d("DAE", "Shortcut to texture name: " + filename); } else { // Locate the image ID from the texture pointer String imgID = getSingleAttribute( "/COLLADA/library_effects//newparam[@sid='" + texPointer + "']/sampler2D/source"); // Locate the image name String imgName = getSingleAttribute( "/COLLADA/library_effects//newparam[@sid='" + imgID + "']/surface/init_from"); // Locate the filename filename = getSingleAttribute("/COLLADA/library_images/image[@id='" + imgName + "']/init_from"); }/* ww w .j av a 2 s . c o m*/ Log.d("DAE", "Filename = " + filename); if (filename.length() == 0) Log.e("DAE", "Filename = 0 length!"); // If a cached compressed copy exists, load that. Otherwise, download, compress, and save the image String compressedFilename = "COMPRESSED_" + serverConnection.getSanitizedPrefix(imgPrefix) + filename; if (!serverConnection.fileExists(compressedFilename)) { Log.i("DAE", "No compressed cached copy exists."); // Load the uncompressed image String downloadedFilename = serverConnection.getFile(imgPrefix + filename); Bitmap uncompressed = null; if (downloadedFilename == null) { Log.e("DAE", "Unable to get file " + imgPrefix + filename + " from server!"); uncompressed = Bitmap.createBitmap(new int[] { 0, 0 }, 1, 1, Bitmap.Config.RGB_565); } else uncompressed = openTextureFile(filesDirectory, downloadedFilename); // Flip the image Matrix flip = new Matrix(); flip.postScale(1f, -1f); Bitmap uncompressed_two = Bitmap.createBitmap(uncompressed, 0, 0, uncompressed.getWidth(), uncompressed.getHeight(), flip, true); uncompressed.recycle(); // Compress the image ETC1Texture compressed = compressBitmap(uncompressed_two); // Save the compressed texture try { BufferedOutputStream bout = new BufferedOutputStream(serverConnection.getContext() .openFileOutput(compressedFilename, Context.MODE_WORLD_READABLE)); bout.write(compressed.getData().array()); bout.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // Add the compressed texture to the return map retval.put(t.toString(), compressed); } else { Log.i("DAE", "A compressed cached copy exists!"); // Load the existing compressed texture try { byte[] dataArray = IOUtils .toByteArray(serverConnection.getContext().openFileInput(compressedFilename)); // Determine the dimensions of the image int bytes = 2 * dataArray.length; int width = 1024; int height = 1024; while ((width * height) > bytes && (width * height) >= 1) { width /= 2; height /= 2; } Log.i("DAE", "Compressed size determined to be " + width + " x " + height); ByteBuffer dataBuffer = ByteBuffer.allocateDirect(dataArray.length) .order(ByteOrder.nativeOrder()); dataBuffer.put(dataArray); dataBuffer.position(0); ETC1Texture compressed = new ETC1Texture(width, height, dataBuffer); retval.put(t.toString(), compressed); } catch (FileNotFoundException e) { Log.e("DAE", "Compressed texture not found!"); e.printStackTrace(); } catch (IOException e) { Log.e("DAE", "IOException!"); e.printStackTrace(); } } } } return retval; }
From source file:ch.ethz.dcg.jukefox.manager.libraryimport.AndroidAlbumCoverFetcherThread.java
/** * Resize a bitmap to targetResxtargetRex pixels * /* w ww . j ava2 s.co m*/ * @param bm * bitmap to resize * @param targetRes * height and width of the new bitmap * @return */ private Bitmap resizeBitmap(Bitmap bm, int targetRes) { // scale the image for opengl int width = bm.getWidth(); int height = bm.getHeight(); float scaleWidth = (float) targetRes / width; float scaleHeight = (float) targetRes / height; // scale matrix 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, true); if (resizedBitmap == null) { Log.w(TAG, "ResizedBitmap is null"); } return resizedBitmap; }
From source file:com.landenlabs.all_UiDemo.frag.ImageScalesFrag.java
private Bitmap fillUpperLeft(final Drawable drawable, ImageView imageView, Bitmap prevBm) { // Compute matrix to fill viewer with drawable starting with upper left // Stretching till 2nd edge is crossed (filling screen) with correct aspect ratio. Matrix m = new Matrix(); m.reset();//from ww w . jav a 2 s. c o m int imgWidth = drawable.getIntrinsicWidth(); int imgHeight = drawable.getIntrinsicHeight(); int viewWidth = imageView.getWidth(); int viewHeight = imageView.getHeight(); float xScale = (float) viewWidth / imgWidth; float yScale = (float) viewHeight / imgHeight; float maxScale = Math.max(xScale, yScale); m.postScale(maxScale, maxScale); imageView.setScaleType(ImageView.ScaleType.MATRIX); imageView.setImageMatrix(m); imageView.setImageDrawable(drawable); return prevBm; }
From source file:com.yk.notification.util.BitmapUtil.java
/** * /*www.ja va2s . c o m*/ * * @param src * ?? * @param scaleX * ? * @param scaleY * ? */ public static Bitmap scale(Bitmap src, float scaleX, float scaleY) { Matrix matrix = new Matrix(); matrix.postScale(scaleX, scaleY); return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); }