Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Thanks,check out this code it may be useful for you to rotate an Bitmap image.. Here i have a taken a aquarium fish example,it should be moved from left to right and flipped and continue moving from right to left and viceversa.. here is the code for you..</p> <pre><code> protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); requestWindowFeature(Window.FEATURE_NO_TITLE); fish = BitmapFactory.decodeResource(getResources(), R.drawable.fish); v = new OurView(this); </code></pre> <p>public class OurView extends SurfaceView implements Runnable {</p> <pre><code> Thread t = null; SurfaceHolder holder; boolean isitOK = false; String Flag = "right"; Bitmap rotatedBitmap=null; Matrix rotateRight = new Matrix(); Matrix rotateLeft = new Matrix(); Bitmap rSprite=null; Bitmap lSprite=null; public OurView(Context context) { super(context); holder = getHolder(); rotateLeft.setScale(-1, 1); rSprite = Bitmap.createBitmap(fish, 0, 0, fish.getWidth(), fish.getHeight(), rotateRight, true); lSprite = Bitmap.createBitmap(fish, 0, 0, fish.getWidth(), fish.getHeight(), rotateLeft, true); } @Override public void run() { // TODO Auto-generated method stub while (isitOK == true) { if (!holder.getSurface().isValid()) { continue; } Canvas canvas = holder.lockCanvas(); canvas.drawBitmap(bg, 0, 0, null); if(Flag == "right") canvas.drawBitmap(lSprite, x, y, null); if(Flag == "left") canvas.drawBitmap(fish, x, y, null); if (Flag == "right" &amp;&amp; x &lt;= 60) { x++; if (x == 60) { Flag = "left"; // canvas.drawBitmap(rSprite, 0, fish.getWidth(), null); canvas.drawBitmap(fish, x, y, null); } } if (Flag == "left" &amp;&amp; x &gt;= 0) { x--; if (x == 0) { Flag = "right"; canvas.drawBitmap(fish, x, y, null); } } holder.unlockCanvasAndPost(canvas); } } </code></pre>
 

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