나는이 질문에 답을 얻었지만 대답했지만 다른 문제가 있음을 알고 있습니다. 지금은 5mp보다 높지만 작은 이미지는로드하지 않는 앱을 가지고 있습니다. Im는 그것의 5mp 또는 1mb 이상, 확실한 그것의 mp 확실히 확실한, 나는 시험했다. 모든 크기의 사진을로드하려면 어떻게해야합니까? 내 코드는 아래에 있습니다. 제발 도와주세요. 코드가 아닌 링크를 게시하십시오. 링크가 있어야하고 도움이 될만한 코드에 링크해야합니다. 감사! 이미지 @Override 다운로드android development loading URL에서 이미지
보호 비트 맵 doInBackground (객체 ... 객체) { 의 InputStream은 = null 인; BufferedInputStream bis = null; 화상
공개 부울 SaveNewPicture (문자열 SelectedFile 문자열 UpdatedPhotoPath) {
HttpURLConnection conn = null;
DataOutputStream dos = null;
DataInputStream inStream = null;
@SuppressWarnings("unused")
문자열 메시지 = NULL 업로드
Bitmap bmp = null;
try {
URL url = new URL(Pictureurl);
URLConnection conn = url.openConnection();
conn.connect();
is = conn.getInputStream();
bis = new BufferedInputStream(is);
bmp = BitmapFactory.decodeStream(bis);
return bmp;
} catch (MalformedURLException e) {
return null;
} catch (IOException e) {
return null;
}
}
@Override
protected void onPostExecute(Object resizedBitmap) {
MainPicture.setImageBitmap((Bitmap) resizedBitmap);
connectionProgressDialog.dismiss();
}
; // 서버에 업로드 할 파일 이름의 전체 경로 문자열 exsistingFileName = SelectedFile;
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int maxBufferSize = 1*1024*1024;
@SuppressWarnings("unused")
String responseFromServer = "";
//Server path to the upload.php
String urlString = "http://www.thelinkhookup.com/upload.php";
try
{
//------------------ CLIENT REQUEST
FileInputStream fileInputStream = new FileInputStream(new File(exsistingFileName));
// open a URL connection to the Servlet
URL url = new URL(urlString);
// Open a HTTP connection to the URL
conn = (HttpURLConnection) url.openConnection();
// Allow Inputs
conn.setDoInput(true);
// Allow Outputs
conn.setDoOutput(true);
// Don't use a cached copy.
conn.setUseCaches(false);
// Use a post method.
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
dos = new DataOutputStream(conn.getOutputStream());
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + exsistingFileName +"\"" + lineEnd);
dos.writeBytes(lineEnd);
System.out.println("Headers are written");
// create a buffer of maximum size
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];
// read file and write it into form...
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0)
{
dos.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
// send multipart form data necesssary after file data...
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
// close streams
System.out.println("File is written");
fileInputStream.close();
dos.flush();
dos.close();
}
catch (MalformedURLException ex)
{
return false;
}
catch (IOException ioe)
{
Message = ioe.toString();
return false;
}
//------------------ read the SERVER RESPONSE
try {
inStream = new DataInputStream (conn.getInputStream());
String str;
while ((str = inStream.readLine()) != null)
{
//the str contains the server response
System.out.println("Server Response"+str);
}
inStream.close();
//Message = "Should Have Worked";
}
catch (IOException ioex){
return false;
}
try{
HttpClient client = new DefaultHttpClient();
HttpPost request = new HttpPost("http://thelinkhookup.com/UpdatePhotoName.php");
List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("Username", MyGlobalInfomation.getUsername()));
postParameters.add(new BasicNameValuePair("Photopath", UpdatedPhotoPath));
postParameters.add(new BasicNameValuePair("localphotopath",SelectedFile));
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
request.setEntity(formEntity);
@SuppressWarnings("unused")
HttpResponse response = client.execute (request); if (SelectedFile! = null || SelectedFile! = "") { MyGlobalInfomation.setLocalPhotoPath (SelectedFile); } } catch (예외 e) { false를 반환합니다. } return true; }
그들은 아니오라고했습니다. 그래서 그것은 코드와 관련이 있습니다. 누군가 BitmapFactory.Options.intsamplesize에 대해 언급했습니다. 그게 도움이 될 거라 생각해? 그렇다면 예제를 보여주기 위해 코드를 약간 변경하십시오. 제발 도와주세요,이게 내가 알아낼 수없는 마지막 것입니다. – Maurice
나는 이것을 시도했지만 행운이 없다. BitmapFactory.Options size = new BitmapFactory.Options(); \t \t \t \t \t size.inSampleSize = 1; \t \t \t \t \t bmp = BitmapFactory.decodeStream (bis, null, size); – Maurice