IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Composant ImageView ne fonctionne pas sous Android 13


Sujet :

Android

  1. #1
    Membre du Club

    Homme Profil pro
    Hobbyiste
    Inscrit en
    Juillet 2018
    Messages
    126
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Hobbyiste

    Informations forums :
    Inscription : Juillet 2018
    Messages : 126
    Points : 68
    Points
    68
    Billets dans le blog
    1
    Par défaut Composant ImageView ne fonctionne pas sous Android 13
    Bonjour,

    J'ai un petit problème je développe une application. Je l'ai testée régulièrement sous l'émulateur API 29, 30, 31, 32
    et elle ne fonctionne pas bien avec la version 33.

    L'utilisateur choisit une image dans le téléphone et le programme appelle le code suivant:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
     
        public void fillGallery(Bitmap photo, InputStream fileInputStream) throws FileNotFoundException {
            if (photo == null) {
                photo = BitmapFactory.decodeStream(fileInputStream);
            }
     
            ImageViewSelection imageView2 = findViewById(R.id.currentImageViewSelection);
     
     
            imageView2.setImageURI(null);
            imageView2.postInvalidate();
     
            imageView2.setImageURI(Uri.fromFile(currentFile));
            imageView2.setImageBitmap(photo);
            System.out.println("Image set in ImageView 4/4");
     
        }
    J'ai ajouté les 2 lignes setImageURI(null) et la suivante après une recherche Google.

    Tout fonctionne, l'image est chargée dans l'ImageView mais ne s'affiche pas.

    Code de l'imageView:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    /*
     * Copyright (c) 2023.
     *
     *
     *  Copyright 2012-2023 Manuel Daniel Dahmen
     *
     *  Licensed under the Apache License, Version 2.0 (the "License");
     *  you may not use this file except in compliance with the License.
     *  You may obtain a copy of the License at
     *
     *  http://www.apache.org/licenses/LICENSE-2.0
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     *  limitations under the License.
     *
     *
     */
     
    package one.empty3.feature.app.maxSdk29.pro;
     
    import android.content.Context;
    import android.graphics.Bitmap;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.graphics.RectF;
    import android.util.AttributeSet;
     
    import androidx.annotation.NonNull;
    import androidx.annotation.Nullable;
     
    import one.empty3.feature20220726.PixM;
    import one.empty3.library.ColorTexture;
    import one.empty3.library.Point3D;
    import one.empty3.library.PolyLine;
     
    public class ImageViewSelection extends androidx.appcompat.widget.AppCompatImageView {
        private final Paint paint =
                new Paint();
        private PixM pixels = null;
     
        {
            paint.setAntiAlias(true);
            paint.setColor(Color.RED);
            paint.setStyle(Paint.Style.FILL_AND_STROKE);
            paint.setStrokeWidth(10);
        }
     
        private RectF rect = null;
        private boolean isDrawingRect = false;
     
        public ImageViewSelection(@NonNull Context context) {
            super(context);
     
        }
     
     
        public ImageViewSelection(@NonNull Context context, @Nullable AttributeSet attrs) {
            super(context, attrs);
        }
     
        public ImageViewSelection(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
        }
     
        public void setDrawingRect(RectF rect) {
            this.rect = rect;
        }
     
        public void setDrawingRectState(boolean isDrawingRect) {
            this.isDrawingRect = isDrawingRect;
            if (isDrawingRect) {
                drawRect();
            }
        }
     
        private void drawRect() {
            if (isDrawingRect && pixels != null) {
                PolyLine polyLine = new PolyLine();
                polyLine.getPoints().add(new Point3D((double) rect.left, (double) rect.top, 0.0));
                polyLine.getPoints().add(new Point3D((double) rect.right, (double) rect.top, 0.0));
                polyLine.getPoints().add(new Point3D((double) rect.right, (double) rect.bottom, 0.0));
                polyLine.getPoints().add(new Point3D((double) rect.left, (double) rect.bottom, 0.0));
                pixels.plotCurve(polyLine, new ColorTexture(Color.YELLOW));
                setImageBitmap(pixels.getImage().getBitmap());
            }
     
     
        }
     
        @Override
        public void setWillNotDraw(boolean willNotDraw) {
            super.setWillNotDraw(willNotDraw);
        }
     
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            //drawRect();
        }
     
        public RectF getDrawingRect() {
            return rect;
        }
     
        @Override
        public void setImageBitmap(Bitmap bm) {
            super.setImageBitmap(bm);
            this.pixels = new PixM(bm);
        }
    }

  2. #2
    Membre du Club

    Homme Profil pro
    Hobbyiste
    Inscrit en
    Juillet 2018
    Messages
    126
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Hobbyiste

    Informations forums :
    Inscription : Juillet 2018
    Messages : 126
    Points : 68
    Points
    68
    Billets dans le blog
    1
    Par défaut
    Je croyais avoir trouvé une solution en demandant au code d'assignation de s'exécuter dans le thread UI:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    Handler(Looper.getMainLooper()).post {
                Log.d(
                    "ImageViewSelection::setImageBitmap",
                    "change image on UI thread"
                )
                imageView.setImageBitmap(bitmap)
                imageView.setPixels(PixM(bitmap))
            }
    Mais ça ne fonctionne pas plus.

Discussions similaires

  1. Réponses: 0
    Dernier message: 08/11/2014, 09h58
  2. Mon script ne fonctionne pas sous android
    Par sp2308 dans le forum jQuery
    Réponses: 4
    Dernier message: 19/08/2014, 23h20
  3. [WM18] ChampSupprime ne fonctionne pas sous Android
    Par ihih45 dans le forum Windev Mobile
    Réponses: 3
    Dernier message: 13/06/2013, 15h52
  4. Réponses: 0
    Dernier message: 12/01/2013, 19h59
  5. Réponses: 6
    Dernier message: 27/01/2004, 11h14

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo