Back to project page AdoreLib.
The source code is released under:
MIT License
If you think the Android project AdoreLib 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 com.ylinval.adore.adorelib.AdoreGraphics; //from w w w. ja v a 2 s . c om import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Rect; /** * Created by jdourlens on 5/9/14. */ public class Image { private Paint paint; private Rect image; private Rect dest; private Bitmap bitmap; public Image(Context context, int id) { paint = new Paint(); bitmap = BitmapFactory.decodeResource(context.getResources(), id); image = new Rect(); dest = new Rect(); paint.setARGB(255, 255, 255, 255); image.set(0, 0, bitmap.getWidth(), bitmap.getHeight()); } public Image(Context context, int id, int width) { Bitmap tmp_bmp; paint = new Paint(); paint.setARGB(255, 255, 255, 255); tmp_bmp = BitmapFactory.decodeResource(context.getResources(), id); float desiredScale = (float) width / tmp_bmp.getWidth(); Matrix matrix = new Matrix(); matrix.postScale(desiredScale, desiredScale); bitmap = Bitmap.createBitmap(tmp_bmp, 0, 0, tmp_bmp.getWidth(), tmp_bmp.getHeight(), matrix, true); tmp_bmp.recycle(); image = new Rect(); dest = new Rect(); image.set(0, 0, bitmap.getWidth(), bitmap.getHeight()); } public Image(Bitmap bitmap) { paint = new Paint(); this.bitmap = bitmap; image = new Rect(); dest = new Rect(); paint.setARGB(255, 255, 255, 255); image.set(0, 0, bitmap.getWidth(), bitmap.getHeight()); } public int getWidth() { return (image.width()); } public int getHeight() { return (image.height()); } public Bitmap getBmp() { return (bitmap); } public void draw(Canvas canvas, int x, int y) { canvas.drawBitmap(bitmap, x, y, paint); } public void clear() { this.bitmap.recycle(); this.bitmap = null; } }