2011-04-14 286 views

回答

3

您是否正在寻找执行转换的算法?

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

如果您想自动确定阈值,您可能需要实施Otsu的方法。当您无法对图像中的像素分布作出太多假设时,该方法总体上会做出正确的工作。

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

作为参考,这就是它看起来像在数学: Binarize[image, threshold],并Binarize[img]对大津算法。

enter image description here

0

可以使用位图转换功能,并将其写入到输出流,然后使用输出流,以获得自己的字节数组 我希望帮助

+1

ü可以提供更多的细节? – barzos 2011-04-15 12:16:41

+0

首先给出你需要什么的更多细节。你的问题没有多大意义。 – 2011-04-15 12:24:31

+0

我没有得到任何想法转换二进制图像 – barzos 2011-04-15 12:51:51

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

试试这个

0

希望这有助于...

Bitmap bitmapObtained =//get your bitmap 
ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
bitmapObtained.compress(Bitmap.CompressFormat.JPEG, 100, stream); 
byte[] byteArray = stream.toByteArray(); 
相关问题