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


Scala ImageIO类代码示例

本文整理汇总了Scala中javax.imageio.ImageIO的典型用法代码示例。如果您正苦于以下问题:Scala ImageIO类的具体用法?Scala ImageIO怎么用?Scala ImageIO使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ImageIO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1:

//设置package包名称以及导入依赖的类
package app

import javax.imageio.ImageIO

trait Settings {
  this: com.jme3.app.SimpleApplication =>

  protected val appSettings = new com.jme3.system.AppSettings(true)

  Seq(
    ("Width", 1920)
    , ("Height", 1080)
    , ("BitsPerPixel", 32)
    , ("Frequency", 60)
    , ("DepthBits", 24)
    , ("StencilBits", 0)
    , ("Samples", 2)
    , ("Fullscreen", false)
    , ("Title", "LW3D")
    , ("Renderer", com.jme3.system.AppSettings.LWJGL_OPENGL2)
    , ("AudioRenderer", com.jme3.system.AppSettings.LWJGL_OPENAL)
    , ("DisableJoysticks", true)
    , ("UseInput", true)
    , ("VSync", false)
    , ("FrameRate", 0)
    , ("SettingsDialogImage", "")
    , ("MinHeight", 1920)
    , ("MinWidth", 1080)
  ) foreach { case (k, v: Object) => appSettings.put(k, v) }

  appSettings.setIcons(
    List(
      ImageIO.read(getClass.getClassLoader.getResource("Yx/logo/Y256.png")),
      ImageIO.read(getClass.getClassLoader.getResource("Yx/logo/Y128.png")),
      ImageIO.read(getClass.getClassLoader.getResource("Yx/logo/Y64.png")),
      ImageIO.read(getClass.getClassLoader.getResource("Yx/logo/Y32.png")),
      ImageIO.read(getClass.getClassLoader.getResource("Yx/logo/Y16.png"))
    ).toArray
  )

  setSettings(appSettings)

  setShowSettings(false)
  setDisplayFps(true)
  setDisplayStatView(false)
  setPauseOnLostFocus(false)
} 
开发者ID:Y-Experiment,项目名称:LW3D,代码行数:48,代码来源:Settings.scala

示例2: Barcoder

//设置package包名称以及导入依赖的类
package kokellab.utils.misc

import java.io.{FileOutputStream, OutputStream, FileInputStream}
import java.nio.file.Path
import javax.imageio.ImageIO

import com.google.zxing.client.j2se.{MatrixToImageWriter, BufferedImageLuminanceSource}
import com.google.zxing.common.HybridBinarizer
import com.google.zxing.BinaryBitmap
import com.google.zxing._

class Barcoder(val barcodeFormat: BarcodeFormat, val imageFormat: String, val width: Int, val height: Int) {

	def decode(path: Path): String = {
		val stream = new FileInputStream(path.toFile)
		try {
			decode(stream)
		} finally stream.close()
	}

	def decode(stream: java.io.InputStream): String = {
		val bitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(stream))))
		new MultiFormatReader().decode(bitmap).getText
	}

	def encode(text: String, path: Path) {
		encode(text, new FileOutputStream(path.toFile))
	}

	def encode(text: String, stream: OutputStream) = {
		val matrix = new MultiFormatWriter().encode(text, barcodeFormat, width, height, null)
		MatrixToImageWriter.writeToStream(matrix, imageFormat, stream)
	}

} 
开发者ID:kokellab,项目名称:kl-common-scala,代码行数:36,代码来源:Barcoder.scala

示例3: OpenCVOps

//设置package包名称以及导入依赖的类
package com.dataoptimo.imgprocessing
import org.opencv.core.Mat
import javax.imageio.ImageIO
import java.io.ByteArrayInputStream
import java.awt.image.DataBufferByte
import org.opencv.core.CvType
import org.opencv.core.Core
import org.opencv.features2d.FeatureDetector
import org.opencv.core.MatOfKeyPoint
import org.opencv.features2d.Features2d
import org.opencv.highgui.Highgui
import java.awt.image.BufferedImage
import java.io.File



object OpenCVOps {
  
  System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
  
  def imageToMat(byteArray: Array[Byte]): MatSer ={
      val bufferedImage = ImageIO.read(new ByteArrayInputStream(byteArray))
      val mat = new Mat(bufferedImage.getHeight(), bufferedImage.getWidth(), CvType.CV_8UC3);
      val data = bufferedImage.getRaster().getDataBuffer.asInstanceOf[DataBufferByte].getData();
      mat.put(0, 0, data);
      new MatSer(mat);
  }
  
  def matToImage(mat: Mat,file: String): Boolean ={
    
      val imageType = BufferedImage.TYPE_3BYTE_BGR;
      val image = new BufferedImage(mat.cols(),mat.rows(), imageType);
      val x = image.getRaster.getDataBuffer.asInstanceOf[DataBufferByte].getData
      mat.get(0,0,x)
      val fileName = new File("file")
      ImageIO.write(image, "jpg", fileName)
    
  }
  
  def detectFeatures(mat: Mat)
  {
    val featureDetector = FeatureDetector.create(FeatureDetector.SIFT)
    val matKeyPoint = new MatOfKeyPoint()
    featureDetector.detect(mat,matKeyPoint)
    println(mat.get(0, 0))
    println(matKeyPoint.toList())
    //writeToImage(mat,matKeyPoint)
    
  }
  
  def writeToImage(mat: Mat, matKeyPoint: MatOfKeyPoint){
    val outImage = new Mat()
    Features2d.drawKeypoints(mat, matKeyPoint, outImage)
    Highgui.imwrite("myfile.jpg",outImage)
    
  }
  
} 
开发者ID:mfawadalam,项目名称:imgprocessing,代码行数:59,代码来源:OpenCVOps.scala

示例4: MnistRawData

//设置package包名称以及导入依赖的类
package woshilaiceshide.nnadl.mnist

import woshilaiceshide.nnadl._
import woshilaiceshide.nnadl.math._
import woshilaiceshide.nnadl.util.Utility._
import woshilaiceshide.nnadl.util.ArrayUtility._

import java.io._

final case class MnistRawData(images: Array[Matrix], labels: Array[Int]) {
  private[nnadl] def split(howmany: Int) = {
    val (i0, i1) = images.cut_at_point(howmany)
    val (l0, l1) = labels.cut_at_point(howmany)
    (MnistRawData(i0, l0), MnistRawData(i1, l1))
  }
}
final case class MnistRawDataSet(training_data: MnistRawData, validation_data: MnistRawData, test_data: MnistRawData)

final case class MnistRecord(image: Matrix, label: Int) {
  def save() = {

    import java.awt.Point
    import java.awt.image._
    import javax.imageio.ImageIO
    val reshaped = image.reshape(28, 28)
    val pixels = reshaped.toArray()
    val (w, h) = reshaped.dim
    val raster = Raster.createWritableRaster(new PixelInterleavedSampleModel(0, w, h, 1, 1920, Array(0)), new Point(0, 0))

    for (i <- w.range; j <- h.range) { raster.setSample(i, j, 0, pixels(i)(j)) }
    val jimage = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_GRAY);
    jimage.setData(raster)
    val output = new File(label + "." + System.currentTimeMillis() + ".jpg")
    ImageIO.write(jimage, "jpg", output)
  }
}

object MnistRecord {

  def apply(nrecord: NRecord) = {
    new MnistRecord(nrecord.x, nrecord.y.column(0).find(1))
  }

}

final case class MnistDataSet(training_data: Array[NRecord], validation_data: Array[NRecord], test_data: Array[NRecord]) 
开发者ID:woshilaiceshide,项目名称:s-nnadl,代码行数:47,代码来源:api.scala

示例5: BrainfuckToKappaLang

//设置package包名称以及导入依赖的类
package com.lthummus.kappalang

import java.awt.image.BufferedImage
import java.io.File
import javax.imageio.ImageIO

import com.lthummus.kappalang.translator.EmoteTranslator._


object BrainfuckToKappaLang extends App {

  val bfCode = scala.io.Source.fromFile(args(0)).getLines.mkString
  val widthTokens = args(1).toInt
  val heightTokens = args(2).toInt

  val dir = args(3)
  val out = args(4)

  val SymbolMap = Map(
    '-' -> ImageIO.read(new File(dir + "BibleThump.png")),
    ']' -> ImageIO.read(new File(dir + "twitchraid.png")),
    '.' -> ImageIO.read(new File(dir + "KAPOW.png")),
    '[' -> ImageIO.read(new File(dir + "riPepperonis.png")),
    ',' -> ImageIO.read(new File(dir + "NotLikeThis.png")),
    '+' -> ImageIO.read(new File(dir + "Kappa.png")),
    '<' -> ImageIO.read(new File(dir + "RitzMitz.png")),
    '>' -> ImageIO.read(new File(dir + "FrankerZ.png"))
  )

  val NopFile = ImageIO.read(new File(dir + "nop.png"))

  if (heightTokens * widthTokens != bfCode.length) {
    println("Can't build that with the given dimensions")
    println("Dimensions given: " + widthTokens + "x" + heightTokens)
    println("Code length: " + bfCode.length)
  }

  val tokenCords = for {
    y <- 0 until heightTokens
    x <- 0 until widthTokens
  } yield (x * TokenWidth, y * TokenHeight)

  val symbols = bfCode.map(SymbolMap.getOrElse(_, NopFile))

  val image = new BufferedImage(widthTokens * TokenWidth,
    heightTokens * TokenHeight,
    BufferedImage.TYPE_INT_RGB)

  val graphics = image.getGraphics


  for (x <- tokenCords zip symbols) {
    graphics.drawImage(x._2, x._1._1, x._1._2, null)
  }

  ImageIO.write(image, "png", new File(out))

} 
开发者ID:LtHummus,项目名称:KappaLang,代码行数:59,代码来源:BrainfuckToKappaLang.scala

示例6: TwitterTagCloud

//设置package包名称以及导入依赖的类
package ttc

import ttc.TStreamer._
import ttc.TagCloud._

import scala.collection.JavaConverters._
import java.io.File
import javax.imageio.ImageIO


object TwitterTagCloud {

  def main(args: Array[String]) = {
    val tstreamer = new TStreamer(1)
    tstreamer.stream()

    sys.ShutdownHookThread {
      tstreamer.close()
    }

    var count = 0
    while (true) {
      try {
        Thread sleep 60000
      } catch {
        case e: InterruptedException => println("gotcha")
      }

      var wc = tstreamer.getWordCount().asScala.toMap.mapValues(_.toInt)
      if (!wc.isEmpty) {
        ImageIO.write(tagCloud(wordsWithSizes(mostCommonWords(10)(wc))),
          "png", new File(s"$count.png"))
        count = count + 1
      }
    }
  }

} 
开发者ID:leohaskell,项目名称:twitter-tag-cloud,代码行数:39,代码来源:main.scala

示例7: Util

//设置package包名称以及导入依赖的类
package org.sparksamples

import java.awt.image.BufferedImage


object Util {
  def loadImageFromFile(path: String): BufferedImage = {
    import javax.imageio.ImageIO
    import java.io.File
    ImageIO.read(new File(path))
  }

  def processImage(image: BufferedImage, width: Int, height: Int): BufferedImage = {
    val bwImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY)
    val g = bwImage.getGraphics()
    g.drawImage(image, 0, 0, width, height, null)
    g.dispose()
    bwImage
  }

  def getPixelsFromImage(image: BufferedImage): Array[Double] = {
    val width = image.getWidth
    val height = image.getHeight
    val pixels = Array.ofDim[Double](width * height)
    image.getData.getPixels(0, 0, width, height, pixels)
    // pixels.map(p => p / 255.0) 		// optionally scale to [0, 1] domain
  }

  def extractPixels(path: String, width: Int, height: Int): Array[Double] = {
    val raw = loadImageFromFile(path)
    val processed = processImage(raw, width, height)
    getPixelsFromImage(processed)
  }


} 
开发者ID:PacktPublishing,项目名称:Machine-Learning-with-Spark-Second-Edition,代码行数:37,代码来源:Util.scala

示例8: Test

//设置package包名称以及导入依赖的类
import java.awt.Color
import java.awt.image.BufferedImage
import java.io.File
import javax.imageio.ImageIO


object Test {
  def main(args: Array[String]) {
    val image=new BufferedImage(400,400,BufferedImage.TYPE_4BYTE_ABGR)
    val graphics=image.createGraphics()
    graphics.setColor(Color.red)
    graphics.drawArc(-50,-50,100,100,0,360)
    graphics.setColor(Color.blue)
    graphics.fillArc(-50,-50,100,100,0,360)
    ImageIO.write(image,"jpg",new File("/home/yuan/workspace/IdeaProjects/ParallelizeHeatmap/source/p.jpg"))
  }
} 
开发者ID:yuanzhaokang,项目名称:ParallelizeHeatmap,代码行数:18,代码来源:Test.scala

示例9: ImageUtils

//设置package包名称以及导入依赖的类
import java.awt.image.BufferedImage
import java.io.{ByteArrayInputStream, ByteArrayOutputStream}
import javax.imageio.ImageIO

import org.apache.commons.io.IOUtils
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.{FileSystem, Path}


object ImageUtils {

  def readImage(hdfsPath: String): BufferedImage = {
    val configuration = new Configuration()
    configuration.addResource(new Path(Path.localConfPath + "/core-site.xml"))
    configuration.addResource(new Path(Path.localConfPath + "/hadoop/hdfs-site.xml"))
    configuration.addResource(new Path(Path.localConfPath + "/hadoop/yarn-site.xml"))
    val fs = FileSystem.get(configuration)
    val is = fs.open(new Path(hdfsPath))
    val buffer = IOUtils.toByteArray(is)
    val out = new ByteArrayOutputStream()
    out.write(buffer, 0, buffer.length)
    val b = out.toByteArray
    out.close()
    val picture = ImageIO.read(new ByteArrayInputStream(b))
    is.close()
    picture
  }

  def writeImage(image: BufferedImage, hdfsPath: String): Unit = {
    val configuration = new Configuration()
    configuration.addResource(new Path(Path.localConfPath + "/core-site.xml"))
    configuration.addResource(new Path(Path.localConfPath + "/hdfs-site.xml"))
    configuration.addResource(new Path(Path.localConfPath + "/yarn-site.xml"))
    val fs = FileSystem.get(configuration)
    val os = fs.create(new Path(hdfsPath))
    val baos = new ByteArrayOutputStream()
    val ios = ImageIO.createImageOutputStream(baos)
    ImageIO.write(image, "png", ios)
    val is = new ByteArrayInputStream(baos.toByteArray)
    IOUtils.copy(is, os)

    is.close()
    ios.close()
    baos.close()
    os.close()
  }
} 
开发者ID:yuanzhaokang,项目名称:ParallelizeHeatmap,代码行数:48,代码来源:ImageUtils.scala

示例10: Pi

//设置package包名称以及导入依赖的类
package com.loopfor.pi

import java.awt.{AlphaComposite, Color, Font, RenderingHints}
import java.awt.image.BufferedImage
import java.io.File
import javax.imageio.ImageIO
import scala.io.Source

object Pi {
  private val Rows = 500
  private val Cols = 2000
  private val Watermark = "?"

  def main(args: Array[String]): Unit = {
    val lines = Source.fromFile("pi-formatted.txt").getLines

    // Calculate width and height of single row of digits.
    val font = new Font("Source Code Pro", Font.PLAIN, 10)
    var gr = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB).createGraphics()
    val (width, height) = try {
      gr.setFont(font)
      val metrics = gr.getFontMetrics
      (metrics.stringWidth("0" * Cols), metrics.getHeight * Rows)
    } finally
      gr.dispose()

    val image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB)

    // Render all digits.
    gr = image.createGraphics()
    gr.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY)
    gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
    gr.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY)
    gr.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE)
    gr.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON)
    gr.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR)
    gr.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY)
    gr.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE)
    gr.setFont(font)
    gr.setColor(Color.BLACK)
    lines.foldLeft(0) { (r, line) =>
      gr.drawString(line, 0, (r + 1) * gr.getFontMetrics.getAscent)
      r + 1
    }

    // Render the Pi symbol overlay.
    gr.setFont(new Font("Symbol", Font.PLAIN, 6000))
    gr.setColor(Color.BLUE)
    gr.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.8F))
    val bounds = gr.getFontMetrics.getStringBounds(Watermark, gr)
    val x = (width - bounds.getWidth) / 2
    val y = -bounds.getY - (height - bounds.getHeight) / 2
    gr.drawString(Watermark, x.toInt, y.toInt)
    gr.dispose()

    ImageIO.write(image, "PNG", new File("pi-poster.png"))
  }
} 
开发者ID:davidledwards,项目名称:huge-pi,代码行数:59,代码来源:Pi.scala

示例11: ExampleBox

//设置package包名称以及导入依赖的类
package kaloffl.rtrender

import java.io.File
import javax.imageio.ImageIO

object ExampleBox {

  def main(args: Array[String]): Unit = {
    val width = 1280
    val height = 720
    val texture = ImageIO.read(new File("res/test.png"))

    new Engine(
      texture = new Texture(
        buffer = texture.getRGB(0, 0, texture.getWidth, texture.getHeight, null, 0, texture.getWidth),
        width = texture.getWidth,
        height = texture.getHeight),
      window = new JfxDisplay(width, height),
      initial_player = Player(
        Viewpoint(
          position = Vec3(20, -7, 0),
          forward = Vec3(0, 0, 1)),
        velocity = Vec3(0, 0, 0)),
      rasterizer = new Rasterizer(
        width = width,
        height = height,
        vertices = Array(
          Vec3(-10, -10, -10), Vec3(-10, -10,  10),
          Vec3(-10,  10, -10), Vec3(-10,  10,  10),
          Vec3( 10, -10, -10), Vec3( 10, -10,  10),
          Vec3( 10,  10, -10), Vec3( 10,  10,  10)),
        vert_indices = Array(
          6, 7, 2, 3, 2, 7,
          2, 3, 0, 1, 0, 3,
          7, 6, 5, 4, 5, 6,
          4, 6, 0, 2, 0, 6,
          3, 7, 1, 5, 1, 7,
          4, 0, 5, 1, 5, 0),
        texcoords = Array(
          Vec2(0, 0), Vec2(0, 1), Vec2(1, 0), Vec2(1, 1), Vec2(1, 0), Vec2(0, 1)),
        texcoord_indices = Array(
          0, 1, 2, 3, 4, 5,
          0, 1, 2, 3, 4, 5,
          0, 1, 2, 3, 4, 5,
          0, 1, 2, 3, 4, 5,
          0, 1, 2, 3, 4, 5,
          0, 1, 2, 3, 4, 5),
        normals = Array(
          Vec3(1, 0, 0), Vec3(-1, 0, 0), Vec3(0, 1, 0), Vec3(0, -1, 0), Vec3(0, 0, 1), Vec3(0, 0, -1)),
        norm_indices = Array(
          2, 2, 2, 2, 2, 2,
          1, 1, 1, 1, 1, 1,
          0, 0, 0, 0, 0, 0,
          5, 5, 5, 5, 5, 5,
          4, 4, 4, 4, 4, 4,
          3, 3, 3, 3, 3, 3)
        )).run()
  }
} 
开发者ID:Kaloffl,项目名称:rasterizer,代码行数:60,代码来源:ExampleBox.scala

示例12: ExampleDragon

//设置package包名称以及导入依赖的类
package kaloffl.rtrender

import java.io.File
import javax.imageio.ImageIO

object ExampleDragon {

  def main(args: Array[String]): Unit = {
    val width = 1280
    val height = 720

    val (vertices, vert_indices, normals, norm_indices, texcoords, texcoord_indices) = ObjImporter.load("res/dragon.obj")

    val texture = ImageIO.read(new File("res/dragon.png"))
    val tex_width = texture.getWidth
    val tex_height = texture.getHeight
    val tex_buffer = texture.getRGB(0, 0, tex_width, tex_height, null, 0, tex_width)

    new Engine(
      texture = new Texture(
        buffer = tex_buffer,
        width = tex_width,
        height = tex_height),
      window = new JfxDisplay(width, height),
      initial_player = Player(
        Viewpoint(
          position = Vec3(5, 1, 5),
          forward = Vec3(0, 0, 1)),
        velocity = Vec3(0, 0, 0)),
      rasterizer = new Rasterizer(
        width = width,
        height = height,
        vertices = vertices,
        vert_indices = vert_indices,
        texcoords = texcoords,
        texcoord_indices = texcoord_indices,
        normals = normals,
        norm_indices = norm_indices
      )).run()
  }
} 
开发者ID:Kaloffl,项目名称:rasterizer,代码行数:42,代码来源:ExampleDragon.scala

示例13: MainWindow

