Bu sorunun soruldu ve cevaplandırıldı biliyorum ama farklı bir sorunum var. Şu anda 5mp'den daha büyük olan ancak daha küçük olanları yükleyen görüntüleri yüklemeyeceğim bir uygulamam var. Ben 5mp veya 1mb üzerinde emin değilim, ben eminim ki, mp olsa da, ben test ettik. Tüm boyutlardaki resimleri nasıl yükleyebilirim? Benim kodum aşağıdadır, Lütfen yardım edin, lütfen bağlantı koduyla bağlantı kurmayın, bağlantılar için gerekli olan linklere linkler yardımcı olabilir. Teşekkürler! Resmi @Override İndirilmesiandroid geliştirme yükleme URL resmi
korumalı Bitmap doInBackground (Object ... nesneler) { inputStream = null; BufferedInputStream bis = null; görüntü
public boolean SaveNewPicture (String SelectedFile, dize UpdatedPhotoPath) {
HttpURLConnection conn = null;
DataOutputStream dos = null;
DataInputStream inStream = null;
@SuppressWarnings("unused")
Yaylı Mesaj = boş yükleme
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();
}
; // Sunucuya yüklenecek dosya yolunun tam yolu String 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 (Özel durum e) { false; } true; }
Hayır dediler. Yani kod ile ilgisi var. Birisi BitmapFactory.Options.intsamplesize hakkında bir şeyden bahsetti. Bunun yardımcı olabileceğini mi düşünüyorsun? Öyleyse lütfen bana bir örnek göstermek için kodumu biraz değiştirin. Lütfen yardım edin, anlayamadığım en son şey bu. – Maurice
Bunu da denedim, ancak şans yok BitmapFactory.Options size = new BitmapFactory.Options(); \t \t \t size.inSampleSize = 1; \t \t \t bm = BitmapFactory.decodeStream (bis, null, size); – Maurice