0
나는 안드로이드 device.What이 최고에 이미지를 저장하기 위해 나를 인도 사람 물어봐 할 device.How에서 이미지를 저장해야 server.I에서 이미지의 집합이 이 과정을 수행하는 방법. 사전에의 안드로이드 장치에 이미지를 저장하는 방법
감사합니다 :) 당신은 URL에서 이미지를 다운로드 및 SD 카드에 저장할 수 있습니다
나는 안드로이드 device.What이 최고에 이미지를 저장하기 위해 나를 인도 사람 물어봐 할 device.How에서 이미지를 저장해야 server.I에서 이미지의 집합이 이 과정을 수행하는 방법. 사전에의 안드로이드 장치에 이미지를 저장하는 방법
감사합니다 :) 당신은 URL에서 이미지를 다운로드 및 SD 카드에 저장할 수 있습니다
. 이미지를 표시하려면 이미지를로드하면됩니다. 이 작업을위한 간단한 코드입니다. 이 당신을 도울 것입니다
private void downloadImagesToSdCard(String downloadUrl,String imageName)
{
try{
URL url = new URL(downloadUrl); //you can write here any link
File myDir = new File("/sdcard"+"/"+Constants.imageFolder);
//Something like ("/sdcard/file.mp3")
if(!myDir.exists()){
myDir.mkdir();
Log.v("", "inside mkdir");
}
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = imageName;
File file = new File (myDir, fname);
if (file.exists()) file.delete();
/* Open a connection to that URL. */
URLConnection ucon = url.openConnection();
InputStream inputStream = null;
HttpURLConnection httpConn = (HttpURLConnection)ucon;
httpConn.setRequestMethod("GET");
httpConn.connect();
if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
inputStream = httpConn.getInputStream();
}
/*
* Define InputStreams to read from the URLConnection.
*/
// InputStream is = ucon.getInputStream();
/*
* Read bytes to the Buffer until there is nothing more to read(-1).
*/
FileOutputStream fos = new FileOutputStream(file);
int size = 1024*1024;
byte[] buf = new byte[size];
int byteRead;
while (((byteRead = inputStream.read(buf)) != -1)) {
fos.write(buf, 0, byteRead);
bytesDownloaded += byteRead;
}
/* Convert the Bytes read to a String. */
fos.close();
}catch(IOException io)
{
networkException = true;
continueRestore = false;
}
catch(Exception e)
{
continueRestore = false;
e.printStackTrace();
}
}
희망.
이미지를 다운로드 한 후이 앱 이름 '앱/images' 만든 폴더에 그들 모두를 유지하는 좋은 생각이 될 것입니다, 당신은 당신의 이미지에 대한 경로를 얻을 당신이 할 필요가 이제까지 다른 무엇을 할 수 앱의 경우 – kabuto178
이미지 크기가 더 큰 경우 저장소에 문제가 있는지 여부 – Kirthiga
크기는 이미지 저장시 항상 염려되지만 이미지 품질을 압축하고 약간의 공간을 절약 할 수는 있지만 이미지를 다운로드해야합니다. 당신은 그 대답 중 하나를 시도해 이미지를 다운로드하는 방법을 알아낼 수 있습니다. 또는 이미지를 '레이지로드 (LazyLoad)'할 수 있습니다. 그러나 이것은 그림의 구현에 달려 있습니다. – kabuto178