Java tutorial
//package com.java2s; /* * Copyright (C) 2011 team-cachebox.de * * Licensed under the : GNU General Public License (GPL); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.gnu.org/licenses/gpl.html * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; public class Main { @SuppressWarnings("deprecation") public static int PutImageScale(Canvas canvas, Drawable image, double Angle, int x, int y, double scale) { if (scale == 0.0) return 0; float newWidth = (int) Math.round((float) image.getIntrinsicWidth() * scale); float newHeight = (int) Math.round((float) image.getIntrinsicHeight() * scale); Bitmap bmp = ((BitmapDrawable) image).getBitmap(); int width = bmp.getWidth(); int height = bmp.getHeight(); float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; // createa matrix for the manipulation Matrix matrix = new Matrix(); // resize the bit map matrix.postScale(scaleWidth, scaleHeight); // rotate the Bitmap matrix.postRotate((float) Angle); // recreate the new Bitmap Bitmap resizedBitmap = Bitmap.createBitmap(bmp, 0, 0, width, height, matrix, true); // make a Drawable from Bitmap to allow to set the BitMap // to the ImageView, ImageButton or what ever BitmapDrawable bmd = new BitmapDrawable(resizedBitmap); bmd.setBounds(x, y, x + bmd.getIntrinsicWidth(), y + bmd.getIntrinsicHeight()); bmd.draw(canvas); return bmd.getIntrinsicWidth(); } }