Note that there are some explanatory texts on larger screens.

plurals
  1. POIn Android, how to shift a bitmap?
    primarykey
    data
    text
    <p>I am trying, unsuccessfully, to "shift" a bitmap. By "shift", I mean: if I have a 500x300 and I shift it 50 pixels to the right, the result should be a 500x300 bitmap where every pixel has been shifted 50 pixels to the left, and the 50 right most pixels are blank. So, the new image is the same as the old one except the left side is cropped, and a blank area is appended to the right side. The below code successfully crops the left side, but it does not produce a blank area on the right side, it just produces a narrower bitmap:</p> <pre><code>Bitmap newBitmap = Bitmap.createBitmap(oldBitmap.getWidth(), m_CurrentBitmap.getHeight(), Config.ARGB_8888); newBitmap = Bitmap.createBitmap(oldBitmap.getWidth(), deltaX, 0, oldBitmap.getWidth() - deltaX, oldBitmap.getHeight()); </code></pre> <p>So then I tried creating a new Bitmap with the desired dimensions, and manually setting the pixels (with an offset). However, this still produces a narrower Bitmap, lacking the blank area on the right side:</p> <pre><code>Bitmap newBitmap = Bitmap.createBitmap(oldBitmap.getWidth(), oldBitmap.getHeight(), Config.ARGB_8888); int[] oldPixels = new int[(int)(oldBitmap.getWidth() - deltaX) * oldBitmap.getHeight()]; m_CurrentBitmap.getPixels(oldPixels, 0, (int) (oldBitmap.getWidth() - deltaX), (int)deltaX, 0, (int) (oldBitmap.getWidth() - deltaX), oldBitmap.getHeight()); newBitmap.setPixels(oldPixels, 0, (int) (oldBitmap.getWidth() - deltaX), 0, 0, (int) (oldBitmap.getWidth() - deltaX), oldBitmap.getHeight()); </code></pre>
    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.
    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