File tree 1 file changed +9
-8
lines changed
spra-web/src/main/scala/net/wiringbits/spra/ui/web/utils
1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -24,16 +24,17 @@ object Images {
24
24
}
25
25
26
26
def convertHexToImage (imageHex : String ): String = {
27
- // Remove the "0x" prefix from the hex string, as it's not part of the actual image data
27
+ // Check if the argument is a hexadecimal string"
28
+ if (! imageHex.startsWith(" \\ x" ) || (imageHex.length % 2 ) == 1 ) {
29
+ throw new IllegalArgumentException (s " Error: Expected a hexadecimal string but found: $imageHex" )
30
+ }
31
+ // Remove the "\x" prefix from the hex string, as it's not part of the actual image data
28
32
val hex = imageHex.tail.tail
29
33
val imageBinary : Array [Byte ] =
30
- if ((hex.length % 2 ) == 1 )
31
- Array .empty
32
- else
33
- Try (hex.grouped(2 ).map { hex => Integer .parseInt(hex, 16 ).toByte }.toArray) match {
34
- case Success (value) => value
35
- case Failure (_) => Array .empty
36
- }
34
+ Try (hex.grouped(2 ).map { hex => Integer .parseInt(hex, 16 ).toByte }.toArray) match {
35
+ case Success (value) => value
36
+ case Failure (_) => Array .empty
37
+ }
37
38
val byteArray = Uint8Array (js.Array (imageBinary.map(_.toShort): _* ))
38
39
dom.URL .createObjectURL(dom.Blob (js.Array (byteArray.buffer)))
39
40
}
You can’t perform that action at this time.
0 commit comments