如何在 Android 编程中使用画布和滑动库从图库中选择图像以及如何将高质量(超过 6 MB)图像放在表面视图上
要从图库中选择照片,您可以使用 (
Intent.ACTION_GET_CONTENT
) 操作打开文件选择器对话框并选择一个
照片。例子:
val intent =Intent( Intent.ACTION_GET_CONTENT )
intent.type ="image/*"
startActivityForResult(Intent.createChooser(intent, "Select Picture"), REQUEST_CODE_FOR_PICK_IMAGE)
在
onActivityResult
函数中,可以获取选中的图片Uri,使用Glide库加载。示例:
Glide.with(this)
.asBitmap()
.load(imageUri)
.into(object : CustomTarget<Bitmap>() {
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
// Draw the bitmap on the SurfaceView using a Canvas
val canvas = surfaceHolder.lockCanvas()
canvas.drawBitmap(resource, 0f, 0f, null)
surfaceHolder.unlockCanvasAndPost(canvas)
}
override fun onLoadCleared(placeholder: Drawable?) {
//Called when the image is no longer available
}
})
Example中,
imageUri
是选中图片的Uri,surfaceHolder
是要在其上绘制照片的SurfaceView的SurfaceHolder。 CustomTarget 类允许您在加载照片时指定回调,并提供可以在 Canvas 上绘制的 Bitmap 对象。
这就是你要找的吗?
dataType[] arrayName = new dataType[arraySize];
int[] numbers = new int[5];
请提供更多详情