简体   繁体   English

在 opengl 中显示图像正在处理来自画廊的图片,但来自相机的图片不

[英]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.我在 OpenGL 中显示图像时遇到了一些麻烦。

Actually I'm able to display images from gallery in opengl.实际上,我可以在 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.对我来说,OpenGL 必须像在画廊中一样显示来自相机的图像。 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.这是我的 onActivityResult,我将 URI 发送到将其转换为 bitmap 并发送的方法。

@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.我意识到问题不在于调用 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?如果我在我的三星 Galaxy Tab A 中的 onActivityResult 作品上运行相同的代码,但不是在相机一上,为什么我提到我的设备? because if I run the app on a Huawei P9 lite, the gallery images are not display either.因为如果我在华为 P9 lite 上运行该应用程序,画廊图像也不会显示。 In both cases appears the next problem on the console: call to opengl es api with no current context (logged once per thread)在这两种情况下,控制台上都会出现下一个问题:在没有当前上下文的情况下调用 opengl es api(每个线程记录一次)

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.搜索该问题后,我认为相机和画廊的意图使用 OpenGL 并且它与我自己的 OpenGL 环境发生冲突。

Finally, I opted to set a bitmap field and add the texture in on the onDrawFrame.最后,我选择设置一个 bitmap 字段并在 onDrawFrame 上添加纹理。 Obviously, with a boolean to make it one time.显然,用一个 boolean 来做一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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