當前位置: 首頁>>代碼示例>>Java>>正文


Java ImageData.setPixel方法代碼示例

本文整理匯總了Java中org.eclipse.swt.graphics.ImageData.setPixel方法的典型用法代碼示例。如果您正苦於以下問題:Java ImageData.setPixel方法的具體用法?Java ImageData.setPixel怎麽用?Java ImageData.setPixel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.swt.graphics.ImageData的用法示例。


在下文中一共展示了ImageData.setPixel方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getImageData

import org.eclipse.swt.graphics.ImageData; //導入方法依賴的package包/類
protected ImageData getImageData() {
	int[][] a = (int[][]) array;
	ImageData data = new ImageData(width, height, 24, palette);
	for(int y = 0; y < height; y++) {
		for(int x = 0; x < width; x++) {
			int v = a[y][x];
			int r = (v >> 16) & 0xFF;
			int g = (v >> 8) & 0xFF;
			int b = v & 0xFF;

			int pixel = 0;
			if(valid(r, g, b)) {
				pixel |= (redShift < 0 ? r << -redShift : r >>> redShift) & redMask;
				pixel |= (greenShift < 0 ? g << -greenShift : g >>> greenShift) & greenMask;
				pixel |= (blueShift < 0 ? b << -blueShift : b >>> blueShift) & blueMask;
			}
			//					int pixel = valid(r,g,b) ? palette.getPixel(new RGB(r,g,b)) : palette.getPixel(new RGB(255, 0, 0));
			data.setPixel(x, y, pixel);
		}
	}
	return data;
}
 
開發者ID:andre-santos-pt,項目名稱:pandionj,代碼行數:23,代碼來源:ColorImageWidget.java

示例2: applyTransparency

import org.eclipse.swt.graphics.ImageData; //導入方法依賴的package包/類
public void applyTransparency( TGColor background ){
	RGB alpha = new RGB( background.getRed(), background.getGreen(), background.getBlue() );
	RGB none = new RGB((0xff ^ alpha.red),(0xff ^ alpha.green),(0xff ^ alpha.blue));
	
	Image srcImage = this.handle;
	ImageData srcData = srcImage.getImageData();
	ImageData maskData = new ImageData(srcData.width,srcData.height,1,new PaletteData(new RGB[]{ none,alpha }  ));
	for(int x = 0; x< maskData.width; x++) {
		for(int y = 0; y < maskData.height; y++) {
			RGB rgb = srcData.palette.getRGB(srcData.getPixel(x, y));
			if(rgb.red == alpha.red && rgb.green == alpha.green && rgb.blue == alpha.blue){
				maskData.setPixel(x, y, maskData.palette.getPixel(none));
			}else{
				maskData.setPixel(x, y, maskData.palette.getPixel(alpha));
			}
		}
	}
	this.handle = new Image(srcImage.getDevice(),srcData,maskData);
	
	srcImage.dispose();
}
 
開發者ID:theokyr,項目名稱:TuxGuitar-1.3.1-fork,代碼行數:22,代碼來源:TGImageImpl.java

示例3: getControllerImage

import org.eclipse.swt.graphics.ImageData; //導入方法依賴的package包/類
public Image getControllerImage(Display display) {
	if(ctrlImage == null) {
		ImageData img = new ImageData(48, 48, 32, RGB_PALETTE);
		for(int y = 0; y < 40; y++)
			for(int x = 0; x < 48; x++) {
				int col = x / 6;
				int row = y / 5;
				int id  = (row * 8) + col; 
				if(x % 6 < 5 && y % 5 < 4) {
					img.setAlpha(x, y+4, 255);
					if(id == this.id)	img.setPixel(x, y+4, color.toARGB32());
					else				img.setPixel(x, y+4, 0x444444);
				} else img.setAlpha(x, y+4, 0);
			}
		ctrlImage = new Image(display, img);
	}
	return ctrlImage;
}
 
開發者ID:arisona,項目名稱:ether,代碼行數:19,代碼來源:Bouncelet.java

示例4: getImageData

