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

📄 imageanalyzer.java

📁 SWT开发例子
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		string = createMsg(bundle.getString("Size_value"), 					 new Object[] {new Integer(imageData.width),							   new Integer(imageData.height)});		sizeLabel.setText(string);		string = createMsg(bundle.getString("Depth_value"), new Integer(imageData.depth));		depthLabel.setText(string);		string = createMsg(bundle.getString("Transparent_pixel_value"), pixelInfo(imageData.transparentPixel));		transparentPixelLabel.setText(string);		string = createMsg(bundle.getString("Time_to_load_value"), new Long(loadTime));		timeToLoadLabel.setText(string);		string = createMsg(bundle.getString("Animation_size_value"), 		                      new Object[] {new Integer(loader.logicalScreenWidth),								new Integer(loader.logicalScreenHeight)});		screenSizeLabel.setText(string);		string = createMsg(bundle.getString("Background_pixel_value"), pixelInfo(loader.backgroundPixel));		backgroundPixelLabel.setText(string);		string = createMsg(bundle.getString("Image_location_value"), 		                      new Object[] {new Integer(imageData.x), new Integer(imageData.y)});		locationLabel.setText(string);		string = createMsg(bundle.getString("Disposal_value"),		                      new Object[] {new Integer(imageData.disposalMethod),							      disposalString(imageData.disposalMethod)});		disposalMethodLabel.setText(string);		int delay = imageData.delayTime * 10;		int delayUsed = visibleDelay(delay);		if (delay != delayUsed) {			string = createMsg(bundle.getString("Delay_value"), 			                   new Object[] {new Integer(delay), new Integer(delayUsed)});		} else {			string = createMsg(bundle.getString("Delay_used"), new Integer(delay));		}		delayTimeLabel.setText(string);		if (loader.repeatCount == 0) {			string = createMsg( bundle.getString("Repeats_forever"), new Integer(loader.repeatCount));		} else {			string = createMsg(bundle.getString("Repeats_value"), new Integer(loader.repeatCount));		}		repeatCountLabel.setText(string);		if (imageData.palette.isDirect) {			string = bundle.getString("Palette_direct");		} else {			string = createMsg(bundle.getString("Palette_value"), new Integer(imageData.palette.getRGBs().length));		}		paletteLabel.setText(string);		string = createMsg(bundle.getString("Pixel_data_value"), 					 new Object[] {new Integer(imageData.bytesPerLine),						         new Integer(imageData.scanlinePad),							   depthInfo(imageData.depth)});		dataLabel.setText(string);		String data = dataHexDump(dataText.getLineDelimiter());		dataText.setText(data);				// bold the first column all the way down		int index = 0;		while((index = data.indexOf(':', index+1)) != -1) 			dataText.setStyleRange(new StyleRange(index - INDEX_DIGITS, INDEX_DIGITS, dataText.getForeground(), dataText.getBackground(), SWT.BOLD));		statusLabel.setText("");		// Redraw both canvases.		paletteCanvas.redraw();		imageCanvas.redraw();	}	void paintImage(PaintEvent event) {		Image paintImage = image;		int transparentPixel = imageData.transparentPixel;		if (transparentPixel != -1 && !transparent) {			imageData.transparentPixel = -1;			paintImage = new Image(display, imageData);		}		int w = Math.round(imageData.width * xscale);		int h = Math.round(imageData.height * yscale);		event.gc.drawImage(			paintImage,			0,			0,			imageData.width,			imageData.height,			ix + imageData.x,			iy + imageData.y,			w,			h);		if (showMask && (imageData.getTransparencyType() != SWT.TRANSPARENCY_NONE)) {			ImageData maskImageData = imageData.getTransparencyMask();			Image maskImage = new Image(display, maskImageData);			event.gc.drawImage(				maskImage,				0,				0,				imageData.width,				imageData.height,				w + 10 + ix + imageData.x,				iy + imageData.y,				w,				h);			maskImage.dispose();		}		if (transparentPixel != -1 && !transparent) {			imageData.transparentPixel = transparentPixel;			paintImage.dispose();		}	}	void paintPalette(PaintEvent event) {		GC gc = event.gc;		gc.fillRectangle(paletteCanvas.getClientArea());		if (imageData.palette.isDirect) {			// For a direct palette, display the masks.			int y = py + 10;			int xTab = 50;			gc.drawString("rMsk", 10, y, true);			gc.drawString(toHex4ByteString(imageData.palette.redMask), xTab, y, true);			gc.drawString("gMsk", 10, y+=12, true);			gc.drawString(toHex4ByteString(imageData.palette.greenMask), xTab, y, true);			gc.drawString("bMsk", 10, y+=12, true);			gc.drawString(toHex4ByteString(imageData.palette.blueMask), xTab, y, true);			gc.drawString("rShf", 10, y+=12, true);			gc.drawString(Integer.toString(imageData.palette.redShift), xTab, y, true);			gc.drawString("gShf", 10, y+=12, true);			gc.drawString(Integer.toString(imageData.palette.greenShift), xTab, y, true);			gc.drawString("bShf", 10, y+=12, true);			gc.drawString(Integer.toString(imageData.palette.blueShift), xTab, y, true);		} else {			// For an indexed palette, display the palette colors and indices.			RGB[] rgbs = imageData.palette.getRGBs();			if (rgbs != null) {				int xTab1 = 40, xTab2 = 100;				for (int i = 0; i < rgbs.length; i++) {					int y = (i+1) * 10 + py;					gc.drawString(String.valueOf(i), 10, y, true);					gc.drawString(toHexByteString(rgbs[i].red) + toHexByteString(rgbs[i].green) + toHexByteString(rgbs[i].blue), xTab1, y, true);					Color color = new Color(display, rgbs[i]);					gc.setBackground(color);					gc.fillRectangle(xTab2, y+2, 10, 10);					color.dispose();				}			}		}	}		void resizeShell(ControlEvent event) {		if (image == null || shell.isDisposed())			return;		resizeScrollBars();	}	// Reset the scale combos to 1.	void resetScaleCombos() {		xscale = 1; yscale = 1;		scaleXCombo.select(scaleXCombo.indexOf("1"));		scaleYCombo.select(scaleYCombo.indexOf("1"));	}		// Reset the scroll bars to 0.	void resetScrollBars() {		if (image == null) return;		ix = 0; iy = 0; py = 0;		resizeScrollBars();		imageCanvas.getHorizontalBar().setSelection(0);		imageCanvas.getVerticalBar().setSelection(0);		paletteCanvas.getVerticalBar().setSelection(0);	}		void resizeScrollBars() {		// Set the max and thumb for the image canvas scroll bars.		ScrollBar horizontal = imageCanvas.getHorizontalBar();		ScrollBar vertical = imageCanvas.getVerticalBar();		Rectangle canvasBounds = imageCanvas.getClientArea();		int width = Math.round(imageData.width * xscale);		if (width > canvasBounds.width) {			// The image is wider than the canvas.			horizontal.setEnabled(true);			horizontal.setMaximum(width);			horizontal.setThumb(canvasBounds.width);			horizontal.setPageIncrement(canvasBounds.width);		} else {			// The canvas is wider than the image.			horizontal.setEnabled(false);			if (ix != 0) {				// Make sure the image is completely visible.				ix = 0;				imageCanvas.redraw();			}		}		int height = Math.round(imageData.height * yscale);		if (height > canvasBounds.height) {			// The image is taller than the canvas.			vertical.setEnabled(true);			vertical.setMaximum(height);			vertical.setThumb(canvasBounds.height);			vertical.setPageIncrement(canvasBounds.height);		} else {			// The canvas is taller than the image.			vertical.setEnabled(false);			if (iy != 0) {				// Make sure the image is completely visible.				iy = 0;				imageCanvas.redraw();			}		}		// Set the max and thumb for the palette canvas scroll bar.		vertical = paletteCanvas.getVerticalBar();		if (imageData.palette.isDirect) {			vertical.setEnabled(false);		} else { // indexed palette			canvasBounds = paletteCanvas.getClientArea();			int paletteHeight = imageData.palette.getRGBs().length * 10 + 20; // 10 pixels each index + 20 for margins.			vertical.setEnabled(true);			vertical.setMaximum(paletteHeight);			vertical.setThumb(canvasBounds.height);			vertical.setPageIncrement(canvasBounds.height);		}	}	/*	 * Called when the image canvas' horizontal scrollbar is selected.	 */	void scrollHorizontally(ScrollBar scrollBar) {		if (image == null) return;		Rectangle canvasBounds = imageCanvas.getClientArea();		int width = Math.round(imageData.width * xscale);		int height = Math.round(imageData.height * yscale);		if (width > canvasBounds.width) {			// Only scroll if the image is bigger than the canvas.			int x = -scrollBar.getSelection();			if (x + width < canvasBounds.width) {				// Don't scroll past the end of the image.				x = canvasBounds.width - width;			}			imageCanvas.scroll(x, iy, ix, iy, width, height, false);			ix = x;		}	}		/*	 * Called when the image canvas' vertical scrollbar is selected.	 */	void scrollVertically(ScrollBar scrollBar) {		if (image == null) return;		Rectangle canvasBounds = imageCanvas.getClientArea();		int width = Math.round(imageData.width * xscale);		int height = Math.round(imageData.height * yscale);		if (height > canvasBounds.height) {			// Only scroll if the image is bigger than the canvas.			int y = -scrollBar.getSelection();			if (y + height < canvasBounds.height) {				// Don't scroll past the end of the image.				y = canvasBounds.height - height;			}			imageCanvas.scroll(ix, y, ix, iy, width, height, false);			iy = y;		}	}	/*	 * Called when the palette canvas' vertical scrollbar is selected.	 */	void scrollPalette(ScrollBar scrollBar) {		if (image == null) return;		Rectangle canvasBounds = paletteCanvas.getClientArea();		int paletteHeight = imageData.palette.getRGBs().length * 10 + 20;		if (paletteHeight > canvasBounds.height) {			// Only scroll if the palette is bigger than the canvas.			int y = -scrollBar.getSelection();			if (y + paletteHeight < canvasBounds.height) {				// Don't scroll past the end of the palette.				y = canvasBounds.height - paletteHeight;			}			paletteCanvas.scroll(0, y, 0, py, paletteWidth, paletteHeight, false);			py = y;		}	}	/*	 * Return a String containing a line-by-line dump of	 * the data in the current imageData. The lineDelimiter	 * parameter must be a string of length 1 or 2.	 */	String dataHexDump(String lineDelimiter) {		if (image == null) return "";		char[] dump = new char[imageData.height * (6 + 3 * imageData.bytesPerLine + lineDelimiter.length())];		int index = 0;		for (int i = 0; i < imageData.data.length; i++) {			if (i % imageData.bytesPerLine == 0) {				int line = i / imageData.bytesPerLine;				dump[index++] = Character.forDigit(line / 1000 % 10, 10);				dump[index++] = Character.forDigit(line / 100 % 10, 10);				dump[index++] = Character.forDigit(line / 10 % 10, 10);				dump[index++] = Character.forDigit(line % 10, 10);				dump[index++] = ':';				dump[index++] = ' ';			}			byte b = imageData.data[i];			dump[index++] = Character.forDigit((b & 0xF0) >> 4, 16);			dump[index++] = Character.forDigit(b & 0x0F, 16);			dump[index++] = ' ';			if ((i + 1) % imageData.bytesPerLine == 0) {				dump[index++] = lineDelimiter.charAt(0);				if (lineDelimiter.length() > 1)					dump[index++] = lineDelimiter.charAt(1);			}		}		String result = "";		try {			result = new String(dump);		} catch (OutOfMemoryError e) {			/* Too much data to display in the text widget - truncate at 4M. */			result = new String(dump, 0, 4 * 1024 * 1024) + "\n ...data dump truncated at 4M...";		}		return result;	}		/*	 * Open an error dialog displaying the specified information.	 */	void showErrorDialog(String operation, String filename, Throwable e) {		MessageBox box = new MessageBox(shell, SWT.ICON_ERROR);		String message = createMsg(bundle.getString("Error"), new String[] {operation, filename});		String errorMessage = "";		if (e != null) {			if (e instanceof SWTException) {				SWTException swte = (SWTException) e;				errorMessage = swte.getMessage();				if (swte.throwable != null) {					errorMessage += ":\n" + swte.throwable.toString();				}			} else if (e instanceof SWTError) {				SWTError swte = (SWTError) e;				errorMessage = swte.getMessage();				if (swte.throwable != null) {					errorMessage += ":\n" + swte.throwable.toString();				}			} else {				errorMessage = e.toString();			}		}		box.setMessage(message + errorMessage);		box.open();	}		/*	 * Return a String describing how to analyze the bytes	 * in the hex dump.	 */	static String depthInfo(int depth) {		Object[] args = {new Integer(depth), ""};		switch (depth) {			case 1:				args[1] = createMsg(bundle.getString("Multi_pixels"), 				                    new Object[] {new Integer(8), " [01234567]"});				break;			case 2:				args[1] = createMsg(bundle.getString("Multi_pixels"),				                    new Object[] {new Integer(4), "[00112233]"});				break;			case 4:				args[1] = createMsg(bundle.getString("Multi_pixels"),				                    new Object[] {new Integer(2), "[00001111]"});				break;			case 8:				args[1] = bundle.getString("One_byte");				break;			case 16:				args[1] = createMsg(bundle.getString("Multi_bytes"), new Integer(2));				break;			case 24:				args[1] = createMsg(bundle.getString("Multi_bytes"), new Integer(3));				break;			case 32:				args[1] = createMsg(bundle.getString("Multi_bytes"), new Integer(4));				break;			default:				args[1] = bundle.getString("Unsupported_lc");		}		return createMsg(bundle.getString("Depth_info"), args);	}		/*	 * Return the specified number of milliseconds.	 * If the specified number of milliseconds is too small	 * to see a visual change, then return a higher number.	 */	static int visibleDelay(in

⌨️ 快捷键说明

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