tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
0
ZUGRIFFE
643
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    Soultaker Soultaker ist offline Grünschnabel
    Registriert seit
    Apr 2010
    Beiträge
    3
    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 :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    
    @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();
            }
        }
    Geändert von Soultaker (15.04.10 um 19:08 Uhr)
     

Ähnliche Themen

  1. ByteArray to ImageData
    Von MySelV im Forum Swing, Java2D/3D, SWT, JFace
    Antworten: 2
    Letzter Beitrag: 11.02.10, 10:21
  2. Transparentes Image drehen, Transparenz beibehalten
    Von jeipack im Forum Swing, Java2D/3D, SWT, JFace
    Antworten: 2
    Letzter Beitrag: 02.03.09, 09:28
  3. Imagedata erstellen zu langsam
    Von Zerwas im Forum Java
    Antworten: 5
    Letzter Beitrag: 28.09.05, 16:29
  4. Image Transparenz
    Von robeldiebone im Forum Borland CBuilder und VCL
    Antworten: 4
    Letzter Beitrag: 25.09.05, 11:07
  5. transparenz-problem...
    Von en2k im Forum 3D Studio Max
    Antworten: 4
    Letzter Beitrag: 13.07.02, 17:35