Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAGSurface readPixels失败 #78

Closed
krislyy opened this issue Jan 26, 2022 Discussed in #77 · 1 comment
Closed

PAGSurface readPixels失败 #78

krislyy opened this issue Jan 26, 2022 Discussed in #77 · 1 comment

Comments

@krislyy
Copy link

krislyy commented Jan 26, 2022

Discussed in #77

Originally posted by krislyy January 26, 2022

private void pagToGif() {
        // pag player
        PAGComposition composition = makeComposition();
        int height = composition.height();
        int width = composition.width();
        PAGSurface surface = PAGSurface.MakeOffScreen(width, height);
        if (surface == null) return;
        PAGPlayer player = new PAGPlayer();
        player.setComposition(composition);
        player.setSurface(surface);
        player.setProgress(0);
        // byte buffer
        ByteBuffer buffer = ByteBuffer.allocateDirect(width * height * 4)
                .order(ByteOrder.nativeOrder());
        buffer.clear();
        // 开始导出
        int totalFrames = (int) (composition.duration() * composition.frameRate() / 1000000);
        for (int i = 0; i < totalFrames; i++) {
            generateSurfaceFrame(player, composition, i);
            surface.readPixels(buffer);
            Bitmap bitmap = BitmapFactory.decodeByteArray(buffer.array(), 0, buffer.capacity());
            buffer.clear();
        }
    }

PAGSurface的readPixels函数返回的buffer一直空的,想问下Android需要特殊设置什么才能拿到当前渲染的到surface上图片呢?

@domchen
Copy link
Collaborator

domchen commented Jan 26, 2022

已在 #77 中回复。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants