import new texture

This commit is contained in:
Hendrik Schutter 2019-06-04 14:57:54 +02:00
parent ca2ad079d4
commit 83e4f10aaa
8 changed files with 19 additions and 11 deletions

View File

@ -2,6 +2,9 @@ package org.hso.texturesyncclient.controller
import javafx.collections.ObservableList
import org.hso.texturesyncclient.controller.net.Connection
import org.hso.texturesyncclient.model.Sha256
import org.hso.texturesyncclient.model.Texture
import org.hso.texturesyncclient.model.TextureFormat
import org.hso.texturesyncclient.view.importView.ImportViewController
import org.hso.texturesyncclient.view.mainView.MainViewController
import org.hso.texturesyncclient.view.startupView.StartupViewController
@ -10,6 +13,12 @@ import java.net.InetAddress
import java.util.Calendar
import java.io.File
import javax.imageio.ImageIO
import java.util.UUID
import java.nio.file.Files
@ -50,13 +59,20 @@ class RootController : Controller() {
* @param tags all tags for the file
*/
fun importTexture(path: String, name: String, tags: ObservableList<String>) {
val data = Files.readAllBytes(File(path).toPath()) // this is the image as byte array
val cal = Calendar.getInstance() //calendar obj with current time
val uuid = UUID.randomUUID()
val format = if (File(path).extension.toLowerCase() == "png") TextureFormat.PNG else TextureFormat.JPEG
val bimg = ImageIO.read(File(path)) //image for obtaining resolution
val resolution = Pair(bimg.height, bimg.width)
val cal = Calendar.getInstance() //calendar obj with current time
val hash = Sha256(data)
println(cal.time)
println("Height: ${bimg.getHeight()} With: ${bimg.getWidth()}")
//Todo free image
val newTexture = Texture(uuid, name, tags.toTypedArray(), format, resolution, cal, hash)
con.uploadTexture(newTexture, data)
}

View File

@ -5,9 +5,6 @@ import java.util.*
import java.security.MessageDigest
class DataModel
enum class TextureFormat {
PNG, JPEG,
}

View File

@ -12,8 +12,6 @@ class ImportViewController : Controller() {
private val rootc = find(RootController::class)
fun btnFileChooserAction() {
println("btn click")
val list = listOf("*.png", "*.PNG", "*.jpg", "*.JPG", "*.jpeg", "*.JPEG")
val arrayFilter = arrayOf(ExtensionFilter("Texturen vom Bildformat: PNG oder JPG", list))
val file = chooseFile("Textur auswählen", arrayFilter, FileChooserMode.Single, owner = null)

View File

@ -10,9 +10,6 @@ import javax.swing.JColorChooser.showDialog
import java.io.File
class MainViewController : Controller() {
private val mv = find(MainView::class)

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB