SWT overlay

I want to have a transparent canvas.

I have a canvas in which the video is being rendered. I want a canvas on top of the video to draw a rectangle over the video to select the video area for some other purpose (for example, to enlarge, to image, etc.).

Is this possible in SWT?

Thank.

+3
source share
1 answer

I don’t think that you can have a transparent canvas, but you can implement double buffering on the canvas that plays video, which will also improve the frame rate and reduce screen flicker.

Image bufferImage = (Image) canvas.getData("buffer-image");
            Display display = Display.getDefault();
            if (bufferImage == null //if there is no image
                    || bufferImage.getBounds().width != canvas.getSize().x //if the image is incorrectly sized, which could result in unnecessary expenditures or not drawing everything
                    || bufferImage.getBounds().height != canvas.getSize().y) {
                bufferImage = new Image(display, canvas.getSize().x, canvas.getSize().y);
                canvas.setData("buffer-image", bufferImage);
            }

            GC bufferImageGC = new GC(bufferImage);
            bufferImageGC.setBackground(e.gc.getBackground());
            bufferImageGC.setForeground(e.gc.getForeground());

                    //fill in the background
            Rectangle background = bufferImage.getBounds();
            bufferImageGC.fillRectangle(0, 0, background.width, background.height);

                    //draw video here, remember to draw onto bufferImageGC
                    //draw anything else you want here

Hope this helps.

+2
source

Source: https://habr.com/ru/post/1737378/


All Articles