//设置package包名称以及导入依赖的类
package fi.kajstrom.efpscala.E49

import java.net.URL
import javax.swing.ImageIcon

import scala.swing._

class MainWindow(imageService: ImageService) extends MainFrame{
  title = "Photo Search"
  preferredSize = new Dimension(640, 480)
  contents = new BoxPanel(Orientation.Horizontal) {
    val text = new TextField()
    text.maximumSize = new Dimension(150, 30)
    contents += text
    contents += Button("Search") {
      val images = imageService.findWithTag(text.text)
      println(images)
      showImages(images)
    }
  }

  def showImages(images: List[Image]): Unit = {
    import javax.imageio.ImageIO
    import java.awt.image.BufferedImage


    contents = new BoxPanel(Orientation.Vertical) {
      images.take(1).foreach((image: Image) => {
        val url = new URL(images.head.url)
        val img: BufferedImage = ImageIO.read(url)

        val label = new Label {
          icon = new ImageIcon(img)
        }

        contents += label
      })
    }
  }
} 
开发者ID:kajstrom,项目名称:EFP-Scala,代码行数:41,代码来源:MainWindow.scala

示例14: SlidingAnimation

//设置package包名称以及导入依赖的类
package gui.animations

import java.awt.AlphaComposite
import java.awt.Graphics2D
import java.awt.image.BufferedImage
import java.io.File
import javax.imageio.ImageIO

import game_mechanics.path.Waypoint
import runtime.{TowerDefense,Controller}
import gui._
import utils.Continuable



object SlidingAnimation
{
    val background = ImageIO.read(
        new File(
            getClass().getResource("/UI/Button_Dark.png").getPath()))
    val image_origin_x : Int = background.getWidth() / 2
    val image_origin_y : Int = background.getHeight() / 2
}

class SlidingAnimation(text_callback : () => String) extends Animatable
{
    import SlidingAnimation._

    val duration = 5.0
    timer = duration

    val origin = new Waypoint( -image_origin_x.toDouble, TowerDefense.map_panel.size.height / 2 )
    val target = origin + new Waypoint( TowerDefense.map_panel.size.width + image_origin_x.toDouble, 0 )

    override def draw(g: Graphics2D): Unit = {
        val interp = Math.pow( timer * 2 / duration - 1, 5 ) / 2 + 0.5
        val pos = origin * interp + target * ( 1 - interp )
        val string = text_callback()
        val strwidth = g.getFontMetrics().stringWidth( string )
        g.drawImage( background,
            pos.x.toInt - image_origin_x,
            pos.y.toInt - image_origin_y,
            null )
        g.setColor( Colors.white )
        g.drawString( string,
            pos.x.toFloat - strwidth.toFloat / 2,
            pos.y.toFloat )
    }
}

class WaveAnimation(wave_number : Int)
extends SlidingAnimation( () => "Wave " + wave_number.toString ) 
开发者ID:bunny-defense,项目名称:bunny_defense,代码行数:53,代码来源:slidinganimation.scala

示例15: SpreadAnimation

//设置package包名称以及导入依赖的类
package gui.animations

import java.awt.Graphics2D
import java.awt.image.BufferedImage
import java.io.File
import javax.imageio.ImageIO

import game_mechanics.path.Waypoint
import runtime.{TowerDefense,Controller}
import gui._
import utils.Continuable

object SpreadAnimation
{
    val background = ImageIO.read(
        new File(
            getClass().getResource("/projectiles/potato-image.png").getPath()))
}

class SpreadAnimation(pos: Waypoint, radius_init: Int, dir: Waypoint) extends Animatable {
    import SpreadAnimation._
    val origin = pos.toInt * MapPanel.cellsize
    val radius = radius_init * MapPanel.cellsize
    val duration = 0.5
    timer = duration
    val target = (pos +  dir * radius_init).toInt * MapPanel.cellsize


    override def draw(g: Graphics2D): Unit = {
        val interp = Math.pow(timer / duration, 1.0/5.0)
        val pos = origin * interp +  target * (1 - interp )
        g.drawImage(background,
            pos.x.toInt,
            pos.y.toInt,
            null )
    }
} 
开发者ID:bunny-defense,项目名称:bunny_defense,代码行数:38,代码来源:spreadanimation.scala


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