Image view without scaling

paramjitparamjit USMember ✭✭
edited November 2018 in Xamarin.Android

I am trying to display a image in Imageview, I want the image to be displayed without any scaling (its exact dimensions on all devices with scrollview).

If i keep the image in "Drawable" folder (without any dip) the image shows as required.

But now i want the image from a path to be displayed for which i create a drawable using

Drawable d = Drawable.CreateFromPath(imgfile);
Img.SetImageDrawable(d);

which does not get displayed as expected.

I have tried using all ScaleType and SetAdjustViewBounds also, but still the image is always resized.

my axml file conains

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/Lay1">

            <ImageView
            android:id="@+id/ImageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

</LinearLayout>

Can anyone help me?

Best Answer

Answers

  • paramjitparamjit USMember ✭✭
    edited December 2018

    Used following Codes now its working as required

    axml:

        <ImageView
                    android:id="@+id/imageHelp"
                android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                android:scaleType="center"
                android:adjustViewBounds="true"/> 
    

    Code:

    Bitmap bp = BitmapFactory.DecodeFile(imgfile);
    
    int pxW = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, bp.Width, Resources.DisplayMetrics); 
    int pxH = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, bp.Height, Resources.DisplayMetrics); 
    
    Bitmap bpresized = Bitmap.CreateScaledBitmap(bp, pxW, pxH, false);
    
    Img.SetImageBitmap(bpresized);
    

    Thanks

Sign In or Register to comment.