How can I have good quality when I get pictures? - android

I want to create user profile. I am using Firebase to make authentication and get profile picture but when I get profile picture, quality is not good.
I used Glide to load image
Glide.with(this)
.load(this.getCurrentUser().getPhotoUrl())
.apply(RequestOptions.circleCropTransform())
.into(imageViewProfile);
My Image view:
<ImageView
android:id="#+id/imageView"
android:layout_width="113dp"
android:layout_height="102dp"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="8dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
How can I fix it? I already try to use Picasso but that didn't work.

Instead of using RequestOptions.circleCropTransform(), try using CircleImageView.
Import this -
compile "de.hdodenhof:circleimageview:2.1.0"
in your layout file
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="#dimen/_80sdp"
android:layout_height="#dimen/_80sdp"
android:layout_centerHorizontal="true"
android:id="#+id/prof_pic"
app:civ_border_width="#dimen/_2sdp"
app:civ_border_color="#bf0000"
android:elevation="#dimen/_2sdp"
android:layout_marginTop="#dimen/_60sdp"
/>
and to load image
Glide.with(getActivity()).load("url").placeholder(R.drawable.bluehead).into(Prof_Pic);

Related

Circularimage library display square image

I'm Using circulcar image view libary available on github. I also add it to build.gradle and sync it. but i am still not getting circular image. if I add SRC insted of background, still not getting result. where i am wrong?
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/imageView"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#drawable/splash_screen"
app:civ_border_width="10dp"
app:civ_border_color="#FF000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" />
remove this line : android:background="#drawable/splash_screen"
and Add this line : android:src="#drawable/splash_screen"
Just change the background line. It will show the circular image.
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/imageView"
android:layout_width="200dp"
android:src="#drawable/splash_screen"
android:layout_height="200dp"
app:civ_border_width="10dp"
app:civ_border_color="#FF000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" />
Image was displayed to the background that's why it was showing the square.

android xml scale type to flutter ui scale type

i have application with android java but now i want to convert into flutter but problem is how i can use
android:scaleType="fitCenter"
in image view.
here is my image view code can anyone help me out?
<ImageView
android:id="#+id/imgView2"
android:layout_width="112dp"
android:layout_height="150dp"
android:background="#000000"
android:contentDescription="TODO"
android:padding="1dp"
android:scaleType="fitCenter"
android:src="#android:drawable/editbox_dropdown_dark_frame"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.528" />
Flutter has a fit property in Image widget which is equivalent to scaleType which accepts Boxfit enum values. You can see more about Image widget here.

Using Glide to load ImageView but still have a visual reference in the layout xml

I've been able to greatly improve my app's performance using Glide, but it means I've had to remove the srcCompat line from the ImageView in the layout xml.
However, this makes designing much harder, because now I can't reference anything in my Design tab when arranging my xml.
Does anyone have a solution to this? Working without being able to see the image in the xml is extremely inconvenient.
Example:
Before using Glide:
in my activity_main.xml:
<ImageView
android:id="#+id/image"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:adjustViewBounds="true"
app:layout_constraintEnd_toStartOf="#id/rightNarrowGuideline"
app:layout_constraintStart_toEndOf="#id/leftNarrowGuideline"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/money_coins" />
<Button
android:id="#+id/example"
style="#style/BigRedButton"
android:layout_width="0dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="50dp"
android:text="EXAMPLE"
app:layout_constraintEnd_toEndOf="#id/rightNarrowGuideline"
app:layout_constraintStart_toStartOf="#id/leftNarrowGuideline"
app:layout_constraintTop_toBottomOf="#+id/image" />
and it looks like this in the Design tab.
After using Glide:
Now I load the image in my MainActivity.java with
ImageView mainImage = findViewById(R.id.image);
Glide.with(this).load(R.drawable.money_coins).into(mainImage);
and I've removed this line:
app:srcCompat="#drawable/money_coins"
from my activity_main.xml, so I'm left with this:
<ImageView
android:id="#+id/image"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:adjustViewBounds="true"
app:layout_constraintEnd_toStartOf="#id/rightNarrowGuideline"
app:layout_constraintStart_toEndOf="#id/leftNarrowGuideline"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/example"
style="#style/BigRedButton"
android:layout_width="0dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="50dp"
android:text="EXAMPLE"
app:layout_constraintEnd_toEndOf="#id/rightNarrowGuideline"
app:layout_constraintStart_toStartOf="#id/leftNarrowGuideline"
app:layout_constraintTop_toBottomOf="#+id/image" />
And now my Design tab looks like this.
If I understand correctly you want to see your image on preview. Well I guess you could set tools:srcCompat="#drawable/money_coins", which basically sets a "placeholder" image for preview. But by doing this you would need to update drawable on two places.
Dunno exactly if you're also changing your image, but for static image use, directly assigning src in layout should be fine performance wise. Unless your drawable image is like huge. If that is the case you should properly resize it or even better, use vector drawable resource. I'm guessing glide downsamples image for you, hence making it load faster.

Error when using Glide

The app crashes when I try to load an image with Glide.
I have the following code:
.java:
ImageButton home_ib1;
Glide.with(Home.this)
.load(R.drawable.moviep_24_hours_to_live)
.override(98, 155)
.centerCrop()
.placeholder(R.drawable.moviep_24_hours_to_live)
.into(home_ib1);
.xml:
<ScrollView
<RelativeLayout
<ImageButton
android:id="#+id/home_ib1"
android:layout_width="98dp"
android:layout_height="155dp"
android:layout_marginStart="16dp"
android:layout_marginTop="155dp"
android:background="#android:color/transparent"
android:scaleType="fitCenter"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
And when I try to run app, i got crash..(LogCat: You must pass in a non null View)
(The image's resolution that i have to load is 175x276 PNG)
ImageButton home_ib1;
Looks Like home_ib1 is null
Just add
home_ib1 = findViewById(R.id.home_ib1);

Blurred profile picture in Android app

I am displaying the Google plus profile picture of the user of my app, but the image is blurred.unless i reduce the size which then makes it almost impossible to recognize who ever is in it.Is there a way to fix this.I am getting the image from a Url.
This is my ImageView
<ImageView
android:id="#+id/profilePicture"
android:layout_width="200dp"
android:layout_height="200dp"
android:contentDescription="hello"
android:maxHeight="200dp"
android:maxWidth="200dp" />
Try display image following way,
<ImageView
android:id="#+id/profilePicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="hello"
android:maxHeight="200dp"
android:maxWidth="200dp" />

Categories

Resources