How to convert bitmap image to binary image in android?
I need to convert bitmap to binary image for my开发者_Python百科 hw.Do u know anything about that?
Are you looking for an algorithm to perform the conversion?
The easiest way is to compare each pixel value with a fixed threshold: if the pixel value is less than the threshold, the corresponding output pixel is black (0), else it is white (1).
If you wish to determine the threshold automatically, you may want to implement Otsu's method. That method does a correct job overall when you can't make too many assumptions about the pixels distribution in your image.
http://en.wikipedia.org/wiki/Otsu%27s_Method
As a reference, that's how it looks like in Mathematica:
Binarize[image, threshold]
, and Binarize[img]
for Otsu's method.
You can use the bitmap convert function and write it to an output stream and then use the output stream to get for yourself the byte array I hope that helps
you can look this link converting Java bitmap to byte array, it can convert bitmap to binary, can then you should look at display image from byteArray
Hope this helps...
Bitmap bitmapObtained =//get your bitmap
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmapObtained.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] byteArray = stream.toByteArray();
perhaps this is your code
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));
}
try this
精彩评论