• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Image类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala ConsumerRecords类代码示例发布时间:2022-05-23
下一篇:
Scala MySQLDriver类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap