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);
    }
}