Why layer drawable image get stretched When making a drawable using multiple layers

569 Views Asked by At

I have made an image by combining multiple images putting one over another Using LayerDrawable

But the final image is getting streched

Here is my code for making a layerdrawable

Bitmap mainBitmap;

Resources r = getResources();
Drawable[] layers = new Drawable[10];

layers[0]=r.getDrawable(R.drawable.cloud);

layers[1] = r.getDrawable(fragment.resId1);

layers[2] = r.getDrawable(fragment.resId2);

layers[3] = r.getDrawable(fragment.resId3);

layers[4] = r.getDrawable(fragment.resId4);

layers[5] = r.getDrawable(fragment.resId5);

layers[6] = r.getDrawable(fragment.resId6);

layers[7] = r.getDrawable(fragment.resId7);

layers[8] = r.getDrawable(fragment.resId8);

layers[9] = r.getDrawable(fragment.resId9);
LayerDrawable layerDrawable = new LayerDrawable(layers);
int width = layerDrawable.getIntrinsicWidth();
int height = layerDrawable.getIntrinsicHeight();
mainBitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Canvas canvas = new Canvas(mainBitmap);
layerDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
layerDrawable.draw(canvas);</p>

and Here is the resultant image that i get through this code </p>

https://i.stack.imgur.com/Vuga9.jpg

Is there anyone who can help me to shortout this?

0

There are 0 best solutions below