Прошу прощения за мой плохой английский, я французский!Android - Изменить размер и обрезать картинку перед отправкой без сохранения
В моем приложении для Android я должен изменить размер и обрезать картинку из галереи перед отправкой ее на сервер БЕЗ, сохраняя ее.
Вот мой код для отправки на сервер:
HttpURLConnection connection = null;
DataOutputStream outputStream = null;
String pathToOurFile = imagePath;
String urlServer = "http://ip/serverApp/upload/transfert.php";
Log.e("UploadImage", urlServer);
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
try
{
File file = new File(imagePath);
FileInputStream fileInputStream = new FileInputStream(file);
byte[] bytes = new byte[(int) file.length()];
fileInputStream.read(bytes);
fileInputStream.close();
URL url = new URL(urlServer);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
connection.setDoOutput(true);
outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.writeBytes(twoHyphens + boundary + lineEnd);
outputStream.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + pathToOurFile +"\"" + lineEnd);
outputStream.writeBytes(lineEnd);
int bufferLength = 1024;
for (int i = 0; i < bytes.length; i += bufferLength) {
int progress = (int)((i/(float) bytes.length) * 100);
publishProgress(progress);
if (bytes.length - i >= bufferLength) {
outputStream.write(bytes, i, bufferLength);
} else {
outputStream.write(bytes, i, bytes.length - i);
}
}
outputStream.writeBytes(lineEnd);
outputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
outputStream.close();
outputStream.flush();
InputStream inputStream = connection.getInputStream();
// read the response
inputStream.close();
int serverResponseCode = connection.getResponseCode();
String serverResponseMessage = connection.getResponseMessage();
Log.w("Upload image", "Response -> Code:"+serverResponseCode+" Message:"+serverResponseMessage);
return serverResponseCode;
}
catch (Exception ex)
{
ex.printStackTrace();
}
Теперь мне нужно код, чтобы изменить размер и обрезать изображение, чтобы иметь изображение размером 350px/350px.
Вы знаете, как я мог это сделать?
Большое спасибо.
Работа прекрасна !!! Большое спасибо –
Mais de rien;) – VincentLamoute
Создает ли этот урожай или уменьшает размеры? –