import org.eclipse.swt.graphics.ImageData; //導入方法依賴的package包/類
protected ImageData getImageData() {
	int[][] a = (int[][]) array;
	ImageData data = new ImageData(width, height, 8, grayscalePalette);
	for(int y = 0; y < height; y++) {
		for(int x = 0; x < width && x < width; x++)
			data.setPixel(x, y, valid(a[y][x]) ? a[y][x] : 0);
	}
	return data;
}
 
開發者ID:andre-santos-pt,項目名稱:pandionj,代碼行數:10,代碼來源:GrayscaleImageWidget.java

示例5: getImageData

import org.eclipse.swt.graphics.ImageData; //導入方法依賴的package包/類
protected ImageData getImageData() {
	boolean[][] a = (boolean[][]) array;
	ImageData data = new ImageData(width, height, 1, binaryPalette);
	for(int y = 0; y < height; y++)
		for(int x = 0; x < width && x < width; x++)
			data.setPixel(x, y, a[y][x] ? 0 : 1);
	return data;
}
 
開發者ID:andre-santos-pt,項目名稱:pandionj,代碼行數:9,代碼來源:BinaryImageWidget.java

示例6: applyMask

import org.eclipse.swt.graphics.ImageData; //導入方法依賴的package包/類
/**
 * Crea una mascara a partir de src.
 * 
 * @param src
 * @param alpha
 * @param none
 * @return ImageData
 */
public static ImageData applyMask(ImageData src,RGB alpha,RGB none){
	ImageData maskData = new ImageData(src.width,src.height,1,new PaletteData(new RGB[]{ none,alpha }  ));
	for(int x = 0; x< maskData.width; x++) {
		for(int y = 0; y < maskData.height; y++) {
			RGB rgb = src.palette.getRGB(src.getPixel(x, y));
			if(rgb.red == alpha.red && rgb.green == alpha.green && rgb.blue == alpha.blue){
				maskData.setPixel(x, y, maskData.palette.getPixel(none));
			}else{
				maskData.setPixel(x, y, maskData.palette.getPixel(alpha));
			}
		}
	}
	return maskData;
}
 
開發者ID:theokyr,項目名稱:TuxGuitar-1.3.1-fork,代碼行數:23,代碼來源:ImageUtils.java

示例7: setBrightness

import org.eclipse.swt.graphics.ImageData; //導入方法依賴的package包/類
private static void setBrightness() {
        if (image.isDisposed()) {
            return;
        }

        final ImageData imageData = image.getImageData();

        for (int x = 0; x < imageData.width; x++) {
            for (int y = 0; y < imageData.height; y++) {
                final RGB rgb = imageData.palette.getRGB(imageData.getPixel(x, y));
                final float[] hsb = rgb.getHSB();

                hsb[2] = hsb[2] + 0.1f;
                if (hsb[2] > 1.0f) {
                    hsb[2] = 1.0f;
                }

//				hsb[1] = hsb[1] - 0.1f;
//				if (hsb[1] < 0.0f) {
//					hsb[1] = 0.0f;
//				}
                final RGB newRGB = new RGB(hsb[0], hsb[1], hsb[2]);

                final int pixel = imageData.palette.getPixel(newRGB);
                imageData.setPixel(x, y, pixel);
            }
        }

        image.dispose();
        image = new Image(Display.getDefault(), imageData);

        imageFigure.setImage(image);
    }
 
開發者ID:roundrop,項目名稱:ermasterr,代碼行數:34,代碼來源:ImageTest.java

示例8: multScalar

