当前位置: 首页>>代码示例>>Scala>>正文


Scala Image类代码示例

本文整理汇总了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
  }
} 
开发者ID:endymecy,项目名称:dl4scala,代码行数:48,代码来源:MNISTVisualizer.scala

示例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)
  }
} 
开发者ID:rwalks,项目名称:ecosim,代码行数:60,代码来源:UnitArt.scala

示例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;
  }
} 
开发者ID:NicoLutz,项目名称:ScalaRisk,代码行数:20,代码来源:Scale.scala


注:本文中的java.awt.Image类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。