如何检查Android中的位图(或画布)是否为空 [英] How to check if a bitmap (or canvas) is empty in Android

查看:383
本文介绍了如何检查Android中的位图(或画布)是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果Android中的位图或画布为空,我必须实现一个返回布尔值的函数.

I have to implement a function that return to me a boolean if a bitmap or canvas is empty in Android.

我该怎么做?

我已经尝试过此解决方案,但是它不起作用:

I have tried this solution, but it doesn't work:

Bitmap emptyBitmap = Bitmap.createBitmap(myBitmap.getWidth(), myBitmap.getHeight(), myBitmap.getConfig());
if (myBitmap.sameAs(emptyBitmap)) {
    // myBitmap is empty/blank
}

如何检查位图是否在Android上为空(空白)

我考虑过的另一种解决方案是:

Another solution that I have considerated is:

最快的方法检查图像是全白还是全透明

但是我无法检查每个像素,我在这项操作中花费了很多时间

But I can't check every pixels, I spend so much time in this operation

推荐答案

很抱歉,现在太晚了,最好的方法是创建一个位图并检查是否相同,因此boolean Res (bitmap.sameAs())

Sorry it's so late apparently the best way to do this is to create a bitmap and check if it's the same so boolean Res (bitmap.sameAs())

这篇关于如何检查Android中的位图(或画布)是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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