私はこの質問が尋ねられ、答えられたが、私は別の問題があることを知っている。私は現在、5メガバイト以上の画像を読み込むのではなく、小さいものを読み込むアプリを持っています。私はテストしているが、私は確かにそのmpは、確かにその5mpまたは1mb、私はかなり確かに私は確信していない。どのサイズの写真をどのように読み込むことができますか?私のコードは以下の通りです。助けてください。ありがとう!イメージ @Overrideをダウンロードandroid development loading URLからの画像
保護ビットマップdoInBackground(オブジェクト...オブジェクト){ 入力ストリームは= 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を返します。 } がtrueを返します。 }
彼らは言いませんでした。だからそれはコードと関係があります。誰かがBitmapFactory.Options.intsamplesizeについて何か言及しました。それが助けになると思いますか?もし私のコードを少し変えてみてください。助けてください、これは私が把握できない最後のものです。 – Maurice
私もこれを試しましたが、運はありませんでした。BitmapFactory.Options size = new BitmapFactory.Options(); \t \t \t \t size.inSampleSize = 1; \t \t \t \t \t bmp = BitmapFactory.decodeStream(bis、null、size); – Maurice