我想製作圖像的縮略圖。圖像位於資源可繪製的圖像中。任何人都可以幫助我。來自資源的圖像的縮略圖
3
A
回答
9
試試這個代碼
im=(ImageView)findViewById(R.id.imageView1);
byte[] imageData = null;
try
{
final int THUMBNAIL_SIZE = 64;
//InputStream is=getAssets().open("apple-android-battle.jpg");
FileInputStream fis = new FileInputStream("/sdcard/apple.jpg");
Bitmap imageBitmap = BitmapFactory.decodeStream(fis);
Float width = new Float(imageBitmap.getWidth());
Float height = new Float(imageBitmap.getHeight());
Float ratio = width/height;
imageBitmap = Bitmap.createScaledBitmap(imageBitmap, (int)(THUMBNAIL_SIZE * ratio), THUMBNAIL_SIZE, false);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
imageData = baos.toByteArray();
im.setImageBitmap(imageBitmap);
}
catch(Exception ex) {
}
+0
thankzzzzzzzzzzzzzzzzz – 2012-12-28 05:29:04
0
//讀取你可繪製
InputStream is = getResources().openRawResource(R.drawable.ic_launcher);
Bitmap mThumbnail = scaleBitmap(BitmapFactory.decodeStream(is));
//現在你可以保存位圖mThumbnail到SD卡
/*convert your image to an thumbnail view */
private static Bitmap scaleBitmap(Bitmap source) {
int maxSize = source.getWidth() > source.getHeight() ? source.getWidth() : source.getHeight();
return Bitmap.createScaledBitmap(source, source.getWidth() * 96/maxSize, source.getHeight() * 96/maxSize, true);
}
相關問題
- 1. 來自timthumb源的Lazyload縮略圖?
- 2. 顯示來自RSS源的縮略圖
- 3. 來自liveleak的縮略圖
- 4. 來自資源的圖像正確縮放,但SQlite的圖像blob不是 - Android
- 5. Xamarin來自資源的本地圖像
- 6. 分享來自資源的圖像
- 7. pyglet圖像資源來自字典
- 8. 資源管理器縮略圖(winXP)
- 9. 在圖像縮略圖上覆蓋來自YouTube API的文字
- 10. PHP - 顯示來自Mysql的圖像縮略圖
- 11. iPhone:拖放需要的縮略圖圖像來自定義完整的圖像
- 12. 圖像縮略圖
- 13. 圖像縮略圖
- 14. HTML來jpeg圖像作爲縮略圖
- 15. C++自旋圖像資源
- 16. 來自http url的視頻縮略圖
- 17. 來自視頻的Xuggler/Java縮略圖
- 18. Django來自網址的縮略圖
- 19. 如何獲取媒體庫的所有資源的縮略圖圖像?我有資源ID(attachment_id)
- 20. 通過WIA 2.0獲取來自攝像頭圖像的縮略圖數據
- 21. mkmapview縮略圖圖像
- 22. 圖像和縮略圖
- 23. 圖像適合縮略圖
- 24. PHP縮略圖圖像
- 25. 安排圖像縮略圖
- 26. UIScrollView和圖像縮略圖
- 27. 圖像縮略圖ASP.NET
- 28. 檢索圖像縮略圖
- 29. Facebook縮略圖圖像
- 30. 純CSS圖像縮略圖
你想展示它就像縮略圖或使其縮略圖並保存它? – 2012-02-27 07:19:12
我想製作圖像的縮略圖並將其保存在SD卡中 – 2012-02-27 08:32:34