Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Actually I am placing an image as background in a view. I want to clip that image and the clipped image should fill the entire view. I am not getting it right.can you help. here is my code....</p> <p>try{ setContentView(R.layout.main); ImageView img = (ImageView)findViewById(R.id.img);</p> <pre><code> Paint paint = new Paint(); paint.setFilterBitmap(true); Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),R.drawable.puli); int targetWidth = 300; int targetHeight = 300; Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight,Bitmap.Config.ARGB_8888); // System.out.println(" P ointsArrayX =" + PointsArrayX[i-1] + " PointsArrayY =" + PointsArrayY[i-1]); RectF rectf = new RectF(0, 00, 100, 100); Canvas canvas = new Canvas(targetBitmap); Path path = new Path(); path.addRect(rectf, Path.Direction.CW); canvas.clipPath(path); canvas.drawBitmap( bitmapOrg,new Rect(0, 0, bitmapOrg.getWidth(), bitmapOrg.getHeight()), new Rect(0, 0, targetWidth, targetHeight), null); </code></pre> <p>// Matrix matrix = new Matrix(); // // resize the bit map // matrix.postScale(100, 133); //<br> // Bitmap resizedBitmap = Bitmap.createBitmap(targetBitmap, 0, 0, 100, 133, matrix, true); // //<br> /*convert Bitmap to resource */ BitmapDrawable bd = new BitmapDrawable(targetBitmap);</p> <pre><code> AbsoluteLayout.LayoutParams abs_params = new AbsoluteLayout.LayoutParams( //width in pixels 30, //height in pixels 40, 0, 0 ); img.setLayoutParams(abs_params); img.setImageDrawable(bd); img.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { System.out.println("onTouch"); return false; } }); } catch(Exception e){ System.out.println("Error1 : " + e.getMessage() + e.toString()); } </code></pre> <p>//my main.xml is</p> <p> android:layout_height="300dp" android:layout_width="300dp" android:id="@+id/img" android:layout_x="10dip" android:layout_y="50dip"</p> <blockquote> <p> </p> </blockquote> <p>the problem is that the image is clipped and placed in the view but the clipped portion is still there. I was not able to resize the image to fit that view.Help me to solve this.Thankyou.</p>
 

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