本文整理汇总了Java中org.jdesktop.swingx.graphics.GraphicsUtilities.createCompatibleTranslucentImage方法的典型用法代码示例。如果您正苦于以下问题:Java GraphicsUtilities.createCompatibleTranslucentImage方法的具体用法?Java GraphicsUtilities.createCompatibleTranslucentImage怎么用?Java GraphicsUtilities.createCompatibleTranslucentImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jdesktop.swingx.graphics.GraphicsUtilities
的用法示例。
在下文中一共展示了GraphicsUtilities.createCompatibleTranslucentImage方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paint
import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入方法依赖的package包/类
/**
* Overriden paint method to take into account the alpha setting
* @param g
*/
@Override
public void paint(Graphics g) {
float a = getAlpha();
if (a == 1) {
super.paint(g);
} else {
//the component is translucent, so we need to render to
//an intermediate image before painting
BufferedImage img = GraphicsUtilities.createCompatibleTranslucentImage(getWidth(), getHeight());
Graphics2D gfx = img.createGraphics();
super.paint(gfx);
gfx.dispose();
Graphics2D g2d = (Graphics2D)g;
Composite oldComp = g2d.getComposite();
Composite alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, a);
g2d.setComposite(alphaComp);
g2d.drawImage(img, null, 0, 0);
g2d.setComposite(oldComp);
}
}
示例2: createShadow
import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入方法依赖的package包/类
public static Shadow createShadow(Image source, int x, int y, boolean paintSource, int shadowSize) {
int size = shadowSize;
final float w = source.getWidth(null);
final float h = source.getHeight(null);
float ratio = w / h;
float deltaX = size;
float deltaY = size / ratio;
final Image scaled = source.getScaledInstance((int)(w + deltaX), (int)(h + deltaY), Image.SCALE_SMOOTH);
final BufferedImage s =
GraphicsUtilities.createCompatibleTranslucentImage(scaled.getWidth(null), scaled.getHeight(null));
final Graphics2D graphics = (Graphics2D)s.getGraphics();
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics.drawImage(scaled, 0, 0, null);
final BufferedImage shadow = new ShadowRenderer(size, .25f, Color.black).createShadow(s);
if (paintSource) {
final Graphics imgG = shadow.getGraphics();
final double d = size * 0.5;
imgG.drawImage(source, (int)(size + d), (int)(size + d / ratio), null);
}
return new Shadow(shadow, x - size - 5, y - size + 2);
}
示例3: getStaticImage
import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入方法依赖的package包/类
/**
* This method is used to show an image during message showing
* @return image to show
*/
Image getStaticImage() {
final JFrame myOffScreenFrame = new JFrame() ;
myOffScreenFrame.add(mySheetPanel);
myOffScreenFrame.getRootPane().setDefaultButton(myDefaultButton);
final BufferedImage image = (SystemInfo.isJavaVersionAtLeast("1.7")) ?
UIUtil.createImage(SHEET_NC_WIDTH, SHEET_NC_HEIGHT, BufferedImage.TYPE_INT_ARGB) :
GraphicsUtilities.createCompatibleTranslucentImage(SHEET_NC_WIDTH, SHEET_NC_HEIGHT);
Graphics g = image.createGraphics();
mySheetPanel.paint(g);
g.dispose();
myOffScreenFrame.dispose();
return image;
}
示例4: getSubImage
import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入方法依赖的package包/类
/**
* Returns a new BufferedImage that represents a subregion of the given
* BufferedImage. (Note that this method does not use
* BufferedImage.getSubimage(), which will defeat image acceleration
* strategies on later JDKs.)
*/
private BufferedImage getSubImage(BufferedImage img,
int x, int y, int w, int h) {
BufferedImage ret = GraphicsUtilities.createCompatibleTranslucentImage(w, h);
Graphics2D g2 = ret.createGraphics();
try {
g2.drawImage(img,
0, 0, w, h,
x, y, x+w, y+h,
null);
} finally {
g2.dispose();
}
return ret;
}
示例5: getStaticImage
import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入方法依赖的package包/类
/**
* This method is used to show an image during message showing
* @return image to show
*/
Image getStaticImage() {
final JFrame myOffScreenFrame = new JFrame() ;
myOffScreenFrame.add(mySheetPanel);
myOffScreenFrame.getRootPane().setDefaultButton(myDefaultButton);
final BufferedImage image = (SystemInfo.isJavaVersionAtLeast("1.7")) ?
UIUtil.createImage(SHEET_NC_WIDTH, SHEET_NC_HEIGHT, BufferedImage.TYPE_INT_ARGB) :
GraphicsUtilities.createCompatibleTranslucentImage(SHEET_NC_WIDTH, SHEET_NC_HEIGHT);
Graphics g = image.createGraphics();
mySheetPanel.paint(g);
g.dispose();
myOffScreenFrame.remove(mySheetPanel);
myOffScreenFrame.dispose();
return image;
}
示例6: matchLabelBorderToButtons
import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入方法依赖的package包/类
private void matchLabelBorderToButtons() {
Insets insets = new Insets(4, 6, 4, 6);
Dimension buttonSize = prevButton.getPreferredSize();
prevButton.setSize(buttonSize);
BufferedImage image = GraphicsUtilities.
createCompatibleTranslucentImage(
buttonSize.width, buttonSize.height);
prevButton.paint(image.getGraphics());
BufferedImage labelTopImage = GraphicsUtilities.
createCompatibleTranslucentImage(
buttonSize.width - insets.left - insets.right,
insets.top);
labelTopImage.getGraphics().drawImage(image, 0, 0,
buttonSize.width - insets.left - insets.right,
insets.top,
insets.left, 0,
buttonSize.width - insets.right, insets.top,
null,
null);
BufferedImage labelBottomImage = GraphicsUtilities.createCompatibleTranslucentImage(buttonSize.width - insets.left - insets.right,
insets.bottom);
labelBottomImage.getGraphics().drawImage(image, 0, 0,
buttonSize.width - insets.left - insets.right, insets.top,
insets.left, buttonSize.height - insets.bottom,
buttonSize.width - insets.right, buttonSize.height,
null,
null);
statusLabel.setBorder(new CenterLabelBorder(labelTopImage, labelBottomImage));
needLabelBorder = false;
}
示例7: initShadowImage
import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入方法依赖的package包/类
private void initShadowImage() {
final BufferedImage mySheetStencil = GraphicsUtilities.createCompatibleTranslucentImage(SHEET_WIDTH, SHEET_HEIGHT);
Graphics2D g2 = mySheetStencil.createGraphics();
g2.setColor(new JBColor(Gray._255, Gray._0));
g2.fillRect(0, 0, SHEET_WIDTH, SHEET_HEIGHT);
g2.dispose();
ShadowRenderer renderer = new ShadowRenderer();
renderer.setSize(SHADOW_BORDER);
renderer.setOpacity(.80f);
renderer.setColor(new JBColor(JBColor.BLACK, Gray._10));
myShadowImage = renderer.createShadow(mySheetStencil);
}
示例8: paint
import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入方法依赖的package包/类
/**
* @inheritDoc
*/
public final void paint(Graphics2D g, T obj, int width, int height) {
if (g == null) {
throw new NullPointerException("The Graphics2D must be supplied");
}
if (!isVisible() || width < 1 || height < 1) {
return;
}
configureGraphics(g);
//paint to a temporary image if I'm caching, or if there are filters to apply
if (shouldUseCache() || filters.length > 0) {
validate(obj);
BufferedImage cache = cachedImage == null ? null : cachedImage.get();
boolean invalidCache = null == cache ||
cache.getWidth() != width ||
cache.getHeight() != height;
if (cacheCleared || invalidCache || isDirty()) {
//rebuild the cacheable. I do this both if a cacheable is needed, and if any
//filters exist. I only *save* the resulting image if caching is turned on
if (invalidCache) {
cache = GraphicsUtilities.createCompatibleTranslucentImage(width, height);
}
Graphics2D gfx = cache.createGraphics();
try {
gfx.setClip(0, 0, width, height);
if (!invalidCache) {
// If we are doing a repaint, but we didn't have to
// recreate the image, we need to clear it back
// to a fully transparent background.
Composite composite = gfx.getComposite();
gfx.setComposite(AlphaComposite.Clear);
gfx.fillRect(0, 0, width, height);
gfx.setComposite(composite);
}
configureGraphics(gfx);
doPaint(gfx, obj, width, height);
} finally {
gfx.dispose();
}
for (BufferedImageOp f : getFilters()) {
cache = f.filter(cache, null);
}
//only save the temporary image as the cacheable if I'm caching
if (shouldUseCache()) {
cachedImage = new SoftReference<BufferedImage>(cache);
cacheCleared = false;
}
}
g.drawImage(cache, 0, 0, null);
} else {
//can't use the cacheable, so just paint
doPaint(g, obj, width, height);
}
//painting has occured, so restore the dirty bit to false
setDirty(false);
}
示例9: paint
import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入方法依赖的package包/类
/**
* @inheritDoc
*/
public final void paint(Graphics2D g, T obj, int width, int height) {
if (g == null) {
throw new NullPointerException("The Graphics2D must be supplied");
}
if(!isVisible() || width < 1 || height < 1) {
return;
}
configureGraphics(g);
//paint to a temporary image if I'm caching, or if there are filters to apply
if (shouldUseCache() || filters.length > 0) {
validate(obj);
BufferedImage cache = cachedImage == null ? null : cachedImage.get();
boolean invalidCache = null == cache ||
cache.getWidth() != width ||
cache.getHeight() != height;
if (cacheCleared || invalidCache || isDirty()) {
//rebuild the cacheable. I do this both if a cacheable is needed, and if any
//filters exist. I only *save* the resulting image if caching is turned on
if (invalidCache) {
cache = GraphicsUtilities.createCompatibleTranslucentImage(width, height);
}
Graphics2D gfx = cache.createGraphics();
try {
gfx.setClip(0, 0, width, height);
if (!invalidCache) {
// If we are doing a repaint, but we didn't have to
// recreate the image, we need to clear it back
// to a fully transparent background.
Composite composite = gfx.getComposite();
gfx.setComposite(AlphaComposite.Clear);
gfx.fillRect(0, 0, width, height);
gfx.setComposite(composite);
}
configureGraphics(gfx);
doPaint(gfx, obj, width, height);
} finally {
gfx.dispose();
}
for (BufferedImageOp f : getFilters()) {
cache = f.filter(cache, null);
}
//only save the temporary image as the cacheable if I'm caching
if (shouldUseCache()) {
cachedImage = new SoftReference<BufferedImage>(cache);
cacheCleared = false;
}
}
g.drawImage(cache, 0, 0, null);
} else {
//can't use the cacheable, so just paint
doPaint(g, obj, width, height);
}
//painting has occured, so restore the dirty bit to false
setDirty(false);
}