如何保存之前的相机拍摄的图像中的任何图像绑定?图像、绑定、相机

2023-09-04 08:04:31 作者:帅到被人砍

可能重复:   Android:如何叠加一个位图/画,在一个位图?

我已经实现艾米应用程序的Andr​​oid摄像头功能。

I have implement the android Camera functionality in amy application.

现在我想任何transperent图像结合的相机拍摄的图像之前保存的图像中库,那么它如何可以做到?

Now i want to combine any transperent image with that captured camera Image before to save that image in to gallery, then how it can be done ??

任何code会真的appereciated。 谢谢你。

Any code will be realy appereciated. Thanks.

编辑: 我用这code,以捕捉并保存图像,这样,我怎么768,16必须实现这样的事情。

I am using this Code to captured and Save the Image So, How shoud i have to Implement Such things.

takePhotoBtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) { // <5>

            ImageCaptureCallback iccb = null;

            try {
                String filename = timeStampFormat.format(new Date());
                ContentValues values = new ContentValues();
                values.put(Media.TITLE, filename);
                values.put(Media.DESCRIPTION, "Image capture by camera");
                Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);

                iccb = new ImageCaptureCallback( getContentResolver().openOutputStream(uri));

                // to put the Image on captured image.
                Canvas canvas = new Canvas();
                Bitmap kangoo = BitmapFactory.decodeResource(getResources(),
                        R.drawable.icon);
                canvas.drawColor(Color.argb(160, 21, 140, 21));
                canvas.drawBitmap(kangoo, 130, 10, null);


            } catch(Exception ex ){
                ex.printStackTrace();
                Log.e(getClass().getSimpleName(), ex.getMessage(), ex);
            }
          camera.takePicture(mShutterCallback, mPictureCallbackRaw, iccb);
        }
      });


Camera.PictureCallback mPictureCallbackRaw = new Camera.PictureCallback() {
    public void onPictureTaken(byte[] data, Camera c) {
        Log.e(getClass().getSimpleName(), "PICTURE CALLBACK RAW: " + data);
            System.out.println("\n\n\n\nThe Data in mPictureCallbackRaw is :"+data);
        //camera.startPreview(); // Added StastPreview();
    }
};

Camera.PictureCallback mPictureCallbackJpeg= new Camera.PictureCallback() {
    public void onPictureTaken(byte[] data, Camera c) {
        Log.e(getClass().getSimpleName(), "PICTURE CALLBACK JPEG: data.length = " + data);
        System.out.println("\n\n\n\nThe Data in mPictureCallbackJPEG is :"+data);
        camera.startPreview();
    }
};

Camera.ShutterCallback mShutterCallback = new Camera.ShutterCallback() {
    public void onShutter() {
        Log.e(getClass().getSimpleName(), "SHUTTER CALLBACK");
    }
};




public class ImageCaptureCallback implements PictureCallback  {

private OutputStream filoutputStream;
public ImageCaptureCallback(OutputStream filoutputStream) {
    this.filoutputStream = filoutputStream;
}
@Override
public void onPictureTaken(byte[] data, Camera camera) {
    try {
        Log.v(getClass().getSimpleName(), "onPictureTaken=" + data + " length = " + data.length);

        filoutputStream.write(data);
        filoutputStream.flush();
        filoutputStream.close();


    } catch(Exception ex) {
        ex.printStackTrace();
    }
}

}

推荐答案

试试这个结合了两个位图摄像机的图像和透明图像。这是结合图像,并存储在SD卡

Try this to combine the two Bitmaps the Camera Image and Transparent Image. This is combine of the images and store in the SDCard.

public Bitmap combineImages(Bitmap c, Bitmap s) {

        Bitmap cs = null;
        int width, height = 0;

        if (c.getWidth() > s.getWidth()) {
            width = c.getWidth();
            height = c.getHeight();
        } else {
            width = s.getWidth() + s.getWidth();
            height = c.getHeight();
        }

        cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

        Canvas comboImage = new Canvas(cs);

        comboImage.drawBitmap(c, 0, 0, null);
        comboImage.drawBitmap(s, 100, 300, null);

        /******
         * 
         *   Write file to SDCard
         * 
         * ****/

        String tmpImg = String.valueOf(System.currentTimeMillis()) + ".png";
        OutputStream os = null;
        try {
            os = new FileOutputStream(Environment.getExternalStorageDirectory()
                    + "/"+tmpImg);
            cs.compress(CompressFormat.PNG, 100, os);
        } catch (IOException e) {
            Log.e("combineImages", "problem combining images", e);
        }
        return cs;
    }