【问题标题】:How to draw the Small logo type image at Right-Bottom corner of the canvas?如何在画布的右下角绘制小标志类型的图像?
【发布时间】:2011-12-28 11:32:05
【问题描述】:

在我的应用程序中,我使用画布进行绘画。 现在在这个应用程序中,我想在画布的右下角绘制小徽标图像,然后将其保存到位图中。 那么如何实现呢?

【问题讨论】:

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


    【解决方案1】:

    如果我理解正确,请尝试

    context.drawImage(img_elem, x, y);
    

    插入您的图像(其中 img_elem 是您的图像参考,x/y 是您的目标坐标)。

    要使用 x 和 y,具体取决于您希望插入图像的位置,请尝试以下操作:

    x = canvasWidth-25;
    y = canvasHeight-25;
    

    把它放在右下角。

    然后,照常转换为图像:

    var dataURL = canvas.toDataURL();
    

    【讨论】:

    • 请看我的回答。我得到了解决方案。
    • 除非您要绘制位图,然后在位图顶部绘制徽标。您的问题询问如何在将其制作为位图之前在画布上绘制它。基本上你的代码做了我上面写的,我很高兴它对你有用,但你没有直接插入到画布中(尽管我怀疑这对你的情况很重要)。
    【解决方案2】:

    在谷歌搜索和搜索代码之后,我得到了问题的答案: 我使用这个函数来获取右下角的图像。

     public static Bitmap addLogo(Bitmap mainImage, Bitmap logoImage) { 
        Bitmap finalImage = null; 
            int width, height = 0; 
            width = mainImage.getWidth(); 
            height = mainImage.getHeight(); 
            finalImage = Bitmap.createBitmap(width, height, mainImage.getConfig()); 
            Canvas canvas = new Canvas(finalImage); 
            canvas.drawBitmap(mainImage, 0,0,null);
            canvas.drawBitmap(logoImage, canvas.getWidth()-logoImage.getWidth() ,canvas.getHeight()-logoImage.getHeight() ,null);
    
            return finalImage; 
    }
    

    希望此代码对其他人有所帮助。 谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多