我在這裏面臨一些問題。我有一個套接字服務器,我的應用程序上傳圖像。現在,如果我說我有1百萬客戶,每個1MB的圖像,我應該留下1太字節的配置文件圖像,這太多了。我正在尋找一種方法來將所有圖像文件轉換爲最大100 kb的大小,是可能的嗎?如果是的話,我應該搜索什麼?在Android中轉換圖像
而且也是我從磁盤中選擇圖像文件,像這樣:
File file = new File("storage/sdcard/LifeMatePrivate/ProfileImage
/ProfileImage,imagechange_1,"+imagenamer+".jpg")
但是當你看到它只是prefix.jpg選擇圖像。有沒有辦法使用任何擴展名的文件?謝謝。
public void SaveImage(View v){
System.out.println(path);
String Path = path;
//File file=new File("storage/sdcard/Pictures/reza2.jpg");
Bitmap bitmap = BitmapFactory.decodeFile("storage/sdcard/Pictures
/reza2.jpg");
// you can change the format of you image compressed for what do you
want;
//now it is set up to 640 x 960;
Bitmap bmpCompressed = Bitmap.createScaledBitmap(bitmap, 640, 960, true);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
// CompressFormat set up to JPG, you can change to PNG or whatever you
want;
bmpCompressed.compress(CompressFormat.PNG, 100, bos);
// Intent returnIntent = new Intent();
// returnIntent.putExtra("result",Path);
// setResult(RESULT_OK,returnIntent);
// Log.i("Image",path);
finish();
}
這個代碼是內部的活動與StartActivityForResult
怎麼能我一個1600x1200的圖像轉換爲635x479? – user3694470
你可以使用'Bitmap.createScaledBitmap()'方法 –
'bmpCompressed'是壓縮格式的新文件..現在你必須在你上傳文件時通過它.. –