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


Java SWT.TRANSPARENCY_PIXEL屬性代碼示例

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


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

示例1: autoScaleImageData

private static ImageData autoScaleImageData(Device device, final ImageData imageData, float scaleFactor) {
	int width = imageData.width;
	int height = imageData.height;
	int scaledWidth = Math.round(width * scaleFactor);
	int scaledHeight = Math.round(height * scaleFactor);


	ImageData imageMaskData = null;

	if (imageData.getTransparencyType() == SWT.TRANSPARENCY_ALPHA) {
		imageMaskData = new ImageData(width, height, 8, ALPHA_PALETTE, 0, imageData.alphaData);
	} else if (imageData.getTransparencyType() == SWT.TRANSPARENCY_PIXEL || imageData.getTransparencyType() == SWT.TRANSPARENCY_MASK) {
		ImageData transparencyMaskData = imageData.getTransparencyMask();
		imageMaskData = new ImageData(width, height, 1, BW_PALETTE, transparencyMaskData.scanlinePad, transparencyMaskData.data);
	}

	Image original = new Image(device, imageData);
	Image originalMask = null;

	if (imageMaskData != null) {
		originalMask = new Image(device, imageMaskData);
	}

	/* Create a 24 bit image data with alpha channel */
	ImageData resultData = new ImageData(scaledWidth, scaledHeight, 24, new PaletteData(0xFF, 0xFF00, 0xFF0000));
	ImageData resultMaskData = null;

	if (imageMaskData != null) {
		resultMaskData = new ImageData(scaledWidth, scaledHeight, imageMaskData.depth, imageMaskData.palette);
	}

	Image result = new Image(device, resultData);
	Image resultMask = null;

	GC gc = new GC(result);
	gc.setAntialias(SWT.ON);
	gc.drawImage(original, 0, 0, width, height, 0, 0, scaledWidth, scaledHeight);
	gc.dispose();

	if (resultMaskData != null) {
		resultMask = new Image(device, resultMaskData);
		gc = new GC(resultMask);
		gc.setAntialias(SWT.ON);
		gc.drawImage(originalMask, 0, 0, width, height, 0, 0, scaledWidth, scaledHeight);
		gc.dispose();
	}

	original.dispose();
	originalMask.dispose();

	ImageData scaledResult = result.getImageData();

	if (resultMask != null) {
		ImageData scaledResultMaskData = resultMask.getImageData();

		// Convert 1-bit mask
		if (scaledResultMaskData.depth == 1) {
			scaledResult.maskPad = scaledResultMaskData.scanlinePad;
			scaledResult.maskData = scaledResultMaskData.data;
		} else {
			scaledResult.alphaData = scaledResultMaskData.data;
		}
	}

	result.dispose();
	resultMask.dispose();
	return scaledResult;
}
 
開發者ID:BiglySoftware,項目名稱:BiglyBT,代碼行數:68,代碼來源:Utils.java


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