Back to project page FeedListViewDemo.
The source code is released under:
MIT License
If you think the Android project FeedListViewDemo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package io.bxbxbai.androiddemos.utils; /*w w w . java 2 s. c o m*/ import android.graphics.Bitmap; import android.graphics.Canvas; import android.view.View; /** * Created by storm on 14-6-17. */ public class BitmapUtils { public static Bitmap drawViewToBitmap(View view, int width, int height, int downSampling) { return drawViewToBitmap(view, width, height, 0f, 0f, downSampling); } public static Bitmap drawViewToBitmap(View view, int width, int height, float translateX, float translateY, int downSampling) { float scale = 1f / downSampling; int bmpWidth = (int) (width * scale - translateX / downSampling); int bmpHeight = (int) (height * scale - translateY / downSampling); Bitmap dest = Bitmap.createBitmap(bmpWidth, bmpHeight, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(dest); c.translate(-translateX / downSampling, -translateY / downSampling); if (downSampling > 1) { c.scale(scale, scale); } view.draw(c); return dest; } }