Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks @Maxim Efimov &amp; @StackOverflowException</p> <p>Just in Case Someone will need a snippet for this kind of problems:</p> <p>this method returns a cut out smaller Bitmap with Margins removed. passing the pixels to a int-array first and then working with the array is a bit faster than the Bitmap.getPixel method</p> <p>just call the method indicating Source Bitmap and Background color.</p> <pre><code>Bitmap bmp2 = removeMargins(bmp, Color.WHITE); private static Bitmap removeMargins2(Bitmap bmp, int color) { // TODO Auto-generated method stub long dtMili = System.currentTimeMillis(); int MTop = 0, MBot = 0, MLeft = 0, MRight = 0; boolean found1 = false, found2 = false; int[] bmpIn = new int[bmp.getWidth() * bmp.getHeight()]; int[][] bmpInt = new int[bmp.getWidth()][bmp.getHeight()]; bmp.getPixels(bmpIn, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight()); for (int ii = 0, contX = 0, contY = 0; ii &lt; bmpIn.length; ii++) { bmpInt[contX][contY] = bmpIn[ii]; contX++; if (contX &gt;= bmp.getWidth()) { contX = 0; contY++; if (contY &gt;= bmp.getHeight()) { break; } } } for (int hP = 0; hP &lt; bmpInt[0].length &amp;&amp; !found2; hP++) { // looking for MTop for (int wP = 0; wP &lt; bmpInt.length &amp;&amp; !found2; wP++) { if (bmpInt[wP][hP] != color) { Log.e("MTop 2", "Pixel found @" + hP); MTop = hP; found2 = true; break; } } } found2 = false; for (int hP = bmpInt[0].length - 1; hP &gt;= 0 &amp;&amp; !found2; hP--) { // looking for MBot for (int wP = 0; wP &lt; bmpInt.length &amp;&amp; !found2; wP++) { if (bmpInt[wP][hP] != color) { Log.e("MBot 2", "Pixel found @" + hP); MBot = bmp.getHeight() - hP; found2 = true; break; } } } found2 = false; for (int wP = 0; wP &lt; bmpInt.length &amp;&amp; !found2; wP++) { // looking for MLeft for (int hP = 0; hP &lt; bmpInt[0].length &amp;&amp; !found2; hP++) { if (bmpInt[wP][hP] != color) { Log.e("MLeft 2", "Pixel found @" + wP); MLeft = wP; found2 = true; break; } } } found2 = false; for (int wP = bmpInt.length - 1; wP &gt;= 0 &amp;&amp; !found2; wP--) { // looking for MRight for (int hP = 0; hP &lt; bmpInt[0].length &amp;&amp; !found2; hP++) { if (bmpInt[wP][hP] != color) { Log.e("MRight 2", "Pixel found @" + wP); MRight = bmp.getWidth() - wP; found2 = true; break; } } } found2 = false; int sizeY = bmp.getHeight() - MBot - MTop, sizeX = bmp.getWidth() - MRight - MLeft; Bitmap bmp2 = Bitmap.createBitmap(bmp, MLeft, MTop, sizeX, sizeY); dtMili = (System.currentTimeMillis() - dtMili); Log.e("Margin 2", "Time needed " + dtMili + "mSec\nh:" + bmp.getWidth() + "w:" + bmp.getHeight() + "\narray x:" + bmpInt.length + "y:" + bmpInt[0].length); return bmp2; } </code></pre>
    singulars
    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.
    1. This table or related slice is empty.
    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