⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imageanalyzer.java

📁 SUN公司eclipse3.2.2经典例子
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	}	void menuPrint() {		if (image == null) return;		try {			// Ask the user to specify the printer.			PrintDialog dialog = new PrintDialog(shell, SWT.NONE);			PrinterData printerData = dialog.open();			if (printerData == null) return;						Printer printer = new Printer(printerData);			Point screenDPI = display.getDPI();			Point printerDPI = printer.getDPI();			int scaleFactor = printerDPI.x / screenDPI.x;			Rectangle trim = printer.computeTrim(0, 0, 0, 0);			if (printer.startJob(currentName)) {				if (printer.startPage()) {					GC gc = new GC(printer);					int transparentPixel = imageData.transparentPixel;					if (transparentPixel != -1 && !transparent) {						imageData.transparentPixel = -1;					}					Image printerImage = new Image(printer, imageData);					gc.drawImage(						printerImage,						0,						0,						imageData.width,						imageData.height,						-trim.x,						-trim.y,						scaleFactor * imageData.width,						scaleFactor * imageData.height);					if (transparentPixel != -1 && !transparent) {						imageData.transparentPixel = transparentPixel;					}					printerImage.dispose();					gc.dispose();					printer.endPage();				}				printer.endJob();			}			printer.dispose();		} catch (SWTError e) {			MessageBox box = new MessageBox(shell, SWT.ICON_ERROR);			box.setMessage(bundle.getString("Printing_error") + e.getMessage());			box.open();		}	}	void menuReopen() {		if (currentName == null) return;		animate = false; // stop any animation in progress		Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);		shell.setCursor(waitCursor);		imageCanvas.setCursor(waitCursor);		try {			loader = new ImageLoader();			ImageData[] newImageData;			if (fileName == null) {				URL url = new URL(currentName);				InputStream stream = url.openStream();				long startTime = System.currentTimeMillis();				newImageData = loader.load(stream);				loadTime = System.currentTimeMillis() - startTime;				stream.close();			} else {				long startTime = System.currentTimeMillis();				newImageData = loader.load(fileName);				loadTime = System.currentTimeMillis() - startTime;			}			imageDataIndex = 0;			displayImage(newImageData[imageDataIndex]);		} catch (Exception e) {			showErrorDialog(bundle.getString("Reloading_lc"), currentName, e);		} catch (OutOfMemoryError e) {			showErrorDialog(bundle.getString("Reloading_lc"), currentName, e);		} finally {				shell.setCursor(null);			imageCanvas.setCursor(crossCursor);			waitCursor.dispose();		}	}		void changeBackground() {		String background = backgroundCombo.getText();		if (background.equals(bundle.getString("White"))) {			imageCanvas.setBackground(whiteColor);		} else if (background.equals(bundle.getString("Black"))) {			imageCanvas.setBackground(blackColor);		} else if (background.equals(bundle.getString("Red"))) {			imageCanvas.setBackground(redColor);		} else if (background.equals(bundle.getString("Green"))) {			imageCanvas.setBackground(greenColor);		} else if (background.equals(bundle.getString("Blue"))) {			imageCanvas.setBackground(blueColor);		} else {			imageCanvas.setBackground(null);		}	}		/*	 * Called when the ScaleX combo selection changes.	 */	void scaleX() {		try {			xscale = Float.parseFloat(scaleXCombo.getText());		} catch (NumberFormatException e) {			xscale = 1;			scaleXCombo.select(scaleXCombo.indexOf("1"));		}		if (image != null) {			resizeScrollBars();			imageCanvas.redraw();		}	}		/*	 * Called when the ScaleY combo selection changes.	 */	void scaleY() {		try {			yscale = Float.parseFloat(scaleYCombo.getText());		} catch (NumberFormatException e) {			yscale = 1;			scaleYCombo.select(scaleYCombo.indexOf("1"));		}		if (image != null) {			resizeScrollBars();			imageCanvas.redraw();		}	}		/*	 * Called when the Alpha combo selection changes.	 */	void alpha() {		try {			alpha = Integer.parseInt(alphaCombo.getText());		} catch (NumberFormatException e) {			alphaCombo.select(alphaCombo.indexOf("255"));			alpha = 255;		}	}		/*	 * Called when the mouse moves in the image canvas.	 * Show the color of the image at the point under the mouse.	 */	void showColorAt(int mx, int my) {		int x = mx - imageData.x - ix;		int y = my - imageData.y - iy;		showColorForPixel(x, y);	}		/*	 * Called when a mouse down or key press is detected	 * in the data text. Show the color of the pixel at	 * the caret position in the data text.	 */	void showColorForData() {		int delimiterLength = dataText.getLineDelimiter().length();		int charactersPerLine = 6 + 3 * imageData.bytesPerLine + delimiterLength;		int position = dataText.getCaretOffset();		int y = position / charactersPerLine;		if ((position - y * charactersPerLine) < 6 || ((y + 1) * charactersPerLine - position) <= delimiterLength) {			statusLabel.setText("");			return;		}		int dataPosition = position - 6 * (y + 1) - delimiterLength * y;		int byteNumber = dataPosition / 3;		int where = dataPosition - byteNumber * 3;		int xByte = byteNumber % imageData.bytesPerLine;		int x = -1;		int depth = imageData.depth;		if (depth == 1) { // 8 pixels per byte (can only show 3 of 8)			if (where == 0) x = xByte * 8;			if (where == 1) x = xByte * 8 + 3;			if (where == 2) x = xByte * 8 + 7;		}		if (depth == 2) { // 4 pixels per byte (can only show 3 of 4)			if (where == 0) x = xByte * 4;			if (where == 1) x = xByte * 4 + 1;			if (where == 2) x = xByte * 4 + 3;		}		if (depth == 4) { // 2 pixels per byte			if (where == 0) x = xByte * 2;			if (where == 1) x = xByte * 2;			if (where == 2) x = xByte * 2 + 1;		}		if (depth == 8) { // 1 byte per pixel			x = xByte;		}		if (depth == 16) { // 2 bytes per pixel			x = xByte / 2;		}		if (depth == 24) { // 3 bytes per pixel			x = xByte / 3;		}		if (depth == 32) { // 4 bytes per pixel			x = xByte / 4;		}		if (x != -1) {			showColorForPixel(x, y);		} else {			statusLabel.setText("");		}	}		/*	 * Set the status label to show color information	 * for the specified pixel in the image.	 */	void showColorForPixel(int x, int y) {		if (x >= 0 && x < imageData.width && y >= 0 && y < imageData.height) {			int pixel = imageData.getPixel(x, y);			RGB rgb = imageData.palette.getRGB(pixel);			boolean hasAlpha = false;			int alphaValue = 0;			if (imageData.alphaData != null && imageData.alphaData.length > 0) {				hasAlpha = true;				alphaValue = imageData.getAlpha(x, y);			}			String rgbMessageFormat = bundle.getString(hasAlpha ? "RGBA" : "RGB");			Object[] rgbArgs = {					Integer.toString(rgb.red),					Integer.toString(rgb.green),					Integer.toString(rgb.blue),					Integer.toString(alphaValue)			};			Object[] rgbHexArgs = {					Integer.toHexString(rgb.red),					Integer.toHexString(rgb.green),					Integer.toHexString(rgb.blue),					Integer.toHexString(alphaValue)			};			Object[] args = {					new Integer(x),					new Integer(y),					new Integer(pixel),					Integer.toHexString(pixel),					createMsg(rgbMessageFormat, rgbArgs),					createMsg(rgbMessageFormat, rgbHexArgs),					(pixel == imageData.transparentPixel) ? bundle.getString("Color_at_transparent") : ""};			statusLabel.setText(createMsg(bundle.getString("Color_at"), args));		} else {			statusLabel.setText("");		}	}		/*	 * Called when the Animate button is pressed.	 */	void animate() {		animate = !animate;		if (animate && image != null && imageDataArray.length > 1) {			animateThread = new Thread(bundle.getString("Animation")) {				public void run() {					// Pre-animation widget setup.					preAnimation();										// Animate.					try {						animateLoop();					} catch (final SWTException e) {						display.syncExec(new Runnable() {							public void run() {								showErrorDialog(createMsg(bundle.getString("Creating_image"), 										    new Integer(imageDataIndex+1)),										    currentName, e);							}						});					}										// Post animation widget reset.					postAnimation();				}			};			animateThread.setDaemon(true);			animateThread.start();		}	}		/*	 * Loop through all of the images in a multi-image file	 * and display them one after another.	 */	void animateLoop() {		// Create an off-screen image to draw on, and a GC to draw with.		// Both are disposed after the animation.		Image offScreenImage = new Image(display, loader.logicalScreenWidth, loader.logicalScreenHeight);		GC offScreenImageGC = new GC(offScreenImage);				try {			// Use syncExec to get the background color of the imageCanvas.			display.syncExec(new Runnable() {				public void run() {					canvasBackground = imageCanvas.getBackground();				}			});			// Fill the off-screen image with the background color of the canvas.			offScreenImageGC.setBackground(canvasBackground);			offScreenImageGC.fillRectangle(				0,				0,				loader.logicalScreenWidth,				loader.logicalScreenHeight);								// Draw the current image onto the off-screen image.			offScreenImageGC.drawImage(				image,				0,				0,				imageData.width,				imageData.height,				imageData.x,				imageData.y,				imageData.width,				imageData.height);			int repeatCount = loader.repeatCount;			while (animate && (loader.repeatCount == 0 || repeatCount > 0)) {				if (imageData.disposalMethod == SWT.DM_FILL_BACKGROUND) {					// Fill with the background color before drawing.					Color bgColor = null;					int backgroundPixel = loader.backgroundPixel;					if (showBackground && backgroundPixel != -1) {						// Fill with the background color.						RGB backgroundRGB = imageData.palette.getRGB(backgroundPixel);						bgColor = new Color(null, backgroundRGB);					}					try {						offScreenImageGC.setBackground(bgColor != null ? bgColor : canvasBackground);						offScreenImageGC.fillRectangle(							imageData.x,							imageData.y,							imageData.width,							imageData.height);					} finally {						if (bgColor != null) bgColor.dispose();					}				} else if (imageData.disposalMethod == SWT.DM_FILL_PREVIOUS) {					// Restore the previous image before drawing.					offScreenImageGC.drawImage(						image,						0,						0,						imageData.width,						imageData.height,						imageData.x,						imageData.y,						imageData.width,						imageData.height);				}													// Get the next image data.				imageDataIndex = (imageDataIndex + 1) % imageDataArray.length;				imageData = imageDataArray[imageDataIndex];				image.dispose();				image = new Image(display, imageData);								// Draw the new image data.				offScreenImageGC.drawImage(					image,					0,					0,					imageData.width,					imageData.height,					imageData.x,					imageData.y,					imageData.width,					imageData.height);								// Draw the off-screen image to the screen.				imageCanvasGC.drawImage(offScreenImage, 0, 0);								// Sleep for the specified delay time before drawing again.				try {					Thread.sleep(visibleDelay(imageData.delayTime * 10));				} catch (InterruptedException e) {				}								// If we have just drawn the last image in the set,				// then decrement the repeat count.				if (imageDataIndex == imageDataArray.length - 1) repeatCount--;			}		} finally {			offScreenImage.dispose();			offScreenImageGC.dispose();		}	}	/*	 * Pre animation setup.	 */	void preAnimation() {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -