Практически все режимы наложения, которые я пробовал, не работают должным образом.Ниже приведены некоторые из них.Имейте в виду, что dst = зеленый, src = красный.
NO BLEND
DST, DST_IN(этот результат подходит для DST, но не для DST_IN)
SRC (плохой результат)
My View:
import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.view.View
class MyView(context: Context?, attrs: AttributeSet?) : View(context, attrs) {
val blendPaint = Paint()
val simplePaint = Paint()
init {
blendPaint.xfermode = PorterDuffXfermode(PorterDuff.Mode.DST_IN)
blendPaint.color = Color.argb(255,255,0,0)
simplePaint.color = Color.argb(255,0,255,0)
}
override fun onDraw(canvas: Canvas?) {
super.onDraw(canvas)
canvas!!.drawRect(Rect(0, 0, 400, 400), simplePaint)
canvas.drawRect(Rect(200, 200, 600, 600), blendPaint)
}
private fun mutableBitmap(resId: Int): Bitmap {
val immutable = BitmapFactory.decodeResource(this.resources, resId)
return immutable.copy(Bitmap.Config.ARGB_8888, true)
}
}
My layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<com.example.scrp01.com.example.scrp01.MyView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
Это недавно созданный проект, никаких изменений в AndroidManifest вообще нет,работает на API 26 Android 8.0, CPU x86.Android Studio версии 3.3.2
Вы можете посмотреть, какие будут подходящие результаты здесь: https://developer.android.com/reference/android/graphics/BlendMode.html#SRC