简体   繁体   中英

Show an image in opengl is working with pictures from gallery but from camera doesn't

I have some troubles to display images in OpenGL.

Actually I'm able to display images from gallery in opengl. The problem occurs when I try to show one from the camera.

For me, OpenGL have to display the image from the camera as it does with the gallery ones. Obviously I'm making something wrong.

Any help will be appreciated.

Intent from gallery:

 Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                    intent.setType("image/");
                    startActivityForResult(intent, 2);

Intent from camera:

Intent takePic = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePic.resolveActivity(getPackageManager()) != null) {
        File imagen = controler.createPhotoFile(getExternalFilesDir(Environment.DIRECTORY_PICTURES));
        if (imagen != null) {
            photoUri = FileProvider.getUriForFile(this, "my.fileprovider", imagen);
            takePic.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
            startActivityForResult(takePic, 1);
        }
    }

This is my onActivityResult where I send the URI to a method which convert it to a bitmap and send it.

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        switch (requestCode) {
            case 1:
                sendImagenPanel(photoUri);
                break;
            case 2:
                sendImagenPanel(data.getData());
                break;
        }
    }
}

private void sendImagenPanel(Uri uri) {
    Bitmap bitmap = null;
    try {
        bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);
    } catch (IOException e) {
        e.printStackTrace();
    }
    final Bitmap imagen = controler.getCroppedBitmap(controler.scaledBitmap(bitmap, 256));
    final CasillaOG casilla = ((GLSurfacePanel) gLViewPanel).getRendererPanel().getCuboSelected();
    gLViewPanel.queueEvent(new Runnable() {
        @Override
        public void run() {
            casilla.loadNewTexture(imagen);
            casilla.setImagen(imagen);
        }
    });
    gLViewPanel.requestRender();
}

In case someone is interested. I realize that the problem is not on the method that calls OpenGL. If I run the same code on the onActivityResult works from the gallery requestCode but not on the camera one, in my Samsung Galaxy Tab A. Why I mention my device? because if I run the app on a Huawei P9 lite, the gallery images are not display either. In both cases appears the next problem on the console: call to opengl es api with no current context (logged once per thread)

After search that problem, I suppose that the intents of the camera and gallery use OpenGL and its originate a conflict with my own OpenGL environment.

Finally, I opted to set a bitmap field and add the texture in on the onDrawFrame. Obviously, with a boolean to make it one time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM