是否有反正我可以縮放圖像變得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