我想在捕获图像后添加文本,然后想要共享该图像

时间:2013-10-21 13:47:43

标签: android

我已完成图像捕捉现在我想在捕获的图像上添加一些文字。

此外,我想将其保存为图像,并希望分享。

以下是代码。

public class Main extends Activity实现OnClickListener {

private static final int TAKE_PICTURE = 0;
private Uri mUri;
private Bitmap mPhoto;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ((Button) findViewById(R.id.snap)).setOnClickListener(this);
    ((Button) findViewById(R.id.rotate)).setOnClickListener(this);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case TAKE_PICTURE:
        if (resultCode == Activity.RESULT_OK) {
            getContentResolver().notifyChange(mUri, null);
            ContentResolver cr = getContentResolver();
            try {
                mPhoto = android.provider.MediaStore.Images.Media.getBitmap(cr, mUri);
                ((ImageView)findViewById(R.id.photo_holder)).setImageBitmap(mPhoto);
            } catch (Exception e) {
                Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }
    }
}




   @Override
    public void onClick(View v) {
        if (v.getId()== R.id.snap) {
            Intent i = new Intent("android.media.action.IMAGE_CAPTURE");
            File f = new File(Environment.getExternalStorageDirectory(),  "photo.jpg");
            i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
            mUri = Uri.fromFile(f);
            startActivityForResult(i, TAKE_PICTURE);
        } else {
            if (mPhoto!=null) {
                Matrix matrix = new Matrix();
                matrix.postRotate(90);
                mPhoto = Bitmap.createBitmap(mPhoto , 0, 0, mPhoto.getWidth(), mPhoto.getHeight(), matrix, true);
                ((ImageView)findViewById(R.id.photo_holder)).setImageBitmap(mPhoto);
            }
        }
    }
}

0 个答案:

没有答案