내 앱에서 갤리에서 이미지를 표시하고 이미지를 선택하면 이미지를 웹 서버에 업로드하고 싶습니다. 서버에 이미지를 업로드하려면 다음을 사용하고 있습니다. 코드에서 오류가 발생했습니다. bitmapImage = BitmapFactory.decodeFile (path, opt);java.lang.outofmemoryerror 비트 맵 크기가 비트 맵에서 비트 맵 크기를 초과했습니다
private void uploadImage(String selectedImagePath) {
String str = null;
byte[] data = null;
String Responce= null;
Bitmap bitmap2 = null;
try {
File file=new File(selectedImagePath);
//FileInputStream fileInputStream = new FileInputStream(new File(imagePath2));
FileInputStream fileInputStream=new FileInputStream(selectedImagePath);
Log.i("Image path 2",""+selectedImagePath+"\n"+fileInputStream);
name=file.getName();
name=name.replace(".jpg","");
name=name.concat(sDate).concat(".jpg");
Log.e("debug",""+name);
//else
//{
BitmapFactory.Options options = new BitmapFactory.Options();
options.inTempStorage = new byte[16*1024];
//bitmapImage = BitmapFactory.decodeFile(path,opt);
bitmap2=BitmapFactory.decodeFileDescriptor(fd, outPadding, opts)
Log.i("Bitmap",""+bitmap.toString());
BitmapFactory.decodeStream(fileInputStream);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap2.compress(Bitmap.CompressFormat.PNG, 100, baos);
data = baos.toByteArray();
str=Base64.encodeBytes(data);
//}
//String image=str.concat(sDate);
ArrayList<NameValuePair> nameValuePairs = new
ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("image",str));
nameValuePairs.add(new BasicNameValuePair("imagename", name));
Log.e("debug",""+nameValuePairs.toString());
HttpClient client=new DefaultHttpClient();
HttpPost post=new HttpPost("http://ufindfish.b4live.com/uploadTipImage.php");
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse httpResponse=client.execute(post);
HttpEntity entity=httpResponse.getEntity();
InputStream inputStream=entity.getContent();
StringBuffer builder=new StringBuffer();
int ch;
while((ch = inputStream.read()) != -1)
{
builder.append((char)ch);
}
String s=builder.toString();
Log.i("Response",""+s);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(bitmap2!=null)
{
bitmap2.recycle();
}
@abhi ... 답장을 보내 주셔서 감사합니다.하지만 여전히 오류가 발생합니다 .1 작은 질문 ... 비트 맵 가져 오기 후 ** 비트 맵 비트 맵 = 비트 맵 Factory.decode 파일 (파일 경로, o2); **이 후 어떻게베이스 64 문자열로 변환합니까 ...이 bitmap.compress (Bitmap.CompressFormat.PNG, 100, baos); 다음 코드를 사용하고 있습니다; \t \t \t \t data = baos.toByteArray(); \t \t \t \t str = Base64.encodeBytes (data); – android
@abhi ... 감사합니다. 나는 그 문제를 해결했습니다 ... 지금은 잘 작동합니다 ... 아주 많이 감사드립니다 ... – android
@Abhi 나는 당신의 코드를 사용했고, 그것에 대한 나의 오류를 거의 해결해주었습니다. 이 방법으로 인해 문제가 발생했습니다. 이 방법은 원본 이미지를 회전시킵니다. 그리고 나는 그다지 원하지 않는다. 갤러리에 표시되는 것처럼 내 이미지를 표시하고 싶습니다. 이 일을 할 수있는 방법이 있습니까? – anddev