本文整理汇总了Java中java.awt.image.AffineTransformOp.TYPE_NEAREST_NEIGHBOR属性的典型用法代码示例。如果您正苦于以下问题:Java AffineTransformOp.TYPE_NEAREST_NEIGHBOR属性的具体用法?Java AffineTransformOp.TYPE_NEAREST_NEIGHBOR怎么用?Java AffineTransformOp.TYPE_NEAREST_NEIGHBOR使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.awt.image.AffineTransformOp
的用法示例。
在下文中一共展示了AffineTransformOp.TYPE_NEAREST_NEIGHBOR属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
@Override
public BufferedImage run(final @NonNull BufferedImage image) {
if (isFlippedHorizontally || isFlippedVertically) {
final double scaleX = isFlippedHorizontally ? -1 : 1;
final double scaleY = isFlippedVertically ? -1 : 1;
final double translateX = isFlippedHorizontally ? -image.getWidth() : 0;
final double translateY = isFlippedVertically ? -image.getHeight() : 0;
final AffineTransform tx = AffineTransform.getScaleInstance(scaleX, scaleY);
tx.translate(translateX, translateY);
final BufferedImageOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
return op.filter(image, null);
}
return image;
}
示例2: isSimpleTranslate
public static boolean isSimpleTranslate(SunGraphics2D sg) {
int ts = sg.transformState;
if (ts <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) {
// Integer translates are always "simple"
return true;
}
if (ts >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
// Scales and beyond are always "not simple"
return false;
}
// non-integer translates are only simple when not interpolating
if (sg.interpolationType == AffineTransformOp.TYPE_NEAREST_NEIGHBOR) {
return true;
}
return false;
}
示例3: addShadow
/**
* Adds a shadow effect by executing the following steps: 1. Transform visible
* pixels to a semi-transparent black 2. Flip the image vertically 3. Scale it
* down 4. Render original image and shadow on a buffered image
*
* @param image
* the image
* @param xOffset
* the x offset
* @param yOffset
* the y offset
* @return the buffered image
*/
public static BufferedImage addShadow(final BufferedImage image, final int xOffset, final int yOffset) {
if (image == null) {
return image;
}
// Transform visible pixels to a semi-transparent black
final BufferedImage shadowImage = flashVisiblePixels(image, new Color(0, 0, 0, 30));
if (shadowImage == null) {
return image;
}
final AffineTransform tx = new AffineTransform();
// Flip the image vertically
tx.concatenate(AffineTransform.getScaleInstance(1, -0.15));
tx.concatenate(AffineTransform.getTranslateInstance(0, -shadowImage.getHeight()));
final AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
final BufferedImage rotatedImage = op.filter(shadowImage, null);
final BufferedImage shadow = getCompatibleImage(image.getWidth(), image.getHeight() + rotatedImage.getHeight());
final Graphics2D g2D = shadow.createGraphics();
g2D.drawImage(rotatedImage, xOffset, yOffset, null);
g2D.drawImage(image, 0, 0, null);
g2D.dispose();
return shadow;
}
示例4: draw
/**
* Legacy method for drawing 8x8 tiles
* @param g
* @param x
* @param y
* @param scale
*/
public void draw(Graphics g, int x, int y, int scale) {
BufferedImage tileimg = getImage();
BufferedImage scaledimg = new BufferedImage(
tileimg.getWidth() * scale, tileimg.getHeight() * scale, BufferedImage.TYPE_INT_ARGB);
AffineTransform at = new AffineTransform();
at.scale(scale, scale);
AffineTransformOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
op.filter(tileimg, scaledimg);
g.drawImage(scaledimg, x, y, null);
}
示例5: run
@Override
public void run() {
BufferedImage img = new BufferedImage(display.getWidth(), display.getHeight(), BufferedImage.TYPE_INT_RGB);
for (int y = 0; y < display.getHeight(); y++) {
for (int x = 0; x < display.getWidth(); x++) {
int idx = getIndex(x, y);
int nIdx = 3 * idx;
int r = ((int) (rgbValues[nIdx++] * 255)); // red component 0...255
int g = ((int) (rgbValues[nIdx++] * 255)); // green component 0...255
int b = ((int) (rgbValues[nIdx] * 255)); // blue component 0...255
int col = (r << 16) | (g << 8) | b;
img.setRGB(x, y, col);
}
}
AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
tx.translate(0, -img.getHeight(null));
AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
img = op.filter(img, null);
SimpleDateFormat sdfDate = new SimpleDateFormat("_yyyy_MM_dd_HH_mm_ss");//dd/MM/yyyy
Date now = new Date();
String strDate = sdfDate.format(now);
try {
ImageIO.write(img, "png", new File(String.format("%s/ImageCreator%s.png", path, strDate)));
} catch (IOException ex) {
log.warning("can not save Image, Error: " + ex.toString());
}
}
示例6: run
@Override
public void run() {
BufferedImage img = new BufferedImage(display.getWidth(), display.getHeight(), BufferedImage.TYPE_INT_RGB);
for (int y = 0; y < display.getHeight(); y++) {
for (int x = 0; x < display.getWidth(); x++) {
int idx = getIndex(x, y);
int nIdx = 3 * idx;
int r = ((int) (rgbValues[nIdx++] * 255)); // red component 0...255
int g = ((int) (rgbValues[nIdx++] * 255)); // green component 0...255
int b = ((int) (rgbValues[nIdx] * 255)); // blue component 0...255
int col = (r << 16) | (g << 8) | b;
img.setRGB(x, y, col);
}
}
AffineTransform tx = AffineTransform.getScaleInstance(1, -1); //alligns the image correctly
tx.translate(0, -img.getHeight(null));
AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
img = op.filter(img, null);
SimpleDateFormat sdfDate = new SimpleDateFormat("_yyyy_MM_dd_HH_mm_ss");//dd/MM/yyyy
Date now = new Date();
String strDate = sdfDate.format(now);
try {
ImageIO.write(img, "png", new File(String.format("%s/ImageCreator%s.png", path, strDate)));
} catch (IOException ex) {
log.warning("can not save Image, Error: " + ex.toString());
}
}
示例7: setRenderingHints
/**
* Sets the preferences for the rendering algorithms.
* Hint categories include controls for rendering quality and
* overall time/quality trade-off in the rendering process.
* @param hints The rendering hints to be set
* @see RenderingHints
*/
public void setRenderingHints(Map<?,?> hints) {
this.hints = null;
renderHint = SunHints.INTVAL_RENDER_DEFAULT;
antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF;
textAntialiasHint = SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT;
fractionalMetricsHint = SunHints.INTVAL_FRACTIONALMETRICS_OFF;
lcdTextContrast = lcdTextContrastDefaultValue;
interpolationHint = -1;
interpolationType = AffineTransformOp.TYPE_NEAREST_NEIGHBOR;
boolean customHintPresent = false;
Iterator<?> iter = hints.keySet().iterator();
while (iter.hasNext()) {
Object key = iter.next();
if (key == SunHints.KEY_RENDERING ||
key == SunHints.KEY_ANTIALIASING ||
key == SunHints.KEY_TEXT_ANTIALIASING ||
key == SunHints.KEY_FRACTIONALMETRICS ||
key == SunHints.KEY_TEXT_ANTIALIAS_LCD_CONTRAST ||
key == SunHints.KEY_STROKE_CONTROL ||
key == SunHints.KEY_INTERPOLATION)
{
setRenderingHint((Key) key, hints.get(key));
} else {
customHintPresent = true;
}
}
if (customHintPresent) {
this.hints = makeHints(hints);
}
invalidatePipe();
}
示例8: SunGraphics2D
public SunGraphics2D(SurfaceData sd, Color fg, Color bg, Font f) {
surfaceData = sd;
foregroundColor = fg;
backgroundColor = bg;
transform = new AffineTransform();
stroke = defaultStroke;
composite = defaultComposite;
paint = foregroundColor;
imageComp = CompositeType.SrcOverNoEa;
renderHint = SunHints.INTVAL_RENDER_DEFAULT;
antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF;
textAntialiasHint = SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT;
fractionalMetricsHint = SunHints.INTVAL_FRACTIONALMETRICS_OFF;
lcdTextContrast = lcdTextContrastDefaultValue;
interpolationHint = -1;
strokeHint = SunHints.INTVAL_STROKE_DEFAULT;
resolutionVariantHint = SunHints.INTVAL_RESOLUTION_VARIANT_DEFAULT;
interpolationType = AffineTransformOp.TYPE_NEAREST_NEIGHBOR;
validateColor();
devScale = sd.getDefaultScale();
if (devScale != 1) {
transform.setToScale(devScale, devScale);
invalidateTransform();
}
font = f;
if (font == null) {
font = defaultFont;
}
setDevClip(sd.getBounds());
invalidatePipe();
}
示例9: renderImageXform
@Override
protected void renderImageXform(SunGraphics2D sg, Image img,
AffineTransform tx, int interpType,
int sx1, int sy1, int sx2, int sy2,
Color bgColor)
{
// punt to the MediaLib-based transformImage() in the superclass if:
// - bicubic interpolation is specified
// - a background color is specified and will be used
// - the source surface is neither a texture nor render-to-texture
// surface, and a non-default interpolation hint is specified
// (we can only control the filtering for texture->surface
// copies)
// REMIND: we should tweak the sw->texture->surface
// transform case to handle filtering appropriately
// (see 4841762)...
// - an appropriate TransformBlit primitive could not be found
if (interpType != AffineTransformOp.TYPE_BICUBIC) {
SurfaceData dstData = sg.surfaceData;
SurfaceData srcData =
dstData.getSourceSurfaceData(img,
SunGraphics2D.TRANSFORM_GENERIC,
sg.imageComp,
bgColor);
if (srcData != null &&
!isBgOperation(srcData, bgColor) &&
(srcData.getSurfaceType() == OGLSurfaceData.OpenGLTexture ||
srcData.getSurfaceType() == OGLSurfaceData.OpenGLSurfaceRTT ||
interpType == AffineTransformOp.TYPE_NEAREST_NEIGHBOR))
{
SurfaceType srcType = srcData.getSurfaceType();
SurfaceType dstType = dstData.getSurfaceType();
TransformBlit blit = TransformBlit.getFromCache(srcType,
sg.imageComp,
dstType);
if (blit != null) {
blit.Transform(srcData, dstData,
sg.composite, sg.getCompClip(),
tx, interpType,
sx1, sy1, 0, 0, sx2-sx1, sy2-sy1);
return;
}
}
}
super.renderImageXform(sg, img, tx, interpType,
sx1, sy1, sx2, sy2, bgColor);
}
示例10: draw
/**
* Draw layers to a Graphics context
* @param g The context to which the layers will be drawn
* @param scale The amount by which the image should be scaled up
* @param mask Which layers to draw
* @param enableAB Use GBA-style alhpa blending
*/
public void draw(Graphics g, int scale, int mask, boolean enableAB) {
BufferedImage canvas = new BufferedImage((width << 4) * scale, (height << 4) * scale,
BufferedImage.TYPE_INT_ARGB);
// Draw the layers in the appropriate order
for(int i : drawOrder()) {
// Only draw layers enabled by caller's mask
if(((mask >> i) & 1) == 1 && layerProperties[i] != 0) {
// Render the layer
BufferedImage layerimg = getRenderedLayer(i);
// Scale the layer graphics
BufferedImage scaledimg = new BufferedImage(
layerimg.getWidth() * scale, layerimg.getHeight() * scale, BufferedImage.TYPE_INT_ARGB);
AffineTransform at = new AffineTransform();
at.scale(scale, scale);
AffineTransformOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
op.filter(layerimg, scaledimg);
// Apply alpha to layer 0 if enabled
if(i == 0 && enableAB && alphaBlendingLevel < 1) {
for(int j = 0; j < scaledimg.getHeight(); ++j) {
for(int k = 0; k < scaledimg.getWidth(); ++k) {
int composite = scaledimg.getRGB(k, j);
// Only modify alpha of opaque values
if((composite & 0xFF000000) != 0) {
int target = canvas.getRGB(k, j);
int dr = Math.min(248, (target & 0xFF) +
(int) ((composite & 0xFF) * alphaBlendingLevel));
int dg = Math.min(248, ((target >> 8) & 0xFF) +
(int) (((composite >> 8) & 0xFF) * alphaBlendingLevel));
int db = Math.min(248, ((target >> 16) & 0xFF) +
(int) (((composite >> 16) & 0xFF) * alphaBlendingLevel));
canvas.setRGB(k, j, dr | (dg << 8) | (db << 16) | 0xFF000000);
}
}
}
} else {
Graphics cg = canvas.getGraphics();
cg.drawImage(scaledimg, 0, 0, null);
cg.dispose();
}
}
}
g.drawImage(canvas, 0, 0, null);
}
示例11: tryCopyOrScale
protected boolean tryCopyOrScale(SunGraphics2D sg,
Image img,
int sx1, int sy1,
int sx2, int sy2,
Color bgColor, int interpType,
double coords[])
{
double dx1 = coords[0];
double dy1 = coords[1];
double dx2 = coords[2];
double dy2 = coords[3];
double dw = dx2 - dx1;
double dh = dy2 - dy1;
/* If any of the destination coordinates exceed the integer range,
* then the calculations performed in calls made here cannot be
* guaranteed to be correct, or to converge (terminate).
* So return out of here, deferring to code that can handle this.
*/
if (dx1 < Integer.MIN_VALUE || dx1 > Integer.MAX_VALUE ||
dy1 < Integer.MIN_VALUE || dy1 > Integer.MAX_VALUE ||
dx2 < Integer.MIN_VALUE || dx2 > Integer.MAX_VALUE ||
dy2 < Integer.MIN_VALUE || dy2 > Integer.MAX_VALUE)
{
return false;
}
// First check if width and height are very close to img w&h.
if (closeToInteger(sx2-sx1, dw) && closeToInteger(sy2-sy1, dh)) {
// Round location to nearest pixel and then test
// if it will cause interpolation anomalies.
int idx = (int) Math.floor(dx1 + 0.5);
int idy = (int) Math.floor(dy1 + 0.5);
if (interpType == AffineTransformOp.TYPE_NEAREST_NEIGHBOR ||
(closeToInteger(idx, dx1) && closeToInteger(idy, dy1)))
{
renderImageCopy(sg, img, bgColor,
idx, idy,
sx1, sy1, sx2-sx1, sy2-sy1);
return true;
}
}
// (For now) We can only use our ScaledBlits if the image
// is upright (i.e. dw & dh both > 0)
if (dw > 0 && dh > 0) {
if (renderImageScale(sg, img, bgColor, interpType,
sx1, sy1, sx2, sy2,
dx1, dy1, dx2, dy2))
{
return true;
}
}
return false;
}
示例12: setTexturePaint
/**
* We use OpenGL's texture coordinate generator to automatically
* map the TexturePaint image to the geometry being rendered. The
* generator uses two separate plane equations that take the (x,y)
* location (in device space) of the fragment being rendered to
* calculate (u,v) texture coordinates for that fragment:
* u = Ax + By + Cz + Dw
* v = Ex + Fy + Gz + Hw
*
* Since we use a 2D orthographic projection, we can assume that z=0
* and w=1 for any fragment. So we need to calculate appropriate
* values for the plane equation constants (A,B,D) and (E,F,H) such
* that {u,v}=0 for the top-left of the TexturePaint's anchor
* rectangle and {u,v}=1 for the bottom-right of the anchor rectangle.
* We can easily make the texture image repeat for {u,v} values
* outside the range [0,1] by specifying the GL_REPEAT texture wrap
* mode.
*
* Calculating the plane equation constants is surprisingly simple.
* We can think of it as an inverse matrix operation that takes
* device space coordinates and transforms them into user space
* coordinates that correspond to a location relative to the anchor
* rectangle. First, we translate and scale the current user space
* transform by applying the anchor rectangle bounds. We then take
* the inverse of this affine transform. The rows of the resulting
* inverse matrix correlate nicely to the plane equation constants
* we were seeking.
*/
private static void setTexturePaint(RenderQueue rq,
SunGraphics2D sg2d,
TexturePaint paint,
boolean useMask)
{
BufferedImage bi = paint.getImage();
SurfaceData dstData = sg2d.surfaceData;
SurfaceData srcData =
dstData.getSourceSurfaceData(bi, SunGraphics2D.TRANSFORM_ISIDENT,
CompositeType.SrcOver, null);
boolean filter =
(sg2d.interpolationType !=
AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
// calculate plane equation constants
AffineTransform at = (AffineTransform)sg2d.transform.clone();
Rectangle2D anchor = paint.getAnchorRect();
at.translate(anchor.getX(), anchor.getY());
at.scale(anchor.getWidth(), anchor.getHeight());
double xp0, xp1, xp3, yp0, yp1, yp3;
try {
at.invert();
xp0 = at.getScaleX();
xp1 = at.getShearX();
xp3 = at.getTranslateX();
yp0 = at.getShearY();
yp1 = at.getScaleY();
yp3 = at.getTranslateY();
} catch (java.awt.geom.NoninvertibleTransformException e) {
xp0 = xp1 = xp3 = yp0 = yp1 = yp3 = 0.0;
}
// assert rq.lock.isHeldByCurrentThread();
rq.ensureCapacityAndAlignment(68, 12);
RenderBuffer buf = rq.getBuffer();
buf.putInt(SET_TEXTURE_PAINT);
buf.putInt(useMask ? 1 : 0);
buf.putInt(filter ? 1 : 0);
buf.putLong(srcData.getNativeOps());
buf.putDouble(xp0).putDouble(xp1).putDouble(xp3);
buf.putDouble(yp0).putDouble(yp1).putDouble(yp3);
}