本文整理匯總了Java中java.awt.RenderingHints.Key方法的典型用法代碼示例。如果您正苦於以下問題:Java RenderingHints.Key方法的具體用法?Java RenderingHints.Key怎麽用?Java RenderingHints.Key使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.RenderingHints
的用法示例。
在下文中一共展示了RenderingHints.Key方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getHints
import java.awt.RenderingHints; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
static final Map getHints() {
//XXX We REALLY need to put this in a graphics utils lib
if (hintsMap == null) {
//Thanks to Phil Race for making this possible
hintsMap = (Map<RenderingHints.Key, Object>)(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints")); //NOI18N
if (hintsMap == null) {
hintsMap = new HashMap<RenderingHints.Key, Object>();
hintsMap.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
}
return hintsMap;
}
示例2: rescaleImage
import java.awt.RenderingHints; //導入方法依賴的package包/類
/**
* Rescales the displayed image to be the specified size.
*
* @param width The new width of the image.
* @param height The new height of the image.
* @param hint The scaling hint to use.
*/
@Override
protected void rescaleImage(int width, int height, int hint) {
Image master = getMasterImage();
if (master!=null) {
Map<RenderingHints.Key, Object> hints =
new HashMap<RenderingHints.Key, Object>();
switch (hint) {
default:
case Image.SCALE_AREA_AVERAGING:
case Image.SCALE_SMOOTH:
hints.put(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
hints.put(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
hints.put(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
}
bgImage = createAcceleratedImage(width, height);
Graphics2D g = bgImage.createGraphics();
g.addRenderingHints(hints);
g.drawImage(master, 0,0, width,height, null);
g.dispose();
}
else {
bgImage = null;
}
}
示例3: setAntiAliasingEnabled
import java.awt.RenderingHints; //導入方法依賴的package包/類
/**
* Sets whether anti-aliasing is enabled in this editor. This method
* fires a property change event of type {@link #ANTIALIAS_PROPERTY}.
*
* @param enabled Whether anti-aliasing is enabled.
* @see #getAntiAliasingEnabled()
*/
public void setAntiAliasingEnabled(boolean enabled) {
boolean currentlyEnabled = aaHints!=null;
if (enabled!=currentlyEnabled) {
if (enabled) {
aaHints = RSyntaxUtilities.getDesktopAntiAliasHints();
// If the desktop query method comes up empty, use the standard
// Java2D greyscale method. Note this will likely NOT be as
// nice as what would be used if the getDesktopAntiAliasHints()
// call worked.
if (aaHints==null) {
Map<RenderingHints.Key, Object> temp =
new HashMap<RenderingHints.Key, Object>();
temp.put(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
aaHints = temp;
}
}
else {
aaHints = null;
}
// We must be connected to a screen resource for our graphics
// to be non-null.
if (isDisplayable()) {
refreshFontMetrics(getGraphics2D(getGraphics()));
}
firePropertyChange(ANTIALIAS_PROPERTY, !enabled, enabled);
repaint();
}
}
示例4: setDefaultAntiAliasingState
import java.awt.RenderingHints; //導入方法依賴的package包/類
/**
* Sets anti-aliasing to whatever the user's desktop value is.
*
* @see #getAntiAliasingEnabled()
*/
private void setDefaultAntiAliasingState() {
// Most accurate technique, but not available on all OSes.
aaHints = RSyntaxUtilities.getDesktopAntiAliasHints();
if (aaHints==null) {
Map<RenderingHints.Key, Object> temp =
new HashMap<RenderingHints.Key, Object>();
// In Java 6+, you can figure out what text AA hint Swing uses for
// JComponents...
JLabel label = new JLabel();
FontMetrics fm = label.getFontMetrics(label.getFont());
Object hint = null;
//FontRenderContext frc = fm.getFontRenderContext();
//hint = fm.getAntiAliasingHint();
try {
Method m = FontMetrics.class.getMethod("getFontRenderContext");
FontRenderContext frc = (FontRenderContext)m.invoke(fm);
m = FontRenderContext.class.getMethod("getAntiAliasingHint");
hint = m.invoke(frc);
} catch (RuntimeException re) {
throw re; // FindBugs
} catch (Exception e) {
// Swallow, either Java 1.5, or running in an applet
}
// If not running Java 6+, default to AA enabled on Windows where
// the software AA is pretty fast, and default (e.g. disabled) on
// non-Windows. Note that OS X always uses AA no matter what
// rendering hints you give it, so this is a moot point there.
//System.out.println("Rendering hint: " + hint);
if (hint==null) {
String os = System.getProperty("os.name").toLowerCase();
if (os.contains("windows")) {
hint = RenderingHints.VALUE_TEXT_ANTIALIAS_ON;
}
else {
hint = RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT;
}
}
temp.put(RenderingHints.KEY_TEXT_ANTIALIASING, hint);
aaHints = temp;
}
// We must be connected to a screen resource for our graphics
// to be non-null.
if (isDisplayable()) {
refreshFontMetrics(getGraphics2D(getGraphics()));
}
repaint();
}