OutOfMemoryError android:将位图转换为字符串(imposiable?)

时间:2015-06-25 15:35:23

标签: android image bitmap imageview

我真的很喜欢这个小东西,因为某种原因只是没有成功......我真的不知道还能做些什么。我试图添加的图片已被我的画廊选中..(我检查的最后一件事是1024X768和32色位)

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
}

我尝试了一切....请帮助我:/

我看到宝的大小是7193767

0 个答案:

没有答案