Android:如何覆盖位图并在位图上绘制? [英] Android: How to overlay a bitmap and draw over a bitmap?

查看:31
本文介绍了Android:如何覆盖位图并在位图上绘制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其实我有三个问题:

  1. 是在位图上绘制图像还是创建位图作为资源然后在位图上绘制更好?性能方面,哪个更好?
  2. 如果我想在位图上绘制透明的东西,我该怎么做?
  3. 如果我想将一个透明位图覆盖在另一个透明位图上,我该怎么做?

抱歉,列表太长,但为了学习的兴趣,我想探索这两种方法.

Sorry for the long list, but in the interest of learning, I would like to explore both the approaches.

推荐答案

我不敢相信还没有人回答这个问题!在 SO 上很少发生!

I can't believe no one has answered this yet! A rare occurrence on SO!

这个问题对我来说不是很有意义.但我会试一试.如果您问的是直接绘制到画布(多边形、阴影、文本等)与加载位图并将其逐位传输到画布上,这取决于您的绘图的复杂性.随着绘图变得越来越复杂,所需的 CPU 时间也会相应增加.但是,将位图块传输到画布上将始终是一个与位图大小成正比的恒定时间.

The question doesn't quite make sense to me. But I'll give it a stab. If you're asking about direct drawing to a canvas (polygons, shading, text etc...) vs. loading a bitmap and blitting it onto the canvas that would depend on the complexity of your drawing. As the drawing gets more complex the CPU time required will increase accordingly. However, blitting a bitmap onto a canvas will always be a constant time which is proportional to the size of the bitmap.

在不知道什么是某事"的情况下,我如何向您展示如何去做?您应该能够从 #3 的答案中找出 #2.

Without knowing what "something" is how can I show you how to do it? You should be able to figure out #2 from the answer for #3.

假设:

  • bmp1 大于 bmp2.
  • 您希望它们都从左上角重叠.

  • bmp1 is larger than bmp2.
  • You want them both overlaid from the top left corner.

    private Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
        Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
        Canvas canvas = new Canvas(bmOverlay);
        canvas.drawBitmap(bmp1, new Matrix(), null);
        canvas.drawBitmap(bmp2, new Matrix(), null);
        return bmOverlay;
    }

这篇关于Android:如何覆盖位图并在位图上绘制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