org.eclipse.swt.graphics.Image类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(16.3k)|赞(0)|评价(0)|浏览(263)

本文整理了Java中org.eclipse.swt.graphics.Image类的一些代码示例,展示了Image类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Image类的具体详情如下:
包路径:org.eclipse.swt.graphics.Image
类名称:Image

Image介绍

[英]Instances of this class are graphics which have been prepared for display on a specific device. That is, they are ready to paint using methods such as GC.drawImage() and display on widgets with, for example, Button.setImage().

If loaded from a file format that supports it, an Image may have transparency, meaning that certain pixels are specified as being transparent when drawn. Examples of file formats that support transparency are GIF and PNG.

There are two primary ways to use Images. The first is to load a graphic file from disk and create an Image from it. This is done using an Image constructor, for example:

Image i = new Image(device, "C:\\graphic.bmp");

A graphic file may contain a color table specifying which colors the image was intended to possess. In the above example, these colors will be mapped to the closest available color in SWT. It is possible to get more control over the mapping of colors as the image is being created, using code of the form:

ImageData data = new ImageData("C:\\graphic.bmp"); 
RGB[] rgbs = data.getRGBs(); 
// At this point, rgbs contains specifications of all 
// the colors contained within this image. You may 
// allocate as many of these colors as you wish by 
// using the Color constructor Color(RGB), then 
// create the image: 
Image i = new Image(device, data);

Applications which require even greater control over the image loading process should use the support provided in class ImageLoader.

Application code must explicitly invoke the Image.dispose() method to release the operating system resources managed by each instance when those instances are no longer required.
[中]此类实例是为在特定设备上显示而准备的图形。也就是说,他们已经准备好使用GC.drawImage()等方法进行绘制,并在小部件上显示,例如Button.setImage()
如果从支持它的文件格式加载,Image可能具有透明度,这意味着某些像素在绘制时被指定为透明。支持透明性的文件格式示例有GIF和PNG。
有两种主要的使用Images的方法。第一种方法是从磁盘加载一个图形文件,并从中创建一个Image。这是使用Image构造函数完成的,例如:

Image i = new Image(device, "C:\\graphic.bmp");

图形文件可能包含一个颜色表,指定图像要具有的颜色。在上面的示例中,这些颜色将映射到SWT中最接近的可用颜色。在创建图像时,可以使用以下代码对颜色映射进行更多控制:

ImageData data = new ImageData("C:\\graphic.bmp"); 
RGB[] rgbs = data.getRGBs(); 
// At this point, rgbs contains specifications of all 
// the colors contained within this image. You may 
// allocate as many of these colors as you wish by 
// using the Color constructor Color(RGB), then 
// create the image: 
Image i = new Image(device, data);

需要对图像加载过程进行更大控制的应用程序应使用类ImageLoader中提供的支持。
当不再需要由每个实例管理的操作系统资源时,应用程序代码必须显式调用Image.dispose()方法来释放这些资源。

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

public void paintControl( PaintEvent e ) {
 Point area = getArea();
 if ( area.x == 0 || area.y == 0 ) {
  return; // nothing to do!
 }
 Display disp = shell.getDisplay();
 Image img = getTransformationImage( disp, area.x, area.y, magnification );
 e.gc.drawImage( img, 0, 0 );
 if ( transMeta.nrSteps() == 0 ) {
  e.gc.setForeground( GUIResource.getInstance().getColorCrystalTextPentaho() );
  e.gc.setFont( GUIResource.getInstance().getFontMedium() );
  Image pentahoImage = GUIResource.getInstance().getImageTransCanvas();
  int leftPosition = ( area.x - pentahoImage.getBounds().width ) / 2;
  int topPosition = ( area.y - pentahoImage.getBounds().height ) / 2;
  e.gc.drawImage( pentahoImage, leftPosition, topPosition );
 }
 img.dispose();
 // spoon.setShellText();
}

代码示例来源:origin: pentaho/pentaho-kettle

