【问题标题】:Function to Overlay Bitmap not working properly覆盖位图的功能无法正常工作
【发布时间】:2011-12-11 15:34:45
【问题描述】:

我正在使用该功能将两个位图文件相互融合,并且它也重叠。 我正在使用此函数将其覆盖在 OneAnother 上。

public static Bitmap combineImages(Bitmap cameraImage, Bitmap visionImage) { // can add a 3rd parameter 'String loc' if you want to save the new image - left some code to do that at the bottom 

     Bitmap finalImage = null; 
        int width, height = 0; 
          width = cameraImage.getWidth(); 
          height = cameraImage.getHeight(); 

        finalImage = Bitmap.createBitmap(width, height, cameraImage.getConfig()); 

        Canvas canvas = new Canvas(finalImage); 

        canvas.drawBitmap(cameraImage, new Matrix(), null);
        canvas.drawBitmap(visionImage, new Matrix(), null);

        // this is an extra bit I added, just incase you want to save the new image somewhere and then return the location 
        /*String tmpImg = String.valueOf(System.currentTimeMillis()) + ".png"; 

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

        return finalImage; 
      } 

但在保存此图像后,我会显示这些图像要相互组合。它不是覆盖。我希望它相互叠加。

请告诉我这个函数哪里错了?? 谢谢。

【问题讨论】:

  • 你想组合位图,就像一个覆盖另一个。
  • 我的第一个图像是 cameraPicture 和 TransperentLayer 的第二个图像。所以我希望将第二个透明图像叠加到第一个图像上。

标签: android android-layout android-emulator android-widget android-ndk


【解决方案1】:

这是叠加两个位图的功能,s

private Bitmap overlayMark(Bitmap bmp1, Bitmap bmp2)    { 
    int bh = originalBitmap.getHeight();
    int bw = originalBitmap.getWidth();
    Bitmap bmOverlay = Bitmap.createBitmap(bw,bh,Bitmap.Config.ARGB_8888); 
    Canvas canvas = new Canvas(bmOverlay); 
    canvas.drawBitmap(bmp1, 0, 0, null);
    canvas.drawBitmap(bmp2, 0,0, null);
    return bmOverlay;
} 

【讨论】:

  • 我已经使用了你的函数但是结果和以前一样。我希望这两个图像相互叠加。但是保存的图像看起来像是相互结合并在一个图像文件中单独显示。
  • 您的回答对我不起作用。我得到了和以前一样的结果
  • 你能贴出你得到的截图吗?
  • 它在我的应用程序中为我工作,我也是这样做的,原始图像上的图像和透明图像。
  • 好的。设备出现问题。这就是为什么我得到以前的结果。但是你的代码工作正常。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-09-23
  • 1970-01-01
  • 1970-01-01
  • 2013-11-06
  • 2013-10-29
  • 1970-01-01
相关资源
最近更新 更多