是否有反正我可以缩放图像变得1.25倍,每次按下按钮时推动? 基本上,有人可以给我一些关于如何做到这一点的提示吗?一个解释,一个链接,一个教程,任何东西都会有所帮助:)在此先感谢我有一个图像,我想成长每次我点击一个按钮
0
A
回答
0
您可以使用Bitmap.createScaledBitmap()
来调整图像大小。 请参阅我的关于Image Processing
的文章以获得一些想法:):https://xjaphx.wordpress.com/learning/tutorials/
1
您应该遵循这一点。
http://www.anddev.org/resize_and_rotate_image_-_example-t621.html
下面是这个页面的代码。它创建一个矩阵来执行操作(调整大小和旋转)并应用该矩阵来创建新的BitMap。
你可以在你的按钮的事件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);
}
}
相关问题
- 1. 我想点击一个按钮
- 2. 我想在每次点击按钮时更改图像
- 3. 我想让我的提交按钮成为一个href图像
- 4. 我想点击切换按钮图像
- 5. 我想让一个图像旋转在一个按钮上点击
- 6. 指数变化每次我点击一个按钮
- 7. 我需要一个按钮,将在每次被点击
- 8. 每次更改布尔我点击一个按钮
- 9. 我想创建一个页面,我有一个按钮和按钮点击打开其他按钮
- 10. 我想要我的控件值。只有一次当我点击按钮
- 11. 每个IP点击一次按钮
- 12. 当我点击一个按钮
- 13. 当我点击一个按钮
- 14. 当我点击一个按钮
- 15. 当我们点击一个按钮时如何改变图像?
- 16. 我想每一个
- 17. 我有一个JSON文件,当我点击按钮
- 18. 我想生成一个UIScrollView的图像?
- 19. 我想在wordpress上点击一个按钮创建新页面
- 20. 我想制作一个按钮,在点击后自行旋转
- 21. 当一个标记被点击时,我想点击它3次
- 22. 我想为我的按钮设置一个背景图像。我崩溃了
- 23. 当我点击一个按钮的listview另一个按钮也点击我怎么能阻止它
- 24. 每次点击按钮时生成一个新的网格
- 25. 每按一次按钮都会增加一个数组点击
- 26. 使用jQuery我想每次显示李五,当我点击显示按钮
- 27. 当点击按钮时,图像第一次没有变化。第一次点击时要改变按钮图像
- 28. 每次当我点击Flex中的按钮时调用一个php文件
- 29. 获得一个属性当我点击一个按钮
- 30. 当我点击一个按钮时创建一个ProgressDialog
您的文章?我可以在哪里找到它们? – user870380
链接将很方便。我认为你的意思是你的网站,所以我快速浏览了http://xjaphx.wordpress.com/tag/image/,但没有看到关于重新调整大小的任何文章。 – Ben