Skip to content

Instantly share code, notes, and snippets.

@pyeongho
Created March 13, 2020 01:47
Show Gist options
  • Save pyeongho/ae31ee6bca03a044c39e28de7ca0aeaf to your computer and use it in GitHub Desktop.
Save pyeongho/ae31ee6bca03a044c39e28de7ca0aeaf to your computer and use it in GitHub Desktop.
val width = bitmap.width
val height = bitmap.height
var R: Int
var G: Int
var B: Int
var pixel: Int
var i = 62
var bit = 7
for (x in height-1 downTo 0) { // 위아래 반전을 제거 하기 위해서 63부터 역순,
for (y in 0 until width) {
pixel = bitmap.getPixel(y, x)
R = Color.red(pixel)
G = Color.green(pixel)
B = Color.blue(pixel)
val gray = R+G+B/3
if(gray > 128){
arrayOfByte[i] = arrayOfByte[i] or (1 shl bit).toByte()
}
if(bit ==0){ // 알아보기 쉽게, 엔디안 처리
i++
bit = 8
}
bit--
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment