-1
서버에 이미지 업로드를 시도합니다. 경로별로 이미지를 가져와 바이트 배열로 변환합니다.저속 이미지 업로드
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
Bitmap picture = BitmapFactory.decodeFile(imagePath, bmOptions);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
ByteArrayOutputStream bao = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bao);
byte[] bytes = bao.toByteArray();
builder.addPart("uploadedfile", new ByteArrayBody(bytes, "name" + ".jpg"));
예를 들어 이미지 크기는 300kb이지만 업로드 된 이미지의 크기는 800kb입니다.
크기를 늘리지 않고 어떻게 경로 (이미지)를 보낼 수 있습니까?
SOULUTION
@greenapps 좋아. 이미지를 파일로 변환 :
public static byte[] fullyReadFileToBytes(File f) throws IOException {
int size = (int) f.length();
byte bytes[] = new byte[size];
byte tmpBuff[] = new byte[size];
FileInputStream fis= new FileInputStream(f);;
try {
int read = fis.read(bytes, 0, size);
if (read < size) {
int remain = size - read;
while (remain > 0) {
read = fis.read(tmpBuff, 0, remain);
System.arraycopy(tmpBuff, 0, bytes, size - remain, read);
remain -= read;
}
}
} catch (IOException e){
throw e;
} finally {
fis.close();
}
return bytes;
}
이미지를 64 비트 문자열 인코딩으로 보내 봤습니까? – Eenvincible
중간 비트 맵을 사용하지 않고 이미지 파일을 바이트 배열에 넣습니다. – greenapps
@greenapps이 댓글을 답으로 추가 할 수 있습니다. –