Transparenz Problem (GC + Image + ImageData )

Soultaker

Grünschnabel
Hallo, wie im Titel schon steht habe ich ein Transparenz Problem beim malen in ein Image.
Ich habe eine draw Methode, die bekommt unter anderem ein GC übergeben.
Ich möchte in ein Image ein paar Ovale malen
Das Image erstell ich durch ein ImageData und setzt die Farbe Schwarz auf transparent.
Ich erstelle dann anschließend ein neues GC. Nun zeichne ich mit dem GC ein paar Ovale in das Image mit der Farbe rot, jedoch sind diese anscheinend auch transparent.
Sobaldich die transparenz abschalte vom ImageData sehe ich zwar die Ovale, aber das Image ist nicht mehr transparent und hat die Farbe schwarz. An was kann das liegen?

Hier mein Code snippet:
Code:
@Override
private Image hitsImage = null;
public draw (GC gc, Rectangle rect) {
    if( hitsImage == null ) {
            final int rgbs = 10;
            final RGB red = new RGB( 255, 0, 0 );
            final float[] hsb = red.getHSB();
            final float hue = hsb[0];
            final float saturation = hsb[1];
            final float brightness = hsb[2];

            final List<RGB> rgbList = new ArrayList<RGB>();
            rgbList.add( new RGB( 0, 0, 0 ) );
            rgbList.add( red );
            for( int i = 0; i < rgbs; i++ ) {
                final RGB rgb = new RGB( hue, saturation, brightness - (i * 0.1f) );
                rgbList.add( rgb );
            }

            final PaletteData palette = new PaletteData( rgbList.toArray( new RGB[0] ) );
            palette.isDirect = false;

            if( imageData == null ) imageData = new ImageData( rect.width, rect.height, 24, palette );
            imageData.transparentPixel = 0;

            hitsImage = new Image( gc.getDevice(), imageData );

        }

        final GC hitGC = new GC( hitsImage );
        hitGC.setAntialias( SWT.ON );

        try {
            // Height and width for drawing
            if( currentRectHeight != rect.height && currentRectWidth != rect.width ) {
                hitPositionMap.clear();
            }

            currentRectHeight = rect.height;
            currentRectWidth = rect.width;

            final PropertyName pn = layerProperties.getPropertyMap().get( "Hit" );
            bgColor = pn.getBackgroundColor();
            foreColor = pn.getColor();
            visibility = pn.isVisible();

            if( visibility ) {

                final int dimension = Util.getCircleDimension( currentRectHeight, currentRectWidth );
                final int center = dimension / 2;

                final long checkAge = new Date().getTime() - 10 * 1000;
                final Date date = new Date( checkAge );
                synchronized( hitList ) {
                    for( final Hits hits : hitList ) {            
                         hitGC.setBackground( new Color( hitGC.getDevice(), new RGB( 255, 0, 0 ) ) );              

                        if( hitPositionMap.containsKey( hits ) ) {
                            for( int i = 0; i < hits.getDistanceM().length; i++ ) {
                                final HitPosition pos = hitPositionMap.get( hits );
                            
                                hitGC.fillOval( pos.xPosition[i] + center, pos.yPosition[i] + center, 5, 5 );

                            }
                        } else {
                            final double radian = Util.azimuthToRadian( hits.getAzimuthMil() );
                            final double[] distanceArray = hits.getDistanceM();

                            final HitPosition position = new HitPosition( distanceArray.length );

                            for( final double element : distanceArray ) {
                                final double distance = (element * (dimension / 2)) / 40000;
                                final int x = (int) (Math.cos( radian ) * distance);
                                final int y = (int) (Math.sin( radian ) * distance);
                                position.addXY( x, y );
                                hitPositionMap.put( hits, position );

                                //FIXME hitGC
                                //imageData.setPixel( x + center, y + center, 1 );
                                hitGC.fillOval( x + center, y + center, 5, 5 );

                            }
                        }
                    }
                }

                gc.drawImage( hitsImage, 0, 0 );
            }

        } catch( final Exception ex ) {
            log.debug( "something went wrong", ex );
        } finally {
            hitGC.dispose();
        }
    }
 
Zuletzt bearbeitet:
Zurück