1
0
mirror of https://github.com/tateisu/SubwayTooter synced 2025-02-04 12:47:48 +01:00

ファイルヘッダからJPEGかどうか判断する際に先頭4バイトではなく3バイトだけ確認する

This commit is contained in:
tateisu 2019-04-21 13:12:58 +09:00
parent 2d5f20a4f5
commit 84410e701a
2 changed files with 29 additions and 24 deletions

View File

@ -114,12 +114,18 @@ class ActPost : AppCompatActivity(),
}
private val imageHeaderList = arrayOf(
Pair("image/jpeg", intArrayOf(0xff, 0xd8, 0xff, 0xe0).toByteArray()),
Pair(
"image/jpeg",
intArrayOf(0xff, 0xd8, 0xff ).toByteArray()
),
Pair(
"image/png",
intArrayOf(0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A).toByteArray()
),
Pair("image/gif", charArrayOf('G', 'I', 'F').toByteArray())
Pair(
"image/gif",
charArrayOf('G', 'I', 'F').toLowerByteArray()
)
)
private fun checkImageHeaderList(contentResolver : ContentResolver, uri : Uri) : String? {
@ -2419,13 +2425,13 @@ class ActPost : AppCompatActivity(),
"friendsNico" -> 2
else -> 0
}
private fun Int?.toPollTypeString() = when(this) {
1 -> "mastodon"
2 -> "friendsNico"
else -> ""
}
private fun openDraftPicker() {
DlgDraftPicker().open(this) { draft -> restoreDraft(draft) }
@ -2580,7 +2586,6 @@ class ActPost : AppCompatActivity(),
etExpireHours.setText(draft.optString(DRAFT_POLL_EXPIRE_HOUR, ""))
etExpireMinutes.setText(draft.optString(DRAFT_POLL_EXPIRE_MINUTE, ""))
val array = draft.optJSONArray(DRAFT_ENQUETE_ITEMS)
if(array != null) {
var src_index = 0

View File

@ -77,7 +77,7 @@ fun IntArray.toByteArray() : ByteArray {
}
// 各要素の下位8ビットを使ってバイト配列を作る
fun CharArray.toByteArray() : ByteArray {
fun CharArray.toLowerByteArray() : ByteArray {
val dst = ByteArray(this.size)
for(i in 0 until this.size) {
dst[i] = this[i].toByte()