本文整理汇总了Scala中java.awt.Image类的典型用法代码示例。如果您正苦于以下问题:Scala Image类的具体用法?Scala Image怎么用?Scala Image使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Image类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: MNISTVisualizer
//设置package包名称以及导入依赖的类
package org.dl4scala.examples.feedforward.anomalydetection
import java.awt.{GridLayout, Image}
import java.awt.image.BufferedImage
import javax.swing.{ImageIcon, JFrame, JLabel, JPanel}
import org.nd4j.linalg.api.ndarray.INDArray
import scala.collection.mutable.ArrayBuffer
class MNISTVisualizer(imageScale: Double, digits: ArrayBuffer[INDArray], title: String, gridWidth: Int) {
def this(imageScale: Double, digits: ArrayBuffer[INDArray], title: String) = {
this(imageScale, digits, title, 5)
}
def visualize(): Unit = {
val frame = new JFrame
frame.setTitle(title)
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
val panel = new JPanel
panel.setLayout(new GridLayout(0, gridWidth))
val list = getComponents
for (image <- list) {
panel.add(image)
}
frame.add(panel)
frame.setVisible(true)
frame.pack()
}
def getComponents: ArrayBuffer[JLabel] = {
val images = new ArrayBuffer[JLabel]()
for (arr <- digits) {
val bi = new BufferedImage(28, 28, BufferedImage.TYPE_BYTE_GRAY)
for(i <- 0 until 784) {
bi.getRaster.setSample(i % 28, i / 28, 0, (255 * arr.getDouble(i)).asInstanceOf[Int])
}
val orig = new ImageIcon(bi)
val imageScaled = orig.getImage.getScaledInstance((imageScale * 28).asInstanceOf[Int],
(imageScale * 28).asInstanceOf[Int], Image.SCALE_REPLICATE)
val scaled = new ImageIcon(imageScaled)
images.append(new JLabel(scaled))
}
images
}
}
示例2: UnitArt
//设置package包名称以及导入依赖的类
package com.marqod.biosphere.art
import java.awt.image.BufferedImage
import com.marqod.biosphere.models.Entity
import com.marqod.biosphere.engine.Camera
import com.marqod.biosphere.utils.{Colors, Config, Vector2}
import java.awt.{Color, Image}
import java.io.File
import javax.imageio.ImageIO
import scala.swing.Graphics2D
abstract class UnitArt extends Art[Entity] with Config {
def drawClass(g: Graphics2D, p: Entity)
}
class FishArt extends UnitArt {
val fishSheet: BufferedImage = ImageIO.read(new File("images/fishAnim3.png"));
val fishAnim1: Image = fishSheet.getSubimage(0,0,32,32)
val fishAnim2: Image = fishSheet.getSubimage(0,32,32,32)
def drawClass(g: Graphics2D, p: Entity) = {
val topLeft = p.topLeft()
val dX = topLeft.x.toInt
val dY = topLeft.y.toInt
val img = if (p.count % 40 > 20) {
fishAnim1
} else {
fishAnim2
}
g.drawImage(img,dX,dY,p.size.x.toInt,p.size.y.toInt,null)
}
}
class SheepArt extends UnitArt {
val sheepImage: Image = ImageIO.read(new File("images/sheep2.png"));
val sheepSheet: BufferedImage = ImageIO.read(new File("images/sheepSheet1.png"));
val sheepAnim1: Image = sheepSheet.getSubimage(0,0,16,16)
val sheepAnim2: Image = sheepSheet.getSubimage(0,16,16,16)
val sheepAnim3: Image = sheepSheet.getSubimage(0,32,16,16)
def drawClass(g: Graphics2D, p: Entity) = {
val topLeft = p.topLeft()
val dX = topLeft.x
val dY = topLeft.y
val f = p.count % 60
val img = if (f < 20) {
sheepAnim1
} else if (f < 40) {
sheepAnim2
} else {
sheepAnim3
}
g.drawImage(img,dX.toInt,dY.toInt,p.size.x.toInt,p.size.y.toInt,null)
}
}
示例3: Scale
//设置package包名称以及导入依赖的类
package de.htwg.se.scala_risk.view
import java.awt.Image
import java.awt.image.BufferedImage
import java.awt.RenderingHints
object Scale {
def getScaledImage(srcImg: Image, w: Int, h: Int): BufferedImage = {
val resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
val g2 = resizedImg.createGraphics();
g2.setRenderingHint(
RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR
);
g2.drawImage(srcImg, 0, 0, w, h, null);
g2.dispose();
return resizedImg;
}
}