Mercurial > dwindows
diff android/DWindows.kt @ 2529:060fdb2d807d
Android: Initial pixmap implmentation using Android Bitmap.
Clean up some clang-tidy warnings reported by Android Studio.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 10 May 2021 20:06:50 +0000 |
parents | 03f6870bcfcc |
children | b9923432cb1f |
line wrap: on
line diff
--- a/android/DWindows.kt Mon May 10 09:29:51 2021 +0000 +++ b/android/DWindows.kt Mon May 10 20:06:50 2021 +0000 @@ -1737,6 +1737,39 @@ } } + fun pixmapNew(width: Int, height: Int, filename: String?, data: ByteArray?, length: Int, resID: Int): Bitmap? + { + var pixmap: Bitmap? = null + + waitOnUiThread { + if(width > 0 && height > 0) { + pixmap = Bitmap.createBitmap(null, width, height, Bitmap.Config.ARGB_8888) + } else if(resID != 0) { + pixmap = BitmapFactory.decodeResource(resources, resID); + } else if(filename != null) { + // Try to load the image, and protect against exceptions + try { + val f = File(filename) + pixmap = BitmapFactory.decodeStream(FileInputStream(f)) + } catch (e: FileNotFoundException) { + } + } else if(data != null) { + pixmap = BitmapFactory.decodeByteArray(data, 0, length) + } + } + return pixmap + } + + fun pixmapGetDimensions(pixmap: Bitmap): Long + { + var dimensions: Long = 0 + + waitOnUiThread { + dimensions = pixmap.width.toLong() or (pixmap.height.toLong() shl 32) + } + return dimensions + } + fun timerConnect(interval: Long, sigfunc: Long, data: Long): Timer { // creating timer task, timer