本文整理匯總了Java中java.awt.image.RescaleOp類的典型用法代碼示例。如果您正苦於以下問題:Java RescaleOp類的具體用法?Java RescaleOp怎麽用?Java RescaleOp使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RescaleOp類屬於java.awt.image包,在下文中一共展示了RescaleOp類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: fadeImage
import java.awt.image.RescaleOp; //導入依賴的package包/類
/**
* Create a faded version of an image.
*
* @param img The {@code Image} to fade.
* @param fade The amount of fading.
* @param target The offset.
* @return The faded image.
*/
public static BufferedImage fadeImage(Image img, float fade, float target) {
int w = img.getWidth(null);
int h = img.getHeight(null);
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bi.createGraphics();
g.drawImage(img, 0, 0, null);
float offset = target * (1.0f - fade);
float[] scales = { fade, fade, fade, 1.0f };
float[] offsets = { offset, offset, offset, 0.0f };
RescaleOp rop = new RescaleOp(scales, offsets, null);
g.drawImage(bi, rop, 0, 0);
g.dispose();
return bi;
}
示例2: runTest
import java.awt.image.RescaleOp; //導入依賴的package包/類
private void runTest(int sType, int dType, int expect) {
BufferedImage src = new BufferedImage(w, h, sType);
BufferedImage dst = new BufferedImage(w, h, dType);
String msg = getMsgText(sType, dType);
Graphics2D g2d = src.createGraphics();
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, w, h);
RescaleOp res = new RescaleOp(scaleFactor, offset, null);
res.filter(src, dst);
if (saveImage) {
try {
String fname = getFileName(sType, dType);
ImageIO.write(dst, "png", new File(fname));
} catch (IOException e) {
}
}
check(dst, expect, msg);
}
示例3: getIcon
import java.awt.image.RescaleOp; //導入依賴的package包/類
@Override
protected Icon getIcon ()
{
// TODO Use that to get the state (-> highlight or not)
TransitionAwareUI transitionAwareUI = (TransitionAwareUI) slider.getUI();
StateTransitionTracker stateTransitionTracker = transitionAwareUI.getTransitionTracker();
// stateTransitionTracker.getModelStateInfo().getCurrModelState();
final Icon icon = super.getIcon();
final BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
final Graphics iconGraphics = image.createGraphics();
icon.paintIcon(slider, iconGraphics, 0, 0);
// Make it brighter (very simple approach)
final RescaleOp rescaleOp = new RescaleOp(2.0f, 50, null);
rescaleOp.filter(image, image);
ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
op.filter(image, image);
return new ImageIcon(image);
}
示例4: toSVG
import java.awt.image.RescaleOp; //導入依賴的package包/類
/**
* @param op BufferedImageOp to be converted to SVG
* @param filterRect Rectangle, in device space, that defines the area
* to which filtering applies. May be null, meaning that the
* area is undefined.
* @return an SVGFilterDescriptor representing the SVG filter
* equivalent of the input BufferedImageOp
*/
public SVGFilterDescriptor toSVG(BufferedImageOp op,
Rectangle filterRect){
SVGFilterDescriptor filterDesc =
svgCustomBufferedImageOp.toSVG(op, filterRect);
if(filterDesc == null){
if(op instanceof LookupOp)
filterDesc = svgLookupOp.toSVG(op, filterRect);
else if(op instanceof RescaleOp)
filterDesc = svgRescaleOp.toSVG(op, filterRect);
else if(op instanceof ConvolveOp)
filterDesc = svgConvolveOp.toSVG(op, filterRect);
}
return filterDesc;
}
示例5: paintImage
import java.awt.image.RescaleOp; //導入依賴的package包/類
protected void paintImage(Graphics2D graphics, Image image, Rectangle bounds, Color tint) {
if (tint == null || tint.equals(Color.white)) {
paintImage(graphics, image, bounds);
}
else {
BufferedImage graphicsBuffer = new BufferedImage(Math.abs(bounds.width), Math.abs(bounds.height), BufferedImage.TYPE_INT_ARGB);
paintImage(graphicsBuffer.createGraphics(), image, new Rectangle(0, 0, bounds.width, bounds.height));
float[] scaleFactors = new float[4];
float[] offsets = new float[4];
scaleFactors[0] = tint.getRed() / 255f;
scaleFactors[1] = tint.getGreen() / 255f;
scaleFactors[2] = tint.getBlue() / 255f;
scaleFactors[3] = tint.getAlpha() / 255f;
// we must use another image, otherwise the tint isn't applied correctly (check the Sporepedia button transparency in the editor)
BufferedImage img = new BufferedImage(Math.abs(bounds.width), Math.abs(bounds.height), BufferedImage.TYPE_INT_ARGB);
img.createGraphics().drawImage(graphicsBuffer, new RescaleOp(scaleFactors, offsets, null), 0, 0);
graphics.drawImage(img, bounds.x, bounds.y, null);
}
}
示例6: drawTintedImage
import java.awt.image.RescaleOp; //導入依賴的package包/類
public static BufferedImage drawTintedImage(BufferedImage image, Dimension dim, int[] uvCoordinates, Color tint) {
BufferedImage temp = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = temp.createGraphics();
Image.drawImage(g, image,
0, 0, dim.width, dim.height,
uvCoordinates[0], uvCoordinates[1], uvCoordinates[2], uvCoordinates[3]);
float[] scaleFactors = new float[4];
float[] offsets = new float[4];
scaleFactors[0] = tint.getRed() / 255f;
scaleFactors[1] = tint.getGreen() / 255f;
scaleFactors[2] = tint.getBlue() / 255f;
scaleFactors[3] = tint.getAlpha() / 255f;
BufferedImage img = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB);
img.createGraphics().drawImage(temp, new RescaleOp(scaleFactors, offsets, null), 0, 0);
return img;
}
示例7: sBrillo_stateChanged
import java.awt.image.RescaleOp; //導入依賴的package包/類
/**
*
* @param e Evento
*/
public void sBrillo_stateChanged(ChangeEvent e) {
//Comprobamos que se ha cargado una imagen
if (this.imagenAbierta) {
RescaleOp rop = new RescaleOp(1.0f,
(float) this.sBrillo.getValue(), null);
BufferedImage aux = new BufferedImage(this.imagenSinModificar.getWidth(),
this.imagenSinModificar.getHeight(),
this.imagenSinModificar.getType());
//Aplicamos el filtro de brillo a la imagen transformada por los filtros
rop.filter(this.imagenTransformada, aux);
//Establecemos la nueva imagen a mostrar
this.PanelTapiz.setImagen(aux);
//Ponemos que se ha modificado la imagen
this.modificado = true;
}
}
示例8: preparePlaceholder
import java.awt.image.RescaleOp; //導入依賴的package包/類
/**
* Prepare a version of the place holder Sprite, that is suitable for the
* transparency mode of the client.
*
* @param original original placeholder Sprite
* @return an adjusted Sprite, or the original if no adjusting is needed
*/
private Sprite preparePlaceholder(Sprite original) {
if ((original == null) || (TransparencyMode.TRANSPARENCY == Transparency.BITMASK)) {
return original;
}
/*
* Using full alpha in the client.
*
* Create a black and white, but translucent version of the same image.
* The filtering has been chosen so that the slot images we use become
* suitably B&W, not for any general rule.
*
* What we'd really want is drawing an opaque B&W image in soft light
* mode, but swing back buffer does not actually support Composites
* despite being accessed via Graphics2D.
*/
BufferedImage img = new BufferedImage(original.getWidth(), original.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics g = img.createGraphics();
original.draw(g, 0, 0);
RescaleOp rescaleOp = new RescaleOp(new float[] {3.0f, 3.0f, 3.0f, 0.5f }, new float[] {-450f, -450f, -450f, 0f}, null);
rescaleOp.filter(img, img);
g.dispose();
return new ImageSprite(img);
}
示例9: drawMovingPlayer
import java.awt.image.RescaleOp; //導入依賴的package包/類
public void drawMovingPlayer(Graphics2D g) {
if(getGameCanvas().getMovingPlayer() != null) {
AffineTransform transform = new AffineTransform();
double tx = getGameCanvas().getStoredMousePosition()[0] / getT(),
ty = getGameCanvas().getStoredMousePosition()[1] / getT();
BufferedImage sprite;
if(isLeft()) sprite = getGameCanvas().getMovingPlayer().getSpriteR();
else sprite = getGameCanvas().getMovingPlayer().getSpriteL();
if(sprite == null) sprite = new BufferedImage(100, 200, BufferedImage.TYPE_INT_ARGB);
transform.scale(getT(), getT());
transform.translate(tx, ty);
double rotation = -(getGameCanvas().getGameFrame().getOldMousePositions().get(0)[0]-getGameCanvas().getGameFrame().getOldMousePositions().get(1)[0]) / getPW();
if(rotation > GameFrame.MAX_DRAG_ROTATION) rotation = GameFrame.MAX_DRAG_ROTATION;
else if(rotation < -GameFrame.MAX_DRAG_ROTATION) rotation = -GameFrame.MAX_DRAG_ROTATION;
transform.rotate(rotation);
g.transform(transform);
g.drawImage(sprite, new RescaleOp(new float[]{0.8f, 0.8f, 0.8f, 0.6f}, new float[4], null), -ResourceManager.IMAGE_WIDTH / 2, 0);
try { g.transform(transform.createInverse()); }
catch (NoninvertibleTransformException ignored) {}
}
}
示例10: filterImage
import java.awt.image.RescaleOp; //導入依賴的package包/類
private BufferedImage filterImage(BufferedImage original, int hash, RescaleOp op) {
HashMap<Integer, BufferedImage> imageMap = imageFilterBuffer.get(hash);
float[] scaleFactors = op.getScaleFactors(null);
int opHash = (int) (10*scaleFactors[0]+100*scaleFactors[1]+1000*scaleFactors[2]+10000*scaleFactors[3]);
if(imageMap != null) {
if(imageMap.size() > MAX_IMAGE_BUFFER_SIZE) emptyImageBuffer(); // empty image buffer of this image if it is too full.
else if(imageMap.containsKey(opHash)) return imageMap.get(opHash); // return the buffered resized image if it was resized before.
}
BufferedImage filtered = gameCanvas.getGraphicsConfiguration().createCompatibleImage(original.getWidth(), original.getHeight(), Transparency.BITMASK);
Graphics2D filteredG = filtered.createGraphics();
filteredG.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
filteredG.drawImage(original, op, 0, 0);
filteredG.dispose();
if(imageMap != null) imageMap.put(opHash, filtered);
else {
imageMap = new HashMap<Integer, BufferedImage>();
imageMap.put(opHash, filtered);
imageFilterBuffer.put(hash, imageMap);
}
return filtered;
}
示例11: getStyledImage
import java.awt.image.RescaleOp; //導入依賴的package包/類
public static BufferedImage getStyledImage(File img, float brightness, float transparency, int size) {
BufferedImage outputImage = null;
try {
BufferedImage readBufferedImage = ImageIO.read(img);
BufferedImage inputBufferedImage = convertToArgb(readBufferedImage);
outputImage = inputBufferedImage;
if (size > 0) {
outputImage = Scalr.resize(inputBufferedImage
, Method.BALANCED
, size
, size);
}
float brightnessFactor = 1.0f + brightness/100.0f;
float transparencyFactor = Math.abs(transparency/100.0f - 1.0f);
RescaleOp rescale = new RescaleOp(
new float[]{brightnessFactor, brightnessFactor, brightnessFactor, transparencyFactor},
new float[]{0f, 0f, 0f, 0f}, null);
rescale.filter(outputImage, outputImage);
} catch (Exception e) {
e.printStackTrace();
}
return outputImage;
}
示例12: getStyledImage
import java.awt.image.RescaleOp; //導入依賴的package包/類
private BufferedImage getStyledImage(float brightness, float transparency, int size) {
BufferedImage outputImage = null;
try {
BufferedImage readBufferedImage = ImageIO.read(new File(imageFilePath));
BufferedImage inputBufferedImage = convertToArgb(readBufferedImage);
outputImage = inputBufferedImage;
if (size > 0) {
outputImage = Scalr.resize(inputBufferedImage
, Method.BALANCED
, size
, size);
}
float brightnessFactor = 1.0f + brightness/100.0f;
float transparencyFactor = Math.abs(transparency/100.0f - 1.0f);
RescaleOp rescale = new RescaleOp(
new float[]{brightnessFactor, brightnessFactor, brightnessFactor, transparencyFactor},
new float[]{0f, 0f, 0f, 0f}, null);
rescale.filter(outputImage, outputImage);
} catch (Exception e) {
e.printStackTrace();
}
return outputImage;
}
示例13: menuRescaleOpActionPerformed
import java.awt.image.RescaleOp; //導入依賴的package包/類
private void menuRescaleOpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuRescaleOpActionPerformed
VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame());
if (vi != null) {
BufferedImage imgSource = vi.getLienzo().getImageOriginal();
if (imgSource != null) {
try {
RescaleOp rop = new RescaleOp(1.0F, 100.0F, null);
BufferedImage imgdest = rop.filter(convertImageType(imgSource, BufferedImage.TYPE_INT_RGB), null);
vi.getLienzo().setImageOriginal(imgdest);
vi.getLienzo().repaint();
} catch (IllegalArgumentException e) {
System.err.println(e.getLocalizedMessage());
}
}
}
}
示例14: menuRescaleOpActionPerformed
import java.awt.image.RescaleOp; //導入依賴的package包/類
private void menuRescaleOpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuRescaleOpActionPerformed
VentanaInternaImagen vi = (VentanaInternaImagen) selectInternalWindows();
if (vi != null) {
BufferedImage imgSource = vi.getLienzo().getImageOriginal();
if (imgSource != null) {
try {
RescaleOp rop = new RescaleOp(1.0F, 100.0F, null);
BufferedImage imgdest = rop.filter(convertImageType(imgSource, BufferedImage.TYPE_INT_RGB), null);
vi.getLienzo().setImageOriginal(imgdest);
vi.getLienzo().repaint();
} catch (IllegalArgumentException e) {
System.err.println(e.getLocalizedMessage());
}
}
}
}
示例15: menuRescaleOpActionPerformed
import java.awt.image.RescaleOp; //導入依賴的package包/類
private void menuRescaleOpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuRescaleOpActionPerformed
VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame());
if (vi != null) {
BufferedImage imgSource = vi.getLienzo().getImageOriginal();
if (imgSource != null) {
try {
RescaleOp rop = new RescaleOp(1.0F, 100.0F, null);
BufferedImage imgdest = rop.filter(imgSource, null);
vi.getLienzo().setImageOriginal(imgdest);
vi.getLienzo().repaint();
} catch (IllegalArgumentException e) {
System.err.println(e.getLocalizedMessage());
}
}
}
}