當我從網上下載圖片,並將它們保存到SD卡在我的應用程序,我用下面的方法:下載圖像:圖像質量影響
private void saveImageToSDcard() throws IOException {
File sdImageMainDirectory = new File(
Environment.getExternalStorageDirectory(), getResources()
.getString(R.string.directory));
if (!sdImageMainDirectory.exists()) {
sdImageMainDirectory.mkdirs();
}
for (int i = 0; i < jArray.length(); i++) {
reviewImageLink = url[i];
urlimage = new URL(reviewImageLink);
input = urlimage.openStream();
try {
output = new FileOutputStream(
Environment.getExternalStorageDirectory()
+ "/Downloads/" + "photo" + i + ".jpg");
try {
byte[] buffer = new byte[2];
int bytesRead = 0;
while ((bytesRead = input.read(buffer, 0, buffer.length)) >= 0) {
output.write(buffer, 0, buffer.length);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
output.close();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
input.close();
}
}
}
的圖像保存到SD卡但當我嘗試將SD卡中的圖像放入我的應用程序中,有時圖像看起來模糊不清。這不會一直髮生,但是當它發生時,部分圖像很不清楚。什麼會造成這種情況?
重要:我用下面的緩衝區從URL中讀取輸入流:
byte[] buffer = new byte[2];
我發現,如果我增加它的大小,然後將其保存到SD卡的圖像是完全模糊。
不,我不調整圖像大小。我認爲這個output.write(buffer,0,bytesRead); 解決了這個問題 – Gabrielle