ทั้งหมดนี้ทำให้ฉันทรมานเป็นเวลานานหลายสัปดาห์ ฉันตั้งค่ารูปภาพให้สูง 227 พิกเซลและปรับขนาดเป็น 170 พิกเซล แม้ว่าฉันต้องการให้เป็น wrap_content ทุกครั้งที่ฉันทำก็ตาม
ตกลง. ที่นี่ฉันจะนำรูปภาพของฉันซึ่งมีความยาว 1950 พิกเซล (ฉันใส่บางส่วนไว้ที่นี่เพื่อให้คุณเข้าใจว่าควรมีลักษณะอย่างไร)
ก่อนอื่น ฉันต้องการปรับขนาดกลับเป็นความสูง 227 พิกเซล เพราะนั่นคือวิธีการออกแบบและวิธีที่ควรจะเป็น
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),R.drawable.ver_bottom_panel_tiled_long);
int width = bitmapOrg.getWidth();
int height = bitmapOrg.getHeight();
int newWidth = 200; //this should be parent's whdth later
int newHeight = 227;
// calculate the scale
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
width, height, matrix, true);
BitmapDrawable dmpDrwbl=new BitmapDrawable(resizedBitmap);
verbottompanelprayer.setBackgroundDrawable(dmpDrwbl);
ดังนั้น... มันไม่ใช่ภาพที่ครอบตัดเลย - ไม่ มันเป็น 1950 พิกเซลที่กดเป็น 200 พิกเซล
แต่ฉันต้องการตัดอะไรก็ได้นอกเหนือจาก 200 พิกเซลหรือความกว้างใดก็ตามที่ฉันจะตั้งค่า - ครอบตัดมันและไม่กดรูปภาพยาวทั้งหมดนี้ลงในพื้นที่ 200 พิกเซล
นอกจากนี้ BitmapDrawable (บิตแมปบิตแมป); และ imageView.setBackgroundDrawable (วาดได้); เลิกใช้แล้ว - ฉันจะเปลี่ยนสิ่งนั้นได้อย่างไร