叠加位图的功能无法正常工作

发布于 2024-12-11 03:27:04 字数 1282 浏览 0 评论 0原文

我正在使用该功能将两个位图文件相互合并,并且它也重叠。 我正在使用此功能将其覆盖在 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; 
      } 

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

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

I am Using the Function to Mearge the Two Bitmap File on One Another and it also overlay.
I am using this Function to Overlay it on 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; 
      } 

But After saving this Image I show that images to be combine with each other. it is not overlay. I want it to be Overlay on One Another.

Please tell me where i am wrong in this Function ??
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

咿呀咿呀哟 2024-12-18 03:27:04

这是叠加两个位图的函数

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;
} 

this is the function to overlay two bitmap,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;
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文