@Override
protected Image renderSimple( Device device, int width, int height ) {
 int xsize = bitmap.getBounds().width;
 int ysize = bitmap.getBounds().height;
 Image result = new Image( device, width, height );
 GC gc = new GC( result );
 gc.drawImage( bitmap, 0, 0, xsize, ysize, 0, 0, width, height );
 gc.dispose();
 return result;
}

代码示例来源:origin: pentaho/pentaho-kettle

private void disposeImage( Image image ) {
 if ( image != null && !image.isDisposed() ) {
  image.dispose();
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

public static Image makeImageTransparent( Display display, Image tempImage, RGB transparentColor ) {
 ImageData imageData = tempImage.getImageData();
 int pixelIndex = imageData.palette.getPixel( transparentColor );
 imageData.transparentPixel = pixelIndex;
 Image image = new Image( display, imageData );
 tempImage.dispose();
 return image;
}

代码示例来源:origin: pentaho/pentaho-kettle

public int open() {
 Shell parent = getParent();
 Display display = parent.getDisplay();
 shell = new Shell( parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX );
 props.setLook( shell );
 formLayout.marginHeight = 15;
 shell.setLayout( formLayout );
 Image image = display.getSystemImage( SWT.ICON_WARNING );
 Label wIcon = new Label( shell, SWT.NONE );
 props.setLook( wIcon );
 wIcon.setImage( image );
 FormData fdIcon = new FormData();
 fdIcon.left = new FormAttachment( 0, 0 );
 fdIcon.top = new FormAttachment( 0, 0 );
 fdIcon.right = new FormAttachment( 0, image.getBounds().width );
 fdIcon.bottom = new FormAttachment( 0, image.getBounds().height );
 wIcon.setLayoutData( fdIcon );
 Composite wcMessage = new Composite( shell, SWT.NONE );
 props.setLook( wcMessage );
 wcMessage.setLayout( new GridLayout() );
  if ( !display.readAndDispatch() ) {
   display.sleep();

代码示例来源:origin: pentaho/pentaho-kettle

public String open() {
 Shell parent = getParent();
 Display display = parent.getDisplay();
 shell = new Shell( parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX );
 props.setLook( shell );
 setShellImage( shell, input );
 formLayout.marginHeight = Const.FORM_MARGIN;
 shell.setLayout( formLayout );
 int margin = Const.MARGIN;
 Rectangle imageBounds = GUIResource.getInstance().getImageInfoHop().getBounds();
 wlStepname = new Label( shell, SWT.RIGHT );
 wlStepname.setText( BaseMessages.getString( PKG, "ValidatorDialog.Stepname.Label" ) );
 props.setLook( wlStepname );
 fdlStepname = new FormData();
 wSComp.setLayoutData( fdComp );
 wComp.layout();
  if ( !display.readAndDispatch() ) {
   display.sleep();

代码示例来源:origin: caoxinyu/RedisClient

shell.setText(RedisClient.i18nFile.getText(I18nFile.ABOUTREDISCLIENT));
shell.setLayout(new GridLayout(1, false));
Composite composite = new Composite(shell, SWT.NONE);
composite.setLayout(new GridLayout(3, false));
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
final int width = image.getBounds().width;
final int height = image.getBounds().height;
final Image scaled050 = new Image(shell.getDisplay(),
    image.getImageData().scaledTo((int)(width*0.5),(int)(height*0.5)));
Label btnNewButton_1 = new Label(composite, SWT.FLAT);
btnNewButton_1.setBounds(0, 0, 80, 27);
btnNewButton_1.setImage(scaled050);
lblNewLabel.addSelectionListener(openUrl);
lblNewLabel.setFont(SWTResourceManager.getFont("Arial", 20, SWT.NORMAL));
lblNewLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
lblNewLabel.setBounds(0, 0, 61, 17);
lblNewLabel.setText("<a href=\"https://github.com/caoxinyu/RedisClient\">RedisClient for Windows</a>");
Label label = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
new Label(composite, SWT.NONE);

代码示例来源:origin: pentaho/pentaho-kettle

public int open() {
 Display display = parent.getDisplay();
 shell = new Shell( parent, SWT.DIALOG_TRIM | SWT.RESIZE );
 shell.setImage( GUIResource.getInstance().getImageSpoon() );
  image = display.getSystemImage( SWT.ICON_WARNING );
  image = display.getSystemImage( SWT.ICON_INFORMATION );
  image = display.getSystemImage( SWT.ICON_QUESTION );
  wIcon = new Label( shell, SWT.NONE );
  props.setLook( wIcon );
  wIcon.setImage( image );
  FormData fdIcon = new FormData();
  fdIcon.left = new FormAttachment( 0, 0 );
  fdIcon.top = new FormAttachment( 0, 0 );
  fdIcon.right = new FormAttachment( 0, image.getBounds().width );
  fdIcon.bottom = new FormAttachment( 0, image.getBounds().height );
  wIcon.setLayoutData( fdIcon );

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.ui.editors

messageComposite = new Composite(parent, SWT.NONE);
GridLayout messageLayout = new GridLayout();
messageLayout.numColumns = 2;
messageLayout.marginHeight = 0;
messageLayout.makeColumnsEqualWidth = false;
messageComposite.setLayout(messageLayout);
messageImageLabel = new Label(messageComposite, SWT.NONE);
GridData imageData = new GridData(GridData.VERTICAL_ALIGN_CENTER);
Image sizingImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR);
Rectangle imageBounds;
if(sizingImage == null)
  imageBounds = new Rectangle(0,0,IDialogConstants.VERTICAL_MARGIN * 2,IDialogConstants.VERTICAL_MARGIN * 2);
else
  imageBounds = sizingImage.getBounds();
imageData.heightHint = imageBounds.height + IDialogConstants.VERTICAL_SPACING;
imageData.widthHint = imageBounds.width + IDialogConstants.HORIZONTAL_SPACING;
messageImageLabel.setLayoutData(imageData);
messageText.setBackground(parent.getDisplay().getSystemColor(
    SWT.COLOR_WIDGET_BACKGROUND));
GridData textData = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL
    | GridData.VERTICAL_ALIGN_CENTER);
messageText.setLayoutData(textData);

代码示例来源:origin: caoxinyu/RedisClient

@Override
public CTabItem init() {
  server = service.listById(id);
  Image subImage = new Image(tabFolder.getShell().getDisplay(),
      getClass().getResourceAsStream("/subscribe.png"));
  Composite composite_4 = new Composite(composite_3, SWT.NONE);
  composite_4.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
  composite_4.setLayout(new GridLayout(3, false));
  lblNewLabel = new Label(composite_4, SWT.NONE);
  lblNewLabel.setBounds(0, 0, 55, 15);
  lblNewLabel.setText(RedisClient.i18nFile.getText(I18nFile.CHANNEL));
  channel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
  channel.setBounds(0, 0, 88, 23);
  channel.addControlListener(new ControlAdapter() {
  btnNewButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
  btnNewButton.setBounds(0, 0, 75, 25);
  btnNewButton.setText(RedisClient.i18nFile.getText(I18nFile.SUBSCRIBE));
  tabFolder_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
  tabFolder_2.setBounds(0, 0, 156, 125);
  tabFolder_2.setSelectionBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));

代码示例来源:origin: org.eclipse.pde/org.eclipse.pde.ui

Label label = new Label(imageComposite, SWT.NONE);
  label.setText(mLastPlugin);
  label.setBackground(label.getParent().getBackground());
    mPluginImageContainer.layout();
  mPluginImageContainer = new Composite(imageComposite, SWT.NONE);
  mPluginImageContainer.setLayout(mRowLayout);
  mPluginImageContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
  mPluginImageContainer.setBackground(mPluginImageContainer.getParent().getBackground());
Image image = new Image(getViewSite().getShell().getDisplay(), element.getImageData());
displayedImages.add(image);
button.setImage(image);

代码示例来源:origin: caoxinyu/RedisClient

public CTabItem init(){
  server = service.listById(id);
  Image pubImage = new Image(tabFolder.getShell().getDisplay(),
      getClass().getResourceAsStream("/publish.png"));
  composite_3 = new Composite(tabFolder, SWT.NONE);
  tbtmNewItem.setControl(composite_3);
  composite_3.setLayout(new GridLayout(1, false));
  tbtmNewItem.setText(server.getName() +" "+RedisClient.i18nFile.getText(I18nFile.PUBLISH));
  tbtmNewItem.setImage(pubImage);
  sashForm_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
  Composite composite_4 = new Composite(sashForm_2, SWT.NONE);
  composite_4.setLayout(new GridLayout(1, false));
  Composite composite_5 = new Composite(composite_4, SWT.NONE);
  composite_5.setLayout(new GridLayout(3, false));
  composite_5.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
  label = new Label(composite_5, SWT.NONE);
  label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
  label.setText(RedisClient.i18nFile.getText(I18nFile.CHANNEL));

代码示例来源:origin: BiglySoftware/BiglyBT

boolean	can_popout 		= shell == null && public_chat;
Composite top_right = new Composite(rhs, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 3;
layout.marginWidth = 0;
top_right.setLayout(layout);
  GridData grid_data = new GridData( GridData.FILL_HORIZONTAL );
  top_right.setLayoutData(grid_data);
  Label label = new Label( top_right, SWT.NULL );
  grid_data = new GridData( GridData.FILL_HORIZONTAL );
  grid_data.horizontalSpan=can_popout?1:2;
  label.setLayoutData(grid_data);
  Label pop_out = new Label( top_right, SWT.NULL );
  Image image = ImageLoader.getInstance().getImage( "popout_window" );
  pop_out.setImage( image );
  GridData grid_data = new GridData();
  grid_data.widthHint=image.getBounds().width;
  grid_data.heightHint=image.getBounds().height;
  pop_out.setLayoutData(grid_data);
  pop_out.setCursor(pop_out.getDisplay().getSystemCursor(SWT.CURSOR_HAND));

代码示例来源:origin: stackoverflow.com

composite.addListener(SWT.Resize, new Listener() {
  public void handleEvent(Event e) {
    changeImage();
composite.setLayout(new FormLayout());
composite.setBackgroundMode(SWT.INHERIT_DEFAULT);
    Color color2 = new Color(display, 255, 255, 255);
    try {
      gc.setForeground(color1);
      gc.setBackground(color2);
      gc.fillGradientRectangle(rect.x, rect.y, rect.width,
          rect.height, true);
    } finally {
  oldImage.dispose();
Shell shell = new Shell(display);
try {
  shell.setSize(200, 100);
  shell.setLayout(new FillLayout());
  createComponents(shell);
  shell.open();
  while (!shell.isDisposed()) {
    if (!display.readAndDispatch()) {
  imageGradient.dispose();

代码示例来源:origin: caoxinyu/RedisClient

@Override
public CTabItem init(){
  server = service.listById(id);
  Image runImage = new Image(tabFolder.getShell().getDisplay(),
      getClass().getResourceAsStream("/run.png"));
  Image consoleImage = new Image(tabFolder.getShell().getDisplay(),
      getClass().getResourceAsStream("/console.png"));
  Composite composite_3 = new Composite(tabFolder, SWT.NONE);
  tbtmNewItem.setControl(composite_3);
  composite_3.setLayout(new GridLayout(1, false));
  tbtmNewItem.setText(server.getName() +" "+RedisClient.i18nFile.getText(I18nFile.CONSOLE));
  tbtmNewItem.setImage(consoleImage);
  composite_4 = new Composite(composite_3, SWT.NONE);
  composite_4.setLayout(new GridLayout(3, false));
  composite_4.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
  sashForm3.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
  cmdResult.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
  cmdResult.setEditable(false);
  cmdResult.addMouseListener(new MouseAdapter() {

代码示例来源:origin: org.eclipse.swt.cocoa.macosx/x86_64

public void setBackground (Color color) {
  super.setBackground(color);
  table.setBackground(color);
  if (sizeImage != null) {
    GC gc = new GC (sizeImage);
    gc.setBackground(getBackground());
    Rectangle size = sizeImage.getBounds();
    gc.fillRectangle(size);
    gc.dispose();
  }
}
public void setEnabled (boolean enabled) {

代码示例来源:origin: org.eclipse.xtext/ui

public void freeze() {
  release();
  if (sourceViewer instanceof SourceViewer) {
    Control viewerControl = ((SourceViewer) sourceViewer).getControl();
    if (viewerControl instanceof Composite) {
      Composite composite = (Composite) viewerControl;
      Display display = composite.getDisplay();
      // Flush pending redraw requests:
      while (!display.isDisposed() && display.readAndDispatch()) {
      }
      // Copy editor area:
      GC gc = new GC(composite);
      Point size;
      try {
        size = composite.getSize();
        image = new Image(gc.getDevice(), size.x, size.y);
        gc.copyArea(image, 0, 0);
      } finally {
        gc.dispose();
        gc = null;
      }
      // Persist editor area while executing refactoring:
      label = new Label(composite, SWT.NONE);
      label.setImage(image);
      label.setBounds(0, 0, size.x, size.y);
      label.moveAbove(null);
    }
  }
}

代码示例来源:origin: org.eclipse.rap/org.eclipse.rap.rwt

private void createText() {
 Label textLabel = new Label( shell, SWT.WRAP );
 if( markupEnabled ) {
  textLabel.setData( RWT.MARKUP_ENABLED, Boolean.TRUE );
 }
 GridData data = new GridData( GridData.HORIZONTAL_ALIGN_FILL );
 int imageWidth = image == null ? 0 : image.getBounds().width;
 int maxTextWidth = MAX_WIDTH - imageWidth - SPACING;
 int maxLineWidth = getMaxMessageLineWidth();
 if( maxLineWidth > maxTextWidth ) {
  data.widthHint = maxTextWidth;
 }
 textLabel.setLayoutData( data );
 textLabel.setText( message );
}

代码示例来源:origin: org.eclipse.mylyn.commons/screenshots

private void captureScreenshotContentFromSelection() {
  Display display = getShell().getDisplay();
  Image image = new Image(display, currentSelection);
  GC gc = new GC(image);
  gc.drawImage(workImage, currentSelection.x, currentSelection.y, currentSelection.width,
      currentSelection.height, 0, 0, currentSelection.width, currentSelection.height);
  gc.dispose();
  disposeImageResources();
  originalImage = image;
  Rectangle displayBounds = originalImage.getBounds();
  workImage = new Image(display, displayBounds.width, displayBounds.height);
  gc = new GC(workImage);
  gc.drawImage(originalImage, 0, 0);
  gc.dispose();
  workImageGC = new GC(workImage);
  workImageGC.setLineCap(SWT.CAP_ROUND);
  scrolledComposite.setEnabled(true);
  clearSelection();
  refreshCanvasSize();
  stateChanged();
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jface

@Override
  protected void updateContents(Object value) {
    RGB rgb = (RGB) value;
    // XXX: We don't have a value the first time this method is called".
    if (rgb == null) {
      rgb = new RGB(0, 0, 0);
    }
    // XXX: Workaround for 1FMQ0P3: SWT:ALL - TableItem.setImage doesn't work if using the identical image."
    if (image != null) {
      image.dispose();
    }

    ImageData id = createColorImage(colorLabel.getParent().getParent(), rgb);
    ImageData mask = id.getTransparencyMask();
    image = new Image(colorLabel.getDisplay(), id, mask);
    colorLabel.setImage(image);

    rgbLabel
        .setText("(" + rgb.red + "," + rgb.green + "," + rgb.blue + ")");//$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
  }
}

相关文章