Drawing on a transparent image using Java SWT

前端 未结 4 1800
天涯浪人
天涯浪人 2021-01-04 12:08

How do I create an in-memory fully transparent SWT image and draw a black line on it with antialias enabled?

I expect the result to include only black color and alph

4条回答
  •  孤街浪徒
    2021-01-04 13:14

    I made it by allocating an ImageData, making it transparent then creating the Image from the data :

    static Image createTransparentImage(Display display, int width, int height) {
        // allocate an image data
        ImageData imData = new ImageData(width, height, 24, new PaletteData(0xff0000,0x00ff00, 0x0000ff));
        imData.setAlpha(0, 0, 0); // just to force alpha array allocation with the right size
        Arrays.fill(imData.alphaData, (byte) 0); // set whole image as transparent
    
        // Initialize image from transparent image data
        return new Image(display, imData);
    }
    

提交回复
热议问题