16進数文字列から画像に変換する方法(Kotlin)
https://so-wh.at/entry/20041012/p1
上記のページを参考にしました。もしかしたら他の方が書いているかもしれませんが自分用メモとして。
前提として、画像を16進文字列に変換したテキストファイルをアセットに保管してあります。
fun hextoBitmap(file: String): Bitmap {
val openfile = assets.open(file)
var imagetext = ""
try {
val inst = InputStreamReader(openfile)
val br = BufferedReader(inst)
var line = br.readLine()
while (line != null) {
imagetext += line
line = br.readLine()
}
inst.close()
br.close()
}catch (e:IOException) {
Log.e("IOException", e.toString())
}
val bytes = mutableListOf<Byte>()
for(index in 1..imagetext.length/2) {
val byte = Integer.parseInt(imagetext.substring((index - 1) * 2,index * 2),16)
bytes.add(byte.toByte())
}
println(bytes)
val byteArray = bytes.toByteArray()
val bitmap = BitmapFactory.decodeByteArray(bytearray, 0, byteArray.size)
return bitmap
}
Author And Source
この問題について(16進数文字列から画像に変換する方法(Kotlin)), 我々は、より多くの情報をここで見つけました https://qiita.com/a153120/items/cf174549a02102a0f36e著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .