0

this is my code i want to scale my drawable image and set on image view please help me here in my code i want to scale bitmap1 please check my code

         protected Bitmap murge() 
         { 
        Murge_Bitmap = null;
        Murge_Bitmap = Bitmap.createBitmap(600, 600, Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(Murge_Bitmap);
        Resources res = getResources(); 
        bitmap1 = BitmapFactory.decodeResource(res, R.drawable.sample_pic); 
        Bitmap bitmap2=Bitmap.createScaledBitmap(bitmap1, 600, 600, true);

        Drawable drawable1 = new BitmapDrawable(Bitmap_recieve);
        Drawable drawable2 = new BitmapDrawable(bitmap2);
         //   c.drawBitmap(Murge_Bitmap, 500,500, null);
        drawable1.setBounds(200, 200, 400, 400);
        drawable2.setBounds(200, 240, 400, 400);
        drawable1.draw(c);
        drawable2.draw(c);


        return Murge_Bitmap;
             }

1 Answers1

0

You can use this: Decode the resource and pass it to this function with scalingfactor

public static Bitmap ScaleBitmap(Bitmap bm, float scalingFactor) {
    int scaleHeight = (int) (bm.getHeight() * scalingFactor);
    int scaleWidth = (int) (bm.getWidth() * scalingFactor);
    return Bitmap.createScaledBitmap(bm, scaleWidth, scaleHeight, true);
}

for scaling factor refer to this Scale factor for xxhdpi android?

Community
  • 1
  • 1
Vikas Rathod
  • 374
  • 2
  • 14
  • i want to scale manually by user in my application by touch event please give me source code for touchevent – ravi patidar Feb 11 '14 at 13:22
  • scale manually?? you mean to say corp image? or let the user select the scaling factor, height and weight ?? – Vikas Rathod Feb 11 '14 at 13:41
  • not crop, resize by user large and small according their requirement – ravi patidar Feb 11 '14 at 13:46
  • you can use seekbar in android and imageview, get the value form the seekbar and pass it to scaleBitmap function. http://www.compiletimeerror.com/2013/09/android-seekbar-example.html#.UvorxPmSySo – Vikas Rathod Feb 11 '14 at 13:57