如何在安卓系统中将位图图像转换为二进制图像?

6

我需要将位图转换为二进制图像以完成我的作业。你知道这方面的任何知识吗?


是的,我对此有所了解...(投票关闭) - WarrenFaith
5个回答

3

你是否正在寻找一个算法来执行转换?

最简单的方法是将每个像素值与固定阈值进行比较:如果像素值小于阈值,则相应的输出像素为黑色(0),否则为白色(1)。

如果您希望自动确定阈值,您可以实现Otsu的方法。当您不能对图像中的像素分布做出太多假设时,该方法总体上能够正确地完成工作。

http://en.wikipedia.org/wiki/Otsu%27s_Method

作为参考,以下是在Mathematica中的样子:Binarize[image, threshold],对于Otsu方法使用Binarize[img]

enter image description here


0
希望这能有所帮助...
Bitmap bitmapObtained =//get your bitmap
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmapObtained.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] byteArray = stream.toByteArray();

0
你可以使用位图转换函数并将其写入输出流,然后使用输出流来获取字节数组。希望这能帮到你。

请提供更多关于您需要的细节。您的问题并不是很明确。 - Kevin Gaudin
我没有想到如何将二进制图像转换。 - barzos

0

-1

也许这是你的代码

imageID = cursor.getString(columnIndex);
              //  uri = Uri.withAppendedPath(Media.EXTERNAL_CONTENT_URI, "" + imageID);
                Log.v("dklfdlk",imageID);
                bitmap = BitmapFactory.decodeFile(imageID);
if (bitmap != null) {
                    newBitmap = Bitmap.createScaledBitmap(bitmap, 78, 78, true);
                    bitmap.recycle();
                    if (newBitmap != null) {
                        publishProgress(new LoadedImage(newBitmap));
}

试试这个


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接