Note that there are some explanatory texts on larger screens.

plurals
  1. POconvert an image to binary image in android
    primarykey
    data
    text
    <p>I'm trying to build simple android project to convert image to binary format , but when I check pixels value ,i get zeros only. I don't know where is the problem. Any one can help me please. This is my code </p> <pre><code>iv = (ImageView) findViewById (R.id.uploadImage); //convert the image view into bitmap iv.buildDrawingCache(); bmap = iv.getDrawingCache(); int red; int newPixel = 0; int threshold =230; int width = bmap.getWidth(); int hieght = bmap.getHeight(); int[] pix = new int[width * hieght]; int[] pix2 = new int[width * hieght]; int alpha = 0; bmap.getPixels(pix, 0, width, 0, 0, width, hieght); //convert the image into white and black for (int i=0;i&lt;width;i++) { for (int j=0;j&lt;hieght;j++) { int index = j * width + i; red = (pix[index] &gt;&gt; 16) &amp; 0xff; alpha = (pix[index] &gt;&gt; 24) &amp; 0xff; if (red&lt;threshold) { newPixel = 0; } else { newPixel = 255; } newPixel = colorToRGB(alpha, newPixel, newPixel, newPixel); bmap.setPixel(i, j, newPixel); iv.setImageBitmap(bmap); } } //convert the black and white image view into bitmap bmap.getPixels(pix2, 0, bmap.getWidth(), 0, 0, bmap.getWidth(),bmap.getHeight()); StringBuilder builder = new StringBuilder(); for (int i :pix2) { builder.append(" " + i + " "); } Toast.makeText(this, builder, Toast.LENGTH_LONG).show(); private static int colorToRGB (int alpha, int red, int green, int blue) { int newPixel = 0; newPixel += alpha; newPixel = newPixel &lt;&lt; 8; newPixel += red; newPixel = newPixel &lt;&lt; 8; newPixel += green; newPixel = newPixel &lt;&lt; 8; newPixel += blue; return newPixel; } </code></pre> <p>this is logcat</p> <blockquote> <p>08-12 08:52:32.887: D/dalvikvm(774): GC_CONCURRENT freed 71K, 7% free 2765K/2964K, paused 23ms+15ms, total 94ms</p> <p>08-12 08:52:33.497: D/gralloc_goldfish(774): Emulator without GPU emulation detected.</p> <p>08-12 08:52:40.698: D/dalvikvm(774): GC_CONCURRENT freed 63K, 6% free 3087K/3272K, paused 73ms+3ms, total 165ms</p> <p>08-12 08:52:49.397: I/Choreographer(774): Skipped 39 frames! The application may be doing too much work on its main thread.</p> <p>08-12 08:52:54.568: D/dalvikvm(774): GC_FOR_ALLOC freed 9K, 5% free 3124K/3272K, paused 68ms, total 81ms</p> <p>08-12 08:52:54.617: I/dalvikvm-heap(774): Grow heap (frag case) to 6.166MB for 3145744-byte allocation</p> <p>08-12 08:52:54.778: D/dalvikvm(774): GC_FOR_ALLOC freed 40K, 4% free 6155K/6348K, paused 156ms, total 156ms</p> <p>08-12 08:52:55.008: D/dalvikvm(774): GC_CONCURRENT freed &lt;1K, 4% free 6155K/6348K, paused 80ms+38ms, total 231ms</p> <p>08-12 08:52:55.898: I/Choreographer(774): Skipped 412 frames! The application may be doing too much work on its main thread.</p> <p>08-12 08:52:57.898: D/dalvikvm(774): GC_FOR_ALLOC freed 38K, 4% free 6119K/6348K, paused 28ms, total 30ms</p> <p>08-12 08:52:57.929: I/dalvikvm-heap(774): Grow heap (frag case) to 9.091MB for 3145744-byte allocation</p> <p>08-12 08:52:58.058: D/dalvikvm(774): GC_CONCURRENT freed &lt;1K, 3% free 9191K/9424K, paused 82ms+6ms, total 125ms</p> <p>08-12 08:52:58.058: D/dalvikvm(774): WAIT_FOR_CONCURRENT_GC blocked 40ms</p> <p>08-12 08:52:58.089: I/dalvikvm-heap(774): Grow heap (frag case) to 12.090MB for 3145744-byte allocation</p> <p>08-12 08:52:58.218: D/dalvikvm(774): GC_FOR_ALLOC freed &lt;1K, 2% free 12263K/12500K, paused 125ms, total 126ms</p> <p>08-12 08:52:58.288: D/dalvikvm(774): GC_CONCURRENT freed 0K, 2% free 12263K/12500K, paused 4ms+16ms, total 70ms</p> <p>08-12 08:56:37.707: E/Trace(886): error opening trace file: No such file or directory (2) 08-12 08:56:38.518: D/dalvikvm(886): GC_CONCURRENT freed 41K, 6% free 2805K/2968K, paused 13ms+3ms, total 77ms</p> <p>08-12 08:56:38.518: D/dalvikvm(886): WAIT_FOR_CONCURRENT_GC blocked 10ms</p> <p>08-12 08:56:38.727: D/gralloc_goldfish(886): Emulator without GPU emulation detected.</p> <p>08-12 08:56:55.107: D/dalvikvm(886): GC_FOR_ALLOC freed 23K, 5% free 3083K/3236K, paused 69ms, total 78ms</p> <p>08-12 08:56:55.207: I/dalvikvm-heap(886): Grow heap (frag case) to 6.126MB for 3145744-byte allocation</p> <p>08-12 08:56:55.367: D/dalvikvm(886): GC_FOR_ALLOC freed 1K, 3% free 6153K/6312K, paused 156ms, total 156ms</p> <p>08-12 08:56:55.607: D/dalvikvm(886): GC_CONCURRENT freed 4K, 3% free 6149K/6312K, paused 80ms+32ms, total 245ms</p> <p>08-12 08:56:56.747: I/Choreographer(886): Skipped 465 frames! The application may be doing too much work on its main thread.</p> <p>08-12 08:58:03.287: D/dalvikvm(936): GC_CONCURRENT freed 44K, 6% free 2805K/2972K, paused 15ms+3ms, total 76ms</p> <p>08-12 08:58:03.287: D/dalvikvm(936): WAIT_FOR_CONCURRENT_GC blocked 9ms</p> <p>08-12 08:58:03.637: D/gralloc_goldfish(936): Emulator without GPU emulation detected.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload