0

我正在开发一个有趣的 android 应用程序。我需要在其中捕获图像,然后在保存之前,我需要在捕获的图像上添加一些文本。是否可以在运行时在 android 中编辑捕获的图像,请建议我。Thaanxx提前..!

4

1 回答 1

2

如果您使用默认意图来捕获图像,请使用以下代码。无论您触摸图像的何处,都会放置文本。cp,imageview 应该在您的布局中。而 RelativeLayout rl 是您的布局的 id。

ImageView cp = (ImageView) findViewById(R.id.img_cp);
                Intent cameraIntent = new Intent(
                        android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(cameraIntent, CAMERA_REQUEST);


        cp.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                Log.v("touched x val of cap img >>", event.getX() + "");
                Log.v("touched y val of cap img >>", event.getY() + "");
                x = (int) event.getX();
                y = (int) event.getY();
                RelativeLayout rl = (RelativeLayout) findViewById(R.id.lay_lin);
                TextView iv = new TextView(Capture_Image.this);
                iv.setText("checking......");
                RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.WRAP_CONTENT,
                        RelativeLayout.LayoutParams.WRAP_CONTENT);
                params.leftMargin = x;
                params.topMargin = y;
                rl.addView(iv, params);
                return false;
            }
        });
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == CAMERA_REQUEST) {
            photo = (Bitmap) data.getExtras().get("data");
            cp.setImageBitmap(photo);
        }

    }
于 2012-07-18T09:56:11.953 回答