Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Commit

Permalink
Sync from next
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Dec 26, 2020
1 parent 0f867ad commit e73ff3b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions korim/src/commonMain/kotlin/com/soywiz/korim/bitmap/BitmapExt.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.soywiz.korim.bitmap

import com.soywiz.korim.color.*
import com.soywiz.korma.geom.*

// -1 if dimensions do not match
fun Bitmap.matchContentsDistinctCount(that: Bitmap): Int {
Expand Down Expand Up @@ -43,3 +44,18 @@ fun <T : Bitmap> T.putWithBorder(x: Int, y: Int, bmp: T, border: Int = 1) {
this.copy(x, y + height - 1, this, x, y + height - 1 + n, rwidth, 1)
}
}

fun Bitmap.resized(out: Bitmap, scale: ScaleMode, anchor: Anchor): Bitmap {
val bmp = this
val width = out.width
val height = out.height
out.context2d(antialiased = true) {
val rect = Rectangle(0, 0, width, height).place(bmp.width.toDouble(), bmp.height.toDouble(), anchor, scale)
drawImage(bmp, rect.x, rect.y, rect.width, rect.height)
}
return out
}


fun Bitmap.resized(width: Int, height: Int, scale: ScaleMode, anchor: Anchor, native: Boolean = true): Bitmap =
resized(if (native) NativeImage(width, height) else createWithThisFormat(width, height), scale, anchor)

0 comments on commit e73ff3b

Please sign in to comment.