3
\$\begingroup\$

Using LibGDX for an AR application and capturing image and merging lines and texts on LibGDX with image with this code.

 private Pixmap merge2Pixmaps(Pixmap mainPixmap, Pixmap overlayedPixmap) {
    // merge to data and Gdx screen shot - but fix Aspect Ratio issues
    // between the screen and the camera
    Pixmap.setFilter(Filter.BiLinear);
    float mainPixmapAR = (float) mainPixmap.getWidth() / mainPixmap.getHeight();
    float overlayedPixmapAR = (float) overlayedPixmap.getWidth() / overlayedPixmap.getHeight();
    if (overlayedPixmapAR < mainPixmapAR) {
        int overlayNewWidth = (int) (((float) mainPixmap.getHeight() / overlayedPixmap.getHeight())
                * overlayedPixmap.getWidth());
        int overlayStartX = (mainPixmap.getWidth() - overlayNewWidth) / 2;
        // Overlaying pixmaps
        mainPixmap.drawPixmap(overlayedPixmap, 0, 0, overlayedPixmap.getWidth(), overlayedPixmap.getHeight(),
                overlayStartX, 0, overlayNewWidth, mainPixmap.getHeight());
    } else {
        int overlayNewHeight = (int) (((float) mainPixmap.getWidth() / overlayedPixmap.getWidth())
                * overlayedPixmap.getHeight());
        int overlayStartY = (mainPixmap.getHeight() - overlayNewHeight) / 2;
        // Overlaying pixmaps
        mainPixmap.drawPixmap(overlayedPixmap, 0, 0, overlayedPixmap.getWidth(), overlayedPixmap.getHeight(), 0,
                overlayStartY, mainPixmap.getWidth(), overlayNewHeight);
    }
    return mainPixmap;
}

In 1.9.6 Pixmap.setFilter(Filter.BiLinear); is not available and it does not merge 2 pixmaps correctly. I tried setting BiLinear filter for both pixmaps or one at a time but none works.Black image

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.