Java Code Examples for org.eclipse.swt.graphics.ImageData#setAlpha()

The following examples show how to use org.eclipse.swt.graphics.ImageData#setAlpha() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwtUniversalImage.java    From hop with Apache License 2.0 5 votes vote down vote up
/**
 * Converts BufferedImage to SWT/Image with alpha channel.
 */
protected Image swing2swt( Device device, BufferedImage img ) {
  PaletteData palette = new PaletteData( 0xFF0000, 0xFF00, 0xFF );
  ImageData data = new ImageData( img.getWidth(), img.getHeight(), 32, palette );
  for ( int y = 0; y < data.height; y++ ) {
    for ( int x = 0; x < data.width; x++ ) {
      int rgba = img.getRGB( x, y );
      int rgb = palette.getPixel( new RGB( ( rgba >> 16 ) & 0xFF, ( rgba >> 8 ) & 0xFF, rgba & 0xFF ) );
      int a = ( rgba >> 24 ) & 0xFF;
      data.setPixel( x, y, rgb );
      data.setAlpha( x, y, a );
    }
  }
  return new Image( device, data );
}
 
Example 2
Source File: ViewList.java    From arx with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a transparent image
 * @param display
 * @param width
 * @param height
 * @return
 */
private Image getTransparentImage(Display display, int width, int height) {
    ImageData imData = new ImageData(width,
                                     height,
                                     24,
                                     new PaletteData(0xff0000,
                                                     0x00ff00,
                                                     0x0000ff));
    imData.setAlpha(0, 0, 0);
    Arrays.fill(imData.alphaData, (byte) 0);
    return new Image(display, imData);
}
 
Example 3
Source File: SwtUniversalImage.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Converts BufferedImage to SWT/Image with alpha channel.
 */
protected Image swing2swt( Device device, BufferedImage img ) {
  PaletteData palette = new PaletteData( 0xFF0000, 0xFF00, 0xFF );
  ImageData data = new ImageData( img.getWidth(), img.getHeight(), 32, palette );
  for ( int y = 0; y < data.height; y++ ) {
    for ( int x = 0; x < data.width; x++ ) {
      int rgba = img.getRGB( x, y );
      int rgb = palette.getPixel( new RGB( ( rgba >> 16 ) & 0xFF, ( rgba >> 8 ) & 0xFF, rgba & 0xFF ) );
      int a = ( rgba >> 24 ) & 0xFF;
      data.setPixel( x, y, rgb );
      data.setAlpha( x, y, a );
    }
  }
  return new Image( device, data );
}
 
Example 4
Source File: BreadcrumbItemDropDown.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
protected void drawCompositeImage(int width, int height) {
  Display display = fParentComposite.getDisplay();

  Image image = new Image(display, ARROW_SIZE, ARROW_SIZE * 2);

  GC gc = new GC(image);

  Color triangle = createColor(SWT.COLOR_LIST_FOREGROUND,
      SWT.COLOR_LIST_BACKGROUND, 20, display);
  Color aliasing = createColor(SWT.COLOR_LIST_FOREGROUND,
      SWT.COLOR_LIST_BACKGROUND, 30, display);
  gc.setBackground(triangle);

  if (fLTR) {
    gc.fillPolygon(new int[] {
        mirror(0), 0, mirror(ARROW_SIZE), ARROW_SIZE, mirror(0),
        ARROW_SIZE * 2});
  } else {
    gc.fillPolygon(new int[] {
        ARROW_SIZE, 0, 0, ARROW_SIZE, ARROW_SIZE, ARROW_SIZE * 2});
  }

  gc.setForeground(aliasing);
  gc.drawLine(mirror(0), 1, mirror(ARROW_SIZE - 1), ARROW_SIZE);
  gc.drawLine(mirror(ARROW_SIZE - 1), ARROW_SIZE, mirror(0),
      ARROW_SIZE * 2 - 1);

  gc.dispose();
  triangle.dispose();
  aliasing.dispose();

  ImageData imageData = image.getImageData();
  for (int y = 1; y < ARROW_SIZE; y++) {
    for (int x = 0; x < y; x++) {
      imageData.setAlpha(mirror(x), y, 255);
    }
  }
  for (int y = 0; y < ARROW_SIZE; y++) {
    for (int x = 0; x <= y; x++) {
      imageData.setAlpha(mirror(x), ARROW_SIZE * 2 - y - 1, 255);
    }
  }

  int offset = fLTR ? 0 : -1;
  drawImage(imageData, (width / 2) - (ARROW_SIZE / 2) + offset,
      (height / 2) - ARROW_SIZE - 1);

  image.dispose();
}
 
Example 5
Source File: BreadcrumbItemDropDown.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void drawCompositeImage(int width, int height) {
	Display display= fParentComposite.getDisplay();

	Image image= new Image(display, ARROW_SIZE, ARROW_SIZE * 2);

	GC gc= new GC(image);

	Color triangle= createColor(SWT.COLOR_LIST_FOREGROUND, SWT.COLOR_LIST_BACKGROUND, 20, display);
	Color aliasing= createColor(SWT.COLOR_LIST_FOREGROUND, SWT.COLOR_LIST_BACKGROUND, 30, display);
	gc.setBackground(triangle);

	if (fLTR) {
		gc.fillPolygon(new int[] { mirror(0), 0, mirror(ARROW_SIZE), ARROW_SIZE, mirror(0), ARROW_SIZE * 2 });
	} else {
		gc.fillPolygon(new int[] { ARROW_SIZE, 0, 0, ARROW_SIZE, ARROW_SIZE, ARROW_SIZE * 2 });
	}

	gc.setForeground(aliasing);
	gc.drawLine(mirror(0), 1, mirror(ARROW_SIZE - 1), ARROW_SIZE);
	gc.drawLine(mirror(ARROW_SIZE - 1), ARROW_SIZE, mirror(0), ARROW_SIZE * 2 - 1);

	gc.dispose();
	triangle.dispose();
	aliasing.dispose();

	ImageData imageData= image.getImageData();
	for (int y= 1; y < ARROW_SIZE; y++) {
		for (int x= 0; x < y; x++) {
			imageData.setAlpha(mirror(x), y, 255);
		}
	}
	for (int y= 0; y < ARROW_SIZE; y++) {
		for (int x= 0; x <= y; x++) {
			imageData.setAlpha(mirror(x), ARROW_SIZE * 2 - y - 1, 255);
		}
	}

	int offset= fLTR ? 0 : -1;
	drawImage(imageData, (width / 2) - (ARROW_SIZE / 2) + offset, (height / 2) - ARROW_SIZE - 1);

	image.dispose();
}
 
Example 6
Source File: BreadcrumbItemDropDown.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
protected void drawCompositeImage( int width, int height )
{
	Display display = fParentComposite.getDisplay( );

	Image image = new Image( display, ARROW_SIZE, ARROW_SIZE * 2 );

	GC gc = new GC( image );

	Color triangle = createColor( SWT.COLOR_LIST_FOREGROUND,
			SWT.COLOR_LIST_BACKGROUND,
			20,
			display );
	Color aliasing = createColor( SWT.COLOR_LIST_FOREGROUND,
			SWT.COLOR_LIST_BACKGROUND,
			30,
			display );
	gc.setBackground( triangle );

	if ( fLTR )
	{
		gc.fillPolygon( new int[]{
				mirror( 0 ),
				0,
				mirror( ARROW_SIZE ),
				ARROW_SIZE,
				mirror( 0 ),
				ARROW_SIZE * 2
		} );
	}
	else
	{
		gc.fillPolygon( new int[]{
				ARROW_SIZE,
				0,
				0,
				ARROW_SIZE,
				ARROW_SIZE,
				ARROW_SIZE * 2
		} );
	}

	gc.setForeground( aliasing );
	gc.drawLine( mirror( 0 ), 1, mirror( ARROW_SIZE - 1 ), ARROW_SIZE );
	gc.drawLine( mirror( ARROW_SIZE - 1 ),
			ARROW_SIZE,
			mirror( 0 ),
			ARROW_SIZE * 2 - 1 );

	gc.dispose( );
	triangle.dispose( );
	aliasing.dispose( );

	ImageData imageData = image.getImageData( );
	for ( int y = 1; y < ARROW_SIZE; y++ )
	{
		for ( int x = 0; x < y; x++ )
		{
			imageData.setAlpha( mirror( x ), y, 255 );
		}
	}
	for ( int y = 0; y < ARROW_SIZE; y++ )
	{
		for ( int x = 0; x <= y; x++ )
		{
			imageData.setAlpha( mirror( x ),
					ARROW_SIZE * 2 - y - 1,
					255 );
		}
	}

	int offset = fLTR ? 0 : -1;
	drawImage( imageData,
			( width / 2 ) - ( ARROW_SIZE / 2 ) + offset,
			( height / 2 ) - ARROW_SIZE - 1 );

	image.dispose( );
}
 
Example 7
Source File: ConsistencyAction.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
private static ImageData modifyAlphaChannel(Image image, int alpha) {

    if (alpha < 0) alpha = 0;

    if (alpha > 255) alpha = 255;

    ImageData data = image.getImageData();

    for (int x = 0; x < data.width; x++) {
      for (int y = 0; y < data.height; y++) {
        int a = data.getAlpha(x, y);

        // value depends on the image, must be determined empirically
        if (a <= MIN_ALPHA_VALUE) continue;

        data.setAlpha(x, y, alpha);
      }
    }

    return data;
  }