2010-11-20 11 views
0

Ich weiß, diese Frage wurde gestellt und beantwortet, aber ich habe ein anderes Problem. Ich habe gerade eine App, die keine Bilder lädt, die höher als 5mp sind, aber kleinere laden. Ich bin nicht sicher, ob seine 5mp oder über 1mb, ich bin ziemlich sicher, dass seine mp, obwohl ich getestet habe. Wie kann ich Bilder in allen Größen laden? Mein Code ist unten, bitte helfe, bitte post Code nicht Links, von müssen zu Links dann Links zu Code, der helfen kann. Vielen Dank!android development loading Bilder von URL

Herunterladen der Bild @Override geschützt Bitmap doInBackground (Object ... Objekte) { Input ist = null; BufferedInputStream bis = 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(); 
     } 

Hochladen des Bildes

public boolean SaveNewPicture (String SelectedFile, String UpdatedPhotoPath) {

HttpURLConnection conn = null; 
DataOutputStream dos = null; 
DataInputStream inStream = null; 
@SuppressWarnings("unused") 

string message = null; // Der vollständige Pfad des Dateinamens, der auf den Server hochgeladen werden soll String exsistingFileName = SelectedFile;

String lineEnd = "\r\n"; 
String twoHyphens = "--"; 
String boundary = "*****"; 

int bytesRead, bytesAvailable, bufferSize; 

byte[] buffer; 

int maxBufferSize = 1*1024*1024; 

@SuppressWarnings("unused") 

Zeichenfolge 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 Antwort = client.execute (Anfrage); if (SelectedFile! = Null || SelectedFile! = "") { MyGlobalInfomation.setLocalPhotoPath (SelectedFile); } } catch (Ausnahme e) { Rückgabe false; } Rückkehr wahr; }

Antwort

0

Versuchen Sie dies gegen verschiedene Websites oder nur eine?

Der einzige Grund, den ich frage, ist, dass Sie erwähnt haben, dass> 1 MB in der Größe die Ursache sein könnte. Ich kenne einige Webhosting-Sites, die ihren Mitgliedern freien Webspace bieten, aber sie sind auf insgesamt 1 MB pro Webseite (oder jeden anderen Download) beschränkt. Wenn die Mitglieder echte Download-Sites haben wollen, müssen sie für die zusätzliche Bandbreite bezahlen.

Tut mir leid, es beantwortet wahrscheinlich Ihre Frage nicht, aber ich dachte, Sie möchten vielleicht überprüfen, dass es nicht die Website-Konfiguration vor dem Verdacht auf Ihren Code ist.

+0

Sie sagten nein. Es hat also etwas mit dem Code zu tun. Jemand hat etwas über BitmapFactory.Options.insamplesize erwähnt. Denkst du, das könnte helfen? Wenn ja, ändere meinen Code ein wenig, um mir ein Beispiel zu zeigen. Bitte helfen Sie, das ist das letzte, was ich nicht herausfinden kann. – Maurice

+0

Ich habe das auch versucht, aber kein Glück 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

Verwandte Themen