0
我試圖在主屏幕上創建圖像效果應用程序 有按鈕相機,畫圖,圖庫,設置 我想從圖庫中選擇圖像並將其發送到新的活動以在點擊圖庫按鈕後添加效果。 這是我的代碼{Android}我可以從圖庫中選擇圖片並將其發送到一個按鈕中的新活動嗎?
private static int RESULT_LOAD_IMAGE = 1;
Bitmap temp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
Button gal = (Button)findViewById(R.id.bgal);
gal.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
Intent intent = new Intent(getApplicationContext(), Gallery.class);
intent.putExtra("BitmapImage", temp);
startActivity(intent);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
temp = BitmapFactory.decodeFile(picturePath);
}
}
能解決這個問題?
謝謝你,但應用程序不會去新activity.It我只能選擇照片。 – TooKom
任何崩潰或沒有.. ?? –
in logcat「失敗的綁定器事務」 – TooKom