import org.eclipse.swt.graphics.ImageData; //導入方法依賴的package包/類
/**
	 * Multiplies all pixels of the given ImageData with the given scalar factor
	 * and returns a new image data
	 */
	public static ImageData multScalar(ImageData data, double factor, boolean inPlace) {
		ImageData newImageData = inPlace ? data : 
				new ImageData (data.width, data.height, 24, new PaletteData (0xFF, 0xFF00, 0xFF0000));
		
		final int w = data.width;
		final int h = data.height;
	
		for (int x=0; x<w; ++x) {
			for (int y=0; y<h; ++y) {
				int p = data.getPixel(x, y);
				
				RGB rgb = data.palette.getRGB(p);
				
//				System.out.println("rgb = "+rgb);
				
				rgb.red = CoreUtils.bound(rgb.red *= factor, 0, 255);
				rgb.green = CoreUtils.bound(rgb.green *= factor, 0, 255);
				rgb.blue = CoreUtils.bound(rgb.blue *= factor, 0, 255);
				
//				rgb.red = CoreUtils.bound((int) Math.pow(rgb.red, gamma), 0, 255);
//				rgb.green = CoreUtils.bound((int) Math.pow(rgb.green, gamma), 0, 255);
//				rgb.blue = CoreUtils.bound((int) Math.pow(rgb.blue, gamma), 0, 255);
				
//				System.out.println("rgb2 = "+rgb);
				newImageData.setPixel(x, y, newImageData.palette.getPixel(rgb));
			}
		}
		
		return newImageData;
	}
 
開發者ID:Transkribus,項目名稱:TranskribusSwtGui,代碼行數:35,代碼來源:SWTUtil.java

示例9: setBrightness

import org.eclipse.swt.graphics.ImageData; //導入方法依賴的package包/類
private static void setBrightness() {
		if (image.isDisposed()) {
			return;
		}

		ImageData imageData = image.getImageData();

		for (int x = 0; x < imageData.width; x++) {
			for (int y = 0; y < imageData.height; y++) {
				RGB rgb = imageData.palette.getRGB(imageData.getPixel(x, y));
				float[] hsb = rgb.getHSB();

				hsb[2] = hsb[2] + 0.1f;
				if (hsb[2] > 1.0f) {
					hsb[2] = 1.0f;
				}
				
//				hsb[1] = hsb[1] - 0.1f;
//				if (hsb[1] < 0.0f) {
//					hsb[1] = 0.0f;
//				}
				RGB newRGB = new RGB(hsb[0], hsb[1], hsb[2]);

				
				int pixel = imageData.palette.getPixel(newRGB);
				imageData.setPixel(x, y, pixel);
			}
		}

		image.dispose();
		image = new Image(Display.getDefault(), imageData);

		imageFigure.setImage(image);
	}
 
開發者ID:kozake,項目名稱:ermaster-k,代碼行數:35,代碼來源:ImageTest.java

示例10: rotate

import org.eclipse.swt.graphics.ImageData; //導入方法依賴的package包/類
/**
 * Rotate an image
 * @param image the source
 * @param direction : SWT.LEFT will rotate by 90 degrees on the left, SWT.RIGHT will rotate by 90 degrees on the right, SWT.DOWN will rotate by 180 degrees.
 * @return the rotated image
 */
private Image rotate(Image image, int direction) {
  ImageData srcData = image.getImageData();
  int bytesPerPixel = srcData.bytesPerLine / srcData.width;
  int destBytesPerLine = (direction == SWT.DOWN) ? srcData.width * bytesPerPixel : srcData.height * bytesPerPixel;
  byte[] newData = new byte[srcData.data.length];

  boolean isAlpha = srcData.alphaData != null;
  byte[] newAlphaData = null;

  if (isAlpha) {
    newAlphaData = new byte[srcData.alphaData.length];
  }
  ImageData imgData =
      new ImageData((direction == SWT.DOWN) ? srcData.width : srcData.height, (direction == SWT.DOWN) ? srcData.height : srcData.width, srcData.depth,
          srcData.palette, destBytesPerLine, newData);
  if (isAlpha) {
    imgData.alphaData = newAlphaData;
  }
  imgData.alpha = srcData.alpha;

  for (int srcY = 0; srcY < srcData.height; srcY++) {
    for (int srcX = 0; srcX < srcData.width; srcX++) {
      int destX = 0, destY = 0;

      switch (direction) {
        case SWT.LEFT: // left 90 degrees
          destX = srcY;
          destY = srcData.width - srcX - 1;
        break;
        case SWT.RIGHT: // right 90 degrees
          destX = srcData.height - srcY - 1;
          destY = srcX;
        break;
        case SWT.DOWN: // 180 degrees
          destX = srcData.width - srcX - 1;
          destY = srcData.height - srcY - 1;
        break;
      }

      imgData.setPixel(destX, destY, srcData.getPixel(srcX, srcY));
      if (isAlpha) {
        imgData.setAlpha(destX, destY, srcData.getAlpha(srcX, srcY));
      }
    }
  }

  return new Image(image.getDevice(), imgData);
}
 
開發者ID:polarsys,項目名稱:time4sys,代碼行數:55,代碼來源:RotativeWorkspaceImageFigure.java

示例11: changeImage

import org.eclipse.swt.graphics.ImageData; //導入方法依賴的package包/類
private void changeImage() {
    final InsertedImage model = (InsertedImage) getModel();

    final ImageData newImageData = new ImageData(imageData.width, imageData.height, imageData.depth, imageData.palette);

    for (int x = 0; x < imageData.width; x++) {
        for (int y = 0; y < imageData.height; y++) {
            final RGB rgb = imageData.palette.getRGB(imageData.getPixel(x, y));
            final float[] hsb = rgb.getHSB();

            if (model.getHue() != 0) {
                hsb[0] = model.getHue() & 360;
            }

            hsb[1] = hsb[1] + (model.getSaturation() / 100f);
            if (hsb[1] > 1.0f) {
                hsb[1] = 1.0f;
            } else if (hsb[1] < 0) {
                hsb[1] = 0f;
            }

            hsb[2] = hsb[2] + (model.getBrightness() / 100f);
            if (hsb[2] > 1.0f) {
                hsb[2] = 1.0f;

            } else if (hsb[2] < 0) {
                hsb[2] = 0f;
            }

            final RGB newRGB = new RGB(hsb[0], hsb[1], hsb[2]);

            final int pixel = imageData.palette.getPixel(newRGB);

            newImageData.setPixel(x, y, pixel);
        }
    }

    if (image != null && !image.isDisposed()) {
        image.dispose();
    }

    image = new Image(Display.getDefault(), newImageData);
}
 
開發者ID:roundrop,項目名稱:ermasterr,代碼行數:44,代碼來源:InsertedImageEditPart.java

示例12: changeImage

import org.eclipse.swt.graphics.ImageData; //導入方法依賴的package包/類
private void changeImage() {
	InsertedImage model = (InsertedImage) this.getModel();

	ImageData newImageData = new ImageData(this.imageData.width,
			this.imageData.height, this.imageData.depth,
			this.imageData.palette);

	for (int x = 0; x < this.imageData.width; x++) {
		for (int y = 0; y < this.imageData.height; y++) {
			RGB rgb = this.imageData.palette.getRGB(this.imageData
					.getPixel(x, y));
			float[] hsb = rgb.getHSB();

			if (model.getHue() != 0) {
				hsb[0] = model.getHue() & 360;
			}

			hsb[1] = hsb[1] + (model.getSaturation() / 100f);
			if (hsb[1] > 1.0f) {
				hsb[1] = 1.0f;
			} else if (hsb[1] < 0) {
				hsb[1] = 0f;
			}

			hsb[2] = hsb[2] + (model.getBrightness() / 100f);
			if (hsb[2] > 1.0f) {
				hsb[2] = 1.0f;

			} else if (hsb[2] < 0) {
				hsb[2] = 0f;
			}

			RGB newRGB = new RGB(hsb[0], hsb[1], hsb[2]);

			int pixel = imageData.palette.getPixel(newRGB);

			newImageData.setPixel(x, y, pixel);
		}
	}

	if (this.image != null && !this.image.isDisposed()) {
		this.image.dispose();
	}

	this.image = new Image(Display.getDefault(), newImageData);
}
 
開發者ID:kozake,項目名稱:ermaster-k,代碼行數:47,代碼來源:InsertedImageEditPart.java


注:本文中的org.eclipse.swt.graphics.ImageData.setPixel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。