本帖最后由 yhm2046 于 2013-05-28 16:56:52 编辑

解决方案 »

  1.   


    private RelativeLayout layout; @Override
    protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.show_img_layout);
    layout = (RelativeLayout) findViewById(R.id.show_img_ly_relativelayout); // 必须要有一个view layout.setFocusable(true);
    layout.setEnabled(true);
    registerForContextMenu(layout); // 监听菜单
    } @Override
    protected void onStart() {
    // TODO Auto-generated method stub
    super.onStart();
    } @Override
    public boolean onCreateOptionsMenu(Menu menu) { return false;
    } // 上下文菜单
    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
    ContextMenuInfo menuInfo) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.m_menu_modify_photo, menu);
    } @Override
    public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_delete:
    deleteThisImg();
    break;
    case R.id.menu_modify:
    System.out.println("modify");
    finish(); // 关闭本页面
    modifyImg();
    break;
    case R.id.menu_save:
    saveModifiyImg();
    break; default:
    break;
    }
    return true;
    } /**
     * @description 编辑图片
     */
    private void modifyImg() {
    // 载入编辑页面
    Intent intent = new Intent(ModifyPhotoActivity.this,
    ShowPhotoActivity.class);
    // 传递bitmap的地址
    intent.putExtra(GlobalConstants.IMG_ABSOLUTE_PATH, getIntent()
    .getStringExtra(GlobalConstants.IMG_ABSOLUTE_PATH));
    // 传递可以修改的信息
    intent.putExtra(GlobalConstants.IMG_EDIT, GlobalConstants.IMG_EDIT);
    startActivity(intent);
    } /**
     * @description 删除图片
     */
    private void deleteThisImg() {
    // 通话id获取图片地址
    String imgPath = getIntent().getStringExtra(
    GlobalConstants.IMG_ABSOLUTE_PATH);
    // 删除sd卡上的图片 File f = new File(imgPath);
    if (f.exists()) {
    try {
    f.delete();
    System.out.println("delete success!");
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    System.out.println("exception--->" + e);
    }
    }
    // 返回主页
    Intent intent = new Intent(ModifyPhotoActivity.this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
    } /**
     * @description 弹出dialog式的activity对话框保存编辑后的图片
     */
    private void saveModifiyImg() {
    // 弹出对话框提示保存
    // 截屏
    Bitmap bitmap = GlobalFunction.getScreenshot(this);
    // bitmap转成byte【】
    byte[] bitmapByte = GlobalFunction.bitmap2byte(bitmap);
    // 发送
    Intent intent = new Intent(ModifyPhotoActivity.this,
    SaveImgActivity.class);
    intent.putExtra("bundle", bitmapByte);
    startActivity(intent);
    }
      

  2.   

    http://www.eoeandroid.com/thread-5813-1-1.html