你好我在想要在android中传输图像的那一刻有这个错误。我不明白为什么。
编辑:我已经找到了存在的理由。存在的是他们拥有不足的记忆。如何更改允许的内存?
EDIT:FATAL EXCEPTION: main
java.lang.OutOfMemoryError
07-18 08:50:35.169: E/AndroidRuntime(16772): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
07-18 08:50:35.169: E/AndroidRuntime(16772): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
07-18 08:50:35.169: E/AndroidRuntime(16772): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:389)
07-18 08:50:35.169: E/AndroidRuntime(16772): at P12.transferImage(P12.java:503)
07-18 08:50:35.169: E/AndroidRuntime(16772): at P12.access$4(P12.java:487)
07-18 08:50:35.169: E/AndroidRuntime(16772): at P12$6.onClick(P12.java:313)
07-18 08:50:35.169: E/AndroidRuntime(16772): at android.view.View.performClick(View.java:3644)
07-18 08:50:35.169: E/AndroidRuntime(16772): at android.view.View$PerformClick.run(View.java:14313)
07-18 08:50:35.169: E/AndroidRuntime(16772): at android.os.Handler.handleCallback(Handler.java:605)
07-18 08:50:35.169: E/AndroidRuntime(16772): at android.os.Handler.dispatchMessage(Handler.java:92)
07-18 08:50:35.169: E/AndroidRuntime(16772): at android.os.Looper.loop(Looper.java:137)
07-18 08:50:35.169: E/AndroidRuntime(16772): at android.app.ActivityThread.main(ActivityThread.java:4514)
07-18 08:50:35.169: E/AndroidRuntime(16772): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 08:50:35.169: E/AndroidRuntime(16772): at java.lang.reflect.Method.invoke(Method.java:511)
07-18 08:50:35.169: E/AndroidRuntime(16772): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
07-18 08:50:35.169: E/AndroidRuntime(16772): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
07-18 08:50:35.169: E/AndroidRuntime(16772): at dalvik.system.NativeStart.main(Native Method)
07-18 08:55:44.474: I/Process(16772): Sending signal. PID: 16772 SIG: 9
07-18 08:55:44.764: D/dalvikvm(17129): GC_FOR_ALLOC freed 65K, 4% free 12756K/13187K, paused 16ms
问题在于
Bitmap imgTaken = BitmapFactory.decodeFile(from, options);
网址文件是否正确我已经验证
这是我的转移功能的开始。
private void transferImage(String from,String imageName) throws IOException {
Log.i("debug","from:"+from.toString());
// we want remote host, user name and password
if (from == null || from.length() == 0) {
Toast.makeText(getBaseContext(), getString(R.string.errorFTPparameters), Toast.LENGTH_LONG).show();
setResult(11);
finish();
}
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inTempStorage = new byte[16*1024];
// byte array transfers
Bitmap imgTaken = BitmapFactory.decodeFile(from, options);
if (imgTaken == null) {
Toast.makeText(getBaseContext(), getString(R.string.errorcreatingstream), Toast.LENGTH_LONG).show();
setResult(11);
finish();
}
// transforming image into byte array
ByteArrayOutputStream bos = new ByteArrayOutputStream();
imgTaken.compress(CompressFormat.JPEG, 60, bos);
byte[] bitmapdata = bos.toByteArray();
// base64 encoding of the bytes in a string
String bos1 = Base64.encodeBytes(bitmapdata);
//...
答案 0 :(得分:0)
嗯,你的形象很大,以适应Android为你分配的内存。
如果您不需要全分辨率图片,请使用setting the image size预先inSampleSize
更小的内容:
options.inSampleSize = 2 //gives you an image with half the height/width
如果您需要全分辨率图片,请说明您希望使用transferImage
功能确切达到的目标,然后我们可以为您提供另一种方式。