Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OutOfMemoryError android:将位图转换为字符串(不可能?)_Android_Image_Bitmap_Imageview - Fatal编程技术网

OutOfMemoryError android:将位图转换为字符串(不可能?)

OutOfMemoryError android:将位图转换为字符串(不可能?),android,image,bitmap,imageview,Android,Image,Bitmap,Imageview,我被这件小事弄得不知所措,不知什么原因,我真的不知道还能做什么。我试图添加的图片已被我的图库选中…(我最后检查的是1024X768和32色位) 我什么都试过了……请帮帮我:/ 我看到BAS的尺寸是7193767请描述您需要做什么。考虑到你的代码,它不是很清楚。我正在尝试将图像编码为字符串(发送给服务器),当我从服务器获取图像时,我将解码它并在我的应用程序上显示。你的requestCode==所选图片在大多数安卓设备上被破坏。您无法可靠地访问从ContentProvider获取的内容的文件路径,因

我被这件小事弄得不知所措,不知什么原因,我真的不知道还能做什么。我试图添加的图片已被我的图库选中…(我最后检查的是1024X768和32色位)

我什么都试过了……请帮帮我:/


我看到BAS的尺寸是7193767

请描述您需要做什么。考虑到你的代码,它不是很清楚。我正在尝试将图像编码为字符串(发送给服务器),当我从服务器获取图像时,我将解码它并在我的应用程序上显示。你的requestCode==所选图片在大多数安卓设备上被破坏。您无法可靠地访问从
ContentProvider
获取的内容的文件路径,因为数据可能不在文件中,或者可能不在您有权访问的文件中。使用
ContentResolver
openInputStream()
访问图像的内容。除此之外,不要在第一个活动中浪费内存读取图像,因为您没有使用它。但是我该怎么做呢?Intent i=新Intent(Intent.ACTION\u PICK,android.provider.MediaStore.Images.Media.EXTERNAL\u CONTENT\u URI);这就是你说的有问题的一面?你能告诉我怎么做吗?我不太明白你的意思
ImageButton img;
private static final int SELECTED_PICTURE = 1;
String picPathFile;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_channel);

    img = (ImageButton) findViewById(R.id.imageButton);

    img.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(
                    Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

            startActivityForResult(i, SELECTED_PICTURE);
        }
    });


    // defines the button functionality

    Button b = (Button) findViewById(R.id.backToMenu);
    b.setOnClickListener(new View.OnClickListener() {
        @Override
        // defines to move to menu activity when button is pressed
        public void onClick(View v) {

            Intent showImageIntent = new Intent(AddChannelActivity.this, ShowPreviewChannel.class);

            Bitmap selected_image = BitmapFactory.decodeFile(picPathFile);

            showImageIntent.putExtra("pic_file", picPathFile);
            showImageIntent.putExtra("c_name", name);
            showImageIntent.putExtra("c_id", "777");
            startActivity(showImageIntent);

            //newImage.recycle(); // where do i put it??
            //newImage = null;
            //selected_image.recycle();
            //selected_image = null;
        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch(requestCode) {
        case SELECTED_PICTURE: {
            if (requestCode == SELECTED_PICTURE) {
                Uri uri = data.getData();
                String[] filePathColumn = {MediaStore.Images.Media.DATA};
                Cursor cursor = getContentResolver().query(uri,
                        filePathColumn, null, null, null);
                cursor.moveToFirst();

                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);

                String picturePath = cursor.getString(columnIndex);

                cursor.close();

                picPathFile = picturePath;
                have_picture = true;

            }
            break;
        }
        default: break;
    }
}



 Intent intent = getIntent();


// the rellvant part from the show preview class
 Bundle bundle = intent.getExtras();
    if(bundle!= null){
        String picturePath = intent.getStringExtra("pic_file");

        Bitmap bm = BitmapFactory.decodeFile(picturePath);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object
        byte[] b = baos.toByteArray(); // HERE~!!!!! out of memory
}