本文整理汇总了Java中org.jdesktop.swingx.graphics.GraphicsUtilities类的典型用法代码示例。如果您正苦于以下问题:Java GraphicsUtilities类的具体用法?Java GraphicsUtilities怎么用?Java GraphicsUtilities使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GraphicsUtilities类属于org.jdesktop.swingx.graphics包,在下文中一共展示了GraphicsUtilities类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: filter
import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public BufferedImage filter(BufferedImage src, BufferedImage dst) {
if (dst == null) {
dst = createCompatibleDestImage(src, null);
}
int width = src.getWidth();
int height = src.getHeight();
int[] pixels = new int[width * height];
GraphicsUtilities.getPixels(src, 0, 0, width, height, pixels);
mixColor(pixels);
GraphicsUtilities.setPixels(dst, 0, 0, width, height, pixels);
return dst;
}
示例3: filter
import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public BufferedImage filter(BufferedImage src, BufferedImage dst) {
int width = src.getWidth();
int height = src.getHeight();
if (dst == null) {
dst = createCompatibleDestImage(src, null);
}
int[] srcPixels = new int[width * height];
int[] dstPixels = new int[width * height];
GraphicsUtilities.getPixels(src, 0, 0, width, height, srcPixels);
// horizontal pass
blur(srcPixels, dstPixels, width, height, radius);
// vertical pass
//noinspection SuspiciousNameCombination
blur(dstPixels, srcPixels, height, width, radius);
// the result is now stored in srcPixels due to the 2nd pass
GraphicsUtilities.setPixels(dst, 0, 0, width, height, srcPixels);
return dst;
}
示例4: filter
import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public BufferedImage filter(BufferedImage src, BufferedImage dst) {
int width = src.getWidth();
int height = src.getHeight();
if (dst == null) {
dst = createCompatibleDestImage(src, null);
}
int[] srcPixels = new int[width * height];
int[] dstPixels = new int[width * height];
GraphicsUtilities.getPixels(src, 0, 0, width, height, srcPixels);
for (int i = 0; i < iterations; i++) {
// horizontal pass
FastBlurFilter.blur(srcPixels, dstPixels, width, height, radius);
// vertical pass
FastBlurFilter.blur(dstPixels, srcPixels, height, width, radius);
}
// the result is now stored in srcPixels due to the 2nd pass
GraphicsUtilities.setPixels(dst, 0, 0, width, height, srcPixels);
return dst;
}
示例5: 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);
}
示例6: 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;
}
示例7: getTransferData
import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入依赖的package包/类
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
//log.fine("doing get trans data: " + flavor);
if(flavor == DataFlavor.imageFlavor) {
return img;
}
if(flavor == DataFlavor.javaFileListFlavor) {
if(files == null) {
files = new ArrayList<File>();
File file = File.createTempFile(exportName,"."+exportFormat);
//log.fine("writing to: " + file);
ImageIO.write(GraphicsUtilities.convertToBufferedImage(img),exportFormat,file);
files.add(file);
}
//log.fine("returning: " + files);
return files;
}
return null;
}
示例8: 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;
}
示例9: filter
import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@SuppressWarnings({ "SuspiciousNameCombination" })
@Override
public BufferedImage filter(BufferedImage src, BufferedImage dst) {
int width = src.getWidth();
int height = src.getHeight();
if (dst == null) {
dst = createCompatibleDestImage(src, null);
}
int[] srcPixels = new int[width * height];
int[] dstPixels = new int[width * height];
float[] kernel = createGaussianKernel(radius);
GraphicsUtilities.getPixels(src, 0, 0, width, height, srcPixels);
// horizontal pass
blur(srcPixels, dstPixels, width, height, kernel, radius);
// vertical pass
blur(dstPixels, srcPixels, height, width, kernel, radius);
// the result is now stored in srcPixels due to the 2nd pass
GraphicsUtilities.setPixels(dst, 0, 0, width, height, srcPixels);
return dst;
}
示例10: 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;
}
示例11: 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;
}
示例12: 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);
}
示例13: doPaint
import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入依赖的package包/类
protected void doPaint(Graphics2D g, T component, int width, int height) {
RectangularShape shape = calculateShape(width, height);
switch (getStyle()) {
case BOTH:
drawBackground(g,shape,width,height);
drawBorder(g,shape,width,height);
break;
case FILLED:
drawBackground(g,shape,width,height);
break;
case OUTLINE:
drawBorder(g,shape,width,height);
break;
case NONE:
break;
}
// background
// border
// leave the clip to support masking other painters
GraphicsUtilities.mergeClip(g,shape);
/*
Area area = new Area(g.getClip());
area.intersect(new Area(shape));//new Rectangle(0,0,width,height)));
g.setClip(area);*/
//g.setClip(shape);
}
示例14: loadFromResource
import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入依赖的package包/类
protected Icon loadFromResource(String name) {
URL url = baseClass.getResource("resources/images/" + name);
if (url == null)
return null;
try {
BufferedImage image = ImageIO.read(url);
if (image.getHeight() > 30) {
image = GraphicsUtilities.createThumbnail(image, 16);
}
return new ImageIcon(image);
} catch (IOException e) {
}
return null;
}
示例15: getBufferedImage
import org.jdesktop.swingx.graphics.GraphicsUtilities; //导入依赖的package包/类
public BufferedImage getBufferedImage(Integer width, Integer height) {
if(bufferedImagesTable == null) { bufferedImagesTable = new Hashtable<>(); }
String imageSize = width+"x"+height;
if(bufferedImagesTable.containsKey(imageSize)) {
return bufferedImagesTable.get(imageSize);
} else {
//System.out.println("Nuevo caché: "+width+", "+height);
return bufferedImagesTable.put(imageSize, GraphicsUtilities.createCompatibleImage(width, height));
}
}