简体   繁体   English

我有一幅我希望每次单击按钮都可以增长的图像

[英]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.

相关问题 我必须单击该按钮两次才能使其工作 - I have to click the button twice for it to work 我有一个视图,并且在该视图内有一个textview我想更新该textview? - I have a view and inside that view I have a textview I would like to update that textview? 我想将合乎逻辑的记录重新组合在一起 - I would like to regroup records thats have a logical suit together 我如何有一个唯一的按钮向JTable添加一行 - How Would I have a button unique add a row to a JTable 当用户单击GUI中的按钮时,我想打开一个图像 - I would like to open an image when a user clicks on a button in GUI 当我有一个jcombobox聚焦时,我需要点击两次才能点击一个按钮 - I need 2 clicks to click a button when I have a jcombobox focused 如何在后端春季启动代码中获取按钮点击计数(我在 UI 中拥有)? - How to get the Button click count (which I have in UI )in backend spring boot code? 每次我要运行时,都必须(项目>清理)。 怎么不呢? - I have to (Project > clean) everytime I want to run. How not to? 大家好! 目前正在创建一个银行api并希望客户有一个地址! 我该怎么做? - Hey guys! Currently creating a banking api and would like to customer to have an address! How would I do that? 当我单击一个按钮时,我只想激活其周围的按钮。 这怎么可能? - When i click a button i would like to activate only its surrounding buttons. How is this possible?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM