【问题标题】:Combine two images into one orientation issue将两个图像合并为一个方向问题
【发布时间】:2014-06-14 06:39:27
【问题描述】:

我想制作一个应用程序,用户可以先用后置摄像头拍照,然后再用前置摄像头拍照。

所以,之后我得到了两张位图,我想将它们组合成一张图片。

这段代码我用于前置摄像头参数:

//Set up picture orientation for saving...
Camera.Parameters parameters = theCamera.getParameters();
parameters.setRotation(90);
frontCamera.setParameters(parameters);

//Set up camera preview and set orientation to PORTRAIT
        frontCamera.stopPreview();
        frontCamera.setDisplayOrientation(90);
        frontCamera.setPreviewDisplay(holder);
        frontCamera.startPreview(); 

我用这个代码用前置摄像头拍照

  cameraObject.takePicture(shutterCallback, rawCallback, jpegCallback);

后置摄像头拍照回调

      PictureCallback jpegCallback = new PictureCallback() {
      @Override
      public void onPictureTaken(byte[] data, Camera camera) {
        backBitmap = decodeBitampFromByte(data, 0, 800, 800);   

        frontCameraObject.release();  

        initFrontCamera();  

      }       
};

注意: 类似代码用于前置摄像头拍照。我得到了两个位图,然后我尝试将它们与下面的代码结合起来,但是我保存的位图方向错误。

我使用这段代码来组合两个位图:frontBitmap、backBitmap。

public Bitmap combineImages(Bitmap c, Bitmap s, String loc) 
{ 
Bitmap cs = null; 

int w = c.getWidth() + s.getWidth();
int h;
if(c.getHeight() >= s.getHeight()){
 h = c.getHeight();
}else{
 h = s.getHeight();
}
cs = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); 

Canvas comboImage = new Canvas(cs); 

comboImage.drawBitmap(c, 0f, 0f, null);
comboImage.drawBitmap(s, c.getWidth, 0f, null);


    String tmpImg = String.valueOf(System.currentTimeMillis()) + ".png";

    OutputStream os = null;
    try {
        os = new FileOutputStream(loc + tmpImg);
        cs.compress(CompressFormat.PNG, 100, os);
    } catch (IOException e) {
        Log.e("combineImages", "problem combining images", e);
    }           

       return cs; 
   }  

注意 带瓶水的图像是用后置摄像头拍摄的,其他是用前置摄像头拍摄的。

【问题讨论】:

  • 您保存的位图是横向的。你想要它的肖像吗?您还没有告诉我们组合的位图应该是什么样子。你想要什么?
  • 是的,我想要它在肖像中。合图上半部分为后置摄像头,下半部分为前置摄像头。
  • 然后不要像这里那样添加宽度: int w = c.getWidth() + s.getWidth();而是添加高度。并将两个位图旋转到正确的位置(如果你想要的话)。
  • 我尝试过像这样更改代码,但它仍然不起作用,即使我看不到正面图像。诠释 w; int h = c.getHeight() + s.getHeight(); if(c.getHeight() >= s.getHeight()){ w = c.getWidth(); }else{ w = s.getWidth(); }
  • 在 if 语句中你应该比较宽度!对于第二个 drawBitmap() 调整 x,y。

标签: android bitmap android-camera android-canvas android-bitmap


【解决方案1】:

尝试将comboImage.drawBitmap(s, c.getWidth, 0f, null); 更改为

comboImage.drawBitmap(s, 0f,c.getHeigh, null);

【讨论】:

    猜你喜欢
    • 2016-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-29
    相关资源
    最近更新 更多