» 首頁 » 討論區 » Android程式設計 »圖片問題

圖片問題

發表人: 阿佑
積分: 16
發表時間: 2011-11-28 11:12:58
我的專題題目是五子棋
我已經可以在 android手機模擬器 把棋子下在正確位置了!
可是當我把五子棋放入手機裡面,位置全亂掉了。為什麼呢...

有android高手可以為我解答嗎?
發表人: Seachaos
積分: 2432
發表時間: 2011-11-29 01:03:51
你好:
你模擬器的螢幕解析度是不是和手機的不同?
Android很容易在不同的螢幕下發生跑版的問題
發表人: 阿佑
積分: 16
發表時間: 2011-11-29 15:05:17
我想寫一個程式 可以抓取我drawable裡面的圖片
然後在不同手機上面可顯示剛好的大小

//圖片原圖
Bitmap bm = BitmapFactory.decodeResource(this.getResources(),R.drawable.pk);
//取得圖片長寬
int width = bm.getWidth();
int height = bm.getHeight();
//設定圖片大小
int newWidth = 250;
int newHeight = 300;
//計算縮放比例
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
//取得縮放的matrix參數
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth,scaleHeight);
//取得新圖
Bitmap newBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix,true);

這是我程式碼...圖片就是顯示不出來
不知道少了什麼步驟。
發表人: Seachaos
積分: 2432
發表時間: 2011-11-30 09:46:10
你好:
問題可能是在型態轉換上出了問題

float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;

改成

float scaleWidth = (float) newWidth / (float)width;
float scaleHeight = (float) newHeight / (float)height;

看看
發表人: 阿佑
積分: 16
發表時間: 2011-11-30 16:59:18
還是沒有辦法,如果要用 Imageview 顯示以修改後的圖片,該怎麼用!?
我覺得要讓圖片顯示的問題。
發表人: Seachaos
積分: 2432
發表時間: 2011-12-01 02:38:33
那你可能是缺少了最後的步驟
imageView.setImageBitmap(newBitmap)