Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
deskscreen
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kowis-projects
deskscreen
Commits
d9c89fb4
Commit
d9c89fb4
authored
Apr 03, 2019
by
David
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding the method from the javafx JDK
parent
302bde05
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
0 deletions
+80
-0
src/main/kotlin/is/kow/deskscreen/utils/Util.kt
src/main/kotlin/is/kow/deskscreen/utils/Util.kt
+80
-0
No files found.
src/main/kotlin/is/kow/deskscreen/utils/Util.kt
View file @
d9c89fb4
package
`is`.kow.deskscreen.utils
import
javafx.scene.image.Image
import
javafx.scene.image.PixelFormat
import
javafx.scene.image.WritableImage
import
sun.awt.image.IntegerComponentRaster
import
java.awt.image.BufferedImage
import
java.io.InputStream
import
java.nio.file.Files
import
java.nio.file.Path
...
...
@@ -31,4 +36,79 @@ object Util {
fun
md5File
(
path
:
Path
):
String
{
return
md5Stuff
(
Files
.
newInputStream
(
path
))
}
/**
* Stolen from the JDK, because it's apparently not in the javafx on the rpi. Maybe different versions?
* Snapshots the specified [BufferedImage] and stores a copy of
* its pixels into a JavaFX [Image] object, creating a new
* object if needed.
* The returned `Image` will be a static snapshot of the state
* of the pixels in the `BufferedImage` at the time the method
* completes. Further changes to the `BufferedImage` will not
* be reflected in the `Image`.
*
*
* The optional JavaFX [WritableImage] parameter may be reused
* to store the copy of the pixels.
* A new `Image` will be created if the supplied object is null,
* is too small or of a type which the image pixels cannot be easily
* converted into.
*
* @param bimg the `BufferedImage` object to be converted
* @param wimg an optional `WritableImage` object that can be
* used to store the returned pixel data
* @return an `Image` object representing a snapshot of the
* current pixels in the `BufferedImage`.
* @since JavaFX 2.2
*/
fun
toFXImage
(
bimg
:
BufferedImage
,
wimg
:
WritableImage
?):
WritableImage
{
var
bimg
=
bimg
var
wimg
=
wimg
val
bw
=
bimg
.
width
val
bh
=
bimg
.
height
when
(
bimg
.
type
)
{
BufferedImage
.
TYPE_INT_ARGB
,
BufferedImage
.
TYPE_INT_ARGB_PRE
->
{
}
else
->
{
val
converted
=
BufferedImage
(
bw
,
bh
,
BufferedImage
.
TYPE_INT_ARGB_PRE
)
val
g2d
=
converted
.
createGraphics
()
g2d
.
drawImage
(
bimg
,
0
,
0
,
null
)
g2d
.
dispose
()
bimg
=
converted
}
}
// assert(bimg.getType == TYPE_INT_ARGB[_PRE]);
if
(
wimg
!=
null
)
{
val
iw
=
wimg
.
width
.
toInt
()
val
ih
=
wimg
.
height
.
toInt
()
if
(
iw
<
bw
||
ih
<
bh
)
{
wimg
=
null
}
else
if
(
bw
<
iw
||
bh
<
ih
)
{
val
empty
=
IntArray
(
iw
)
val
pw
=
wimg
.
pixelWriter
val
pf
=
PixelFormat
.
getIntArgbPreInstance
()
if
(
bw
<
iw
)
{
pw
.
setPixels
(
bw
,
0
,
iw
-
bw
,
bh
,
pf
,
empty
,
0
,
0
)
}
if
(
bh
<
ih
)
{
pw
.
setPixels
(
0
,
bh
,
iw
,
ih
-
bh
,
pf
,
empty
,
0
,
0
)
}
}
}
if
(
wimg
==
null
)
{
wimg
=
WritableImage
(
bw
,
bh
)
}
val
pw
=
wimg
.
pixelWriter
val
icr
=
bimg
.
raster
as
IntegerComponentRaster
val
data
=
icr
.
dataStorage
val
offset
=
icr
.
getDataOffset
(
0
)
val
scan
=
icr
.
scanlineStride
val
pf
=
if
(
bimg
.
isAlphaPremultiplied
)
PixelFormat
.
getIntArgbPreInstance
()
else
PixelFormat
.
getIntArgbInstance
()
pw
.
setPixels
(
0
,
0
,
bw
,
bh
,
pf
,
data
,
offset
,
scan
)
return
wimg
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment