0

i'have Get Bitmap from oneActivity to secondSctivity in imageview. Now i want this bitmap as the same size of Imageview. but this code is now working.

    ViewTreeObserver vto = ph.getViewTreeObserver(); 
    vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        public boolean onPreDraw() {
            ph.getViewTreeObserver().removeOnPreDrawListener(this); 
            ph.getMeasuredWidth();
            ph.getMeasuredHeight(); 
            return true;
            } 
        });


    // set contact Photo Bitmap in Image view-------------------------------------------------

    byte[] byteArray = getIntent().getByteArrayExtra("image");
    if (byteArray != null) {
        bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
    }

    if (bmp != null) {
        Bitmap bmpimg = Bitmap.createScaledBitmap(bmp,ph.getMeasuredWidth(),ph.getMeasuredHeight() , true);
        ph.setImageBitmap(createRoundedBitmap(bmpimg,5));



    } else {
        ph.setImageResource(R.drawable.upload_photo);
    }

what i have to do for that???

user3855491
  • 15
  • 1
  • 7

2 Answers2

0

will you can get ImageView size by imageViewObject.getWidth(); and obj.getHeight(); then scaled your bitmap following those value not tested.

Bitmap bmpimg = Bitmap.createScaledBitmap(bmp, obj.getWidth(), getHeight(), true);

i hope this helps.

NoXSaeeD
  • 924
  • 1
  • 7
  • 13
  • this is not work....ViewTreeObserver vto = ph.getViewTreeObserver(); vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { public boolean onPreDraw() { ph.getViewTreeObserver().removeOnPreDrawListener(this); ph.getMeasuredWidth(); ph.getMeasuredWidth(); return true; } }); – user3855491 Jul 23 '14 at 05:05
  • haa!! what?! what is this. – NoXSaeeD Jul 23 '14 at 05:09
  • i have found this from http://stackoverflow.com/questions/10411975/how-to-get-the-width-and-height-of-an-image-view-in-android# – user3855491 Jul 23 '14 at 05:12
  • @user3855491 yes that getViewTreeObserver code is work and you can get width and Height from that. – Divyang Metaliya Jul 23 '14 at 05:27
  • you only need ImageView Height and Width, right, so you can't call getWidth() and getHeight() on ImageView from onCreate() in activity you have to wait for activity attached to window and then call getWidth() and getHeight(). just call getWidth() and getHeight() from anywhere else onCreate(). – NoXSaeeD Jul 23 '14 at 05:38
  • i want imageview height & width & aftre i'hve use this for set bitmap in imageview as size of imageview. – user3855491 Jul 23 '14 at 06:19
0

Here is the very simple and easy solution am sure it will work for you Use "scaleType" property of ImageView in your xml file keep it as "scaleType=fitXY" here is snippest

 <ImageView
            android:id="@+id/img1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scaleType="fitXY"/>

Enjoy coding