本文介绍了保存图像叠加相机拍摄的图像underneith的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有一个大头功能,这将允许用户拍摄照片的相机,并在同一时间上显示的摄像机视图的顶部叠加图像。在拍摄完照片后,我需要保存什么用户看到的,而拍摄照片的文件系统。

我曾经历过1大问题,同时制定了解决这个:捕捉图像与兼容的尺寸,我可以将一个叠加图像产生什么样的用户看到的,而拍照

我似乎无法从相机定义尺寸(我基本上选择从他们的列表)拍摄的图像。有些手机只可以产生一定的尺寸。

既然不能选择拍摄图像的尺寸,它好像我将要求包括许多不同尺寸的叠加图像,并附加了最佳匹配拍摄的图像。我不能只拍任何旧叠加在摄像机图像的顶部,使它看起来正确的。

问题:

  • 我是过于复杂这个摄像头+图像叠加图像创作的过程?
  • 在做什么建议你在完成这个任务,而不包括几个不同大小的叠加图像的需要?

编辑:下面是我的解决方案(简介)。请知道这是不是一个完美的,也许不是最有效的方法来做到这一点,但它的作品。有些东西可能是不必要的/多余的,但不管!

注:

  • 在这不起作用太大的平板电脑设备。
  • 的叠加图像需要旋转为横向模式(即使你将采取的图像保存在手机中的纵向)
  • 在覆盖规模小480x320
  • 您需要强制活动为横向模式,而拍摄照片(现已覆盖看起来像它的画像!)
  • 在我添加使用 addContentView(overlayImageView,新的LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT))的叠加图像视图;

...

 最后Camera.PictureCallback jpegCallback =新Camera.PictureCallback(){
    @覆盖
    公共无效onPictureTaken(byte []的数据,摄像头摄像头){
        BitmapFactory.Options选项=新BitmapFactory.Options();
        位图mut​​ableBitmap = NULL;
        尝试 {
                    //对于肖像覆盖,并采取像握着手机在纵向模式
            mutableBitmap = BitmapFactory.de codeByteArray(数据,0,data.length,期权).copy(Bitmap.Config.RGB_565,真正的);
            字模=新的Matrix();
            INT宽度= mutableBitmap.getWidth();
            INT高= mutableBitmap.getHeight();
            。INT newWidth = overlayImage.getDrawable()的getBounds()宽();
            。INT newHeight = overlayImage.getDrawable()的getBounds()高度();
            浮动scaleWidth =((浮点)newWidth)/宽度;
            浮动scaleHeight =((浮点)newHeight)/身高;
            matrix.postScale(scaleWidth,scaleHeight);
            matrix.postRotate(90);

            位图resizedBitmap = Bitmap.createBitmap(mutableBitmap,0,0,mutableBitmap.getWidth(),mutableBitmap.getHeight(),矩阵,真);
            finalBitmap = resizedBitmap.copy(Bitmap.Config.RGB_565,真正的);
            帆布油画=新的Canvas(finalBitmap);

            位图overlayBit​​map = BitmapFactory.de codeResource(getResources(),叠加);
            矩阵=新的Matrix();
            matrix.postRotate(90);
            位图resizedOverlay = Bitmap.createBitmap(overlayBit​​map,0,0,overlayBit​​map.getWidth(),overlayBit​​map.getHeight(),矩阵,真);
            canvas.drawBitmap(resizedOverlay,0,0,新的油漆());
            canvas.scale(50,0);
            canvas.save();
            // finalBitmap是与它的叠加图像
        }
        赶上(OutOfMemoryError异常E){
            //失败
        }
    }
}
 

解决方案

我觉得这是你如何处理你覆盖的问题。您可以根据所拍摄的图像尺寸裁剪,并调整其大小,以适应,preserving其比例。您可以将叠加,其比例比作底色比,它的最佳位置。

我会使用过滤器,具有良好的热心公益事业绘制覆盖保持足够大,具有广泛的边界(出血),以轻松地将其大小为图像。我猜覆盖的一些东西,你会设计,并有透明的部分,像一个小丑的形象没有面子,使用户可以捕捉偷别人的脸成吗?

My application has a "photobooth" feature which will allow the user to take a picture with the camera and at the same time show an overlay image on top of the camera view. After the picture is taken, i need to save what the user saw while taking the picture to the filesystem.

I have experienced 1 big problem while developing a solution to this: capturing an image with the compatible dimensions in which i can attach an overlay image to resulting in what the user saw while taking the picture.

It seems i cannot capture an image from the camera with defined dimensions(i have to basically pick from a list of them). Some phones only can produce certain dimensions.

Since i cannot choose the size of the captured image, it seems as though i will be required to include many different sizes of the overlay image, and attach the best match to the captured image. I can't just slap any old overlay on top of the camera image and make it look right.

Questions:

  • Am i over-complicating this "camera image + overlay image creation" process?
  • What suggestions do you have in completing this task without the need of including several different sizes overlay images?

Edit:Here is my solution(brief). Please realize this is not a perfect and maybe not most efficient way to do this, but it works. Some things may be unnecessary/redundant but whatever!

Notes:

  • this doesn't work too great on tablet devices.
  • the overlay image needs to be rotated to be in landscape mode(even though you will be taking the image holding the phone in portrait)
  • overlay size is 480x320
  • you need to force the activity to landscape mode while taking the picture(now the overlay looks like its portrait!)
  • i add the overlay image view using addContentView(overlayImageView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

...

final Camera.PictureCallback jpegCallback = new Camera.PictureCallback() {
    @Override
    public void onPictureTaken(byte[] data, Camera camera) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        Bitmap mutableBitmap = null;
        try {
                    //for a PORTRAIT overlay and taking the image holding the phone in PORTRAIT mode
            mutableBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options).copy(Bitmap.Config.RGB_565, true);
            Matrix matrix = new Matrix();
            int width = mutableBitmap.getWidth();
            int height = mutableBitmap.getHeight();
            int newWidth = overlayImage.getDrawable().getBounds().width();
            int newHeight = overlayImage.getDrawable().getBounds().height();
            float scaleWidth = ((float) newWidth) / width;
            float scaleHeight = ((float) newHeight) / height;
            matrix.postScale(scaleWidth, scaleHeight);
            matrix.postRotate(90);

            Bitmap resizedBitmap = Bitmap.createBitmap(mutableBitmap, 0, 0, mutableBitmap.getWidth(), mutableBitmap.getHeight(), matrix, true);
            finalBitmap = resizedBitmap.copy(Bitmap.Config.RGB_565, true);
            Canvas canvas = new Canvas(finalBitmap);

            Bitmap overlayBitmap = BitmapFactory.decodeResource(getResources(), overlay);
            matrix = new Matrix();
            matrix.postRotate(90);
            Bitmap resizedOverlay = Bitmap.createBitmap(overlayBitmap, 0, 0, overlayBitmap.getWidth(), overlayBitmap.getHeight(), matrix, true);
            canvas.drawBitmap(resizedOverlay, 0, 0, new Paint());
            canvas.scale(50, 0);
            canvas.save();
            //finalBitmap is the image with the overlay on it
        }
        catch(OutOfMemoryError e) {
            //fail
        }
    }
}
解决方案

I think this is a question of how you manipulate your overlays. You can crop it according to the captured image size and resize it to fit, preserving its ratio. You can place the overlay, by comparing its ratio to the backround ratio, to its optimal position.

I would keep overlays big enough, with a wide border (bleed), to easily size them to an image using filters to draw it with good qaulity. I guess overlays are something which you would design and have transparent parts, like an image of a clown without a face so the user can snap somebody elses face into it?

这篇关于保存图像叠加相机拍摄的图像underneith的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 15:36