[Android] Problem z mikroskopijnym zdjęciem w ImageView

0

Mam problem z załadowaniem zdjecia do ImageSwitcher. Zdjecie po załadowaniu jest strasznie malutki praktycznie nie widoczne.
Zdjecie pobierane przez REST'a. Metoda zwracajaca koduje byte array to stringa:

byte[] image = imageInByteBuffer.array();
return Base64.encodeBase64String(image);

Po stronie apki:

byte[] image = Base64.decode(this.pictures.get(0).getImage(), Base64.DEFAULT);
imageSwitcher.setImageDrawable(new BitmapDrawable(
                BitmapFactory.decodeByteArray(image, 0, image.length)));

Co robie źle?

0

główny layout xml;

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="***.GalleryActivity"
    tools:showIn="@layout/activity_gallery">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/pictureViewer"
        android:scrollbars="vertical"/>

    <ImageSwitcher
        android:id="@+id/imageSwitcher"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_below="@id/pictureViewer"/>

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:text="@string/back" />

        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:text="@string/next" />

</RelativeLayout>

Inicjalizacja ImageSwitcher'a

imageSwitcher = findViewById(R.id.imageSwitcher);
        imageSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                ImageView imageView = new ImageView(getApplicationContext());
                imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
                return imageView;
            }
        });
        Animation in = AnimationUtils.loadAnimation(this,android.R.anim.slide_in_left);
        Animation out = AnimationUtils.loadAnimation(this,android.R.anim.slide_in_left);
        imageSwitcher.setInAnimation(in);
        imageSwitcher.setOutAnimation(out);
0

a nie jest tak ze skoro RecyclerView ma Height = match_parent wiec zajmuje w relativie caly ekran a imageSwitcher ma android:layout_below="@id/pictureViewer"
to zdjecie zostanie "ściśnięte" ?

wywal to android:layout_below="@id/pictureViewer" i zobacz jak to sie zachowa, powinno byc na pelny ekran skoro masz
android:layout_width="match_parent" android:layout_height="match_parent"

0

title

0

po wywaleniu below z ImageSwitcher taki efekt sam efekt foto: https://ibb.co/jL7j1x

0

A Ty jesteś pewny, że ten obrazek się w ogóle dobrze pobiera? Dlaczego nie skorzystasz z Picasso lub Glide?

0

bo obrazek siedzi w bazie danych (Cassandra) i tam musi byc :)

0

No dobra, zakładając, że musi być w bazie jako blob:

byte[] imageByteArray = Base64.decode(this.pictures.get(0).getImage(), Base64.DEFAULT);

no i teraz do Glide

Glide.with(context)
    .load(imageByteArray)
    .asBitmap()
    .placeholder(R.drawable.ic_broken)
    .into(rowImageView);

Na Twoim miejscu sprawdziłbym, czy aby obraz dobrze idzie do apki. No i oczywiście rozważyłbym trzymanie jpg, a w cassandrze tylko ścieżki do obrazka, no ale co kto tam ma.

0
    <ImageSwitcher
        android:id="@+id/imageSwitcher"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"/>

to i tak cos jest nie tak bo masz center horiz/vert a i tak jest u góry a powinien być centralnie. zobacz tez w Android Strudio Profiler w network co wlasciwie Ci sie sciaga i jaki ma rozmiar

0

Sprawdziłem obrazek wychodzący z bazy na poziomie resta oraz obrazek który dostaje już apka i wielość jest prawidłowa. Obstawiam żę coś robię źle z wyświetlaniem po stronie apki

0

Cała metoda inicjalizujaca aktywność:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gallery);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        LinearLayoutManager layoutManager= new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL, false);
        recyclerView = findViewById(R.id.pictureViewer);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));

        objectIndex = getIntent().getIntExtra("index", -1);
        loadPictures();

        imageSwitcher = findViewById(R.id.imageSwitcher);
        imageSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                ImageView imageView = new ImageView(getApplicationContext());
                imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
                return imageView;
            }
        });
        Animation in = AnimationUtils.loadAnimation(this,android.R.anim.slide_in_left);
        Animation out = AnimationUtils.loadAnimation(this,android.R.anim.slide_in_left);
        imageSwitcher.setInAnimation(in);
        imageSwitcher.setOutAnimation(out);
    }
0

wlacz w opcjach deweloperskich pokazywanie granic układu i może to ci jakoś pomoże

1 użytkowników online, w tym zalogowanych: 0, gości: 1