[英]I have an image which i would like to have grow everytime i click a button
Is there anyway i could scale an image to become 1.25x bigger everytime a button is pushed? 无论如何,每次按下按钮,我都可以将图像缩放为1.25倍大吗? Basically, could someone give me some tips on how to do this?
基本上,有人可以给我一些如何做的提示吗? An explanation, a link, a tutorial, anything would be helpful :) thanks in advance
一个解释,一个链接,一个教程,任何都会有所帮助的:)预先感谢
You should follow this. 您应该遵循此。
http://www.anddev.org/resize_and_rotate_image_-_example-t621.html http://www.anddev.org/resize_and_rotate_image_-_example-t621.html
Here is code from this page. 这是此页面上的代码。 It creates a Matrix to perform operations(resize and rotate) and applies that matrix to create new BitMap.
它创建一个执行操作(调整大小和旋转)的矩阵,并将该矩阵应用于创建新的BitMap。
You can add the code(with some modifications) on OnClickListener
event of yout Button. 您可以在yout Button的
OnClickListener
事件上添加代码(进行一些修改)。
public class bitmaptest extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
LinearLayout linLayout = new LinearLayout(this);
// load the origial BitMap (500 x 500 px)
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
R.drawable.android);
int width = bitmapOrg.width();
int height = bitmapOrg.height();
int newWidth = 200;
int newHeight = 200;
// calculate the scale - in this case = 0.4f
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(45);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 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);
ImageView imageView = new ImageView(this);
// set the Drawable on the ImageView
imageView.setImageDrawable(bmd);
// center the Image
imageView.setScaleType(ScaleType.CENTER);
// add ImageView to the Layout
linLayout.addView(imageView,
new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT
)
);
// set LinearLayout as ContentView
setContentView(linLayout);
}
}
You can use Bitmap.createScaledBitmap()
to resize image. 您可以使用
Bitmap.createScaledBitmap()
调整图像大小。 Refer to my articles on Image Processing
to get some idea :): https://xjaphx.wordpress.com/learning/tutorials/ 请参阅我有关
Image Processing
文章以获取一些想法:): https : //xjaphx.wordpress.com/learning/tutorials/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.