无法访问“<init>”:它在“Image”中是包私有的

问题描述 投票:0回答:1

Android studio,我想用内置方法“Image”发布一个简单的图像。编译器抛出了我在标题中发布的内容。

我尝试了不同的图像选项和 ImageView 但没有成功。我尝试更改图片的大小及其密度,但也没有帮助。我期待简单的帮助。

今天尝试了 ImageReader 并出现了同样的错误。我以为这会是依赖,但它们很好。我正在使用 @OptIn(ExperimentalFoundationApi::class) 但我认为无论如何都不重要。:(

顺便说一句。这就是我的代码,我正在尝试放大玻璃:https://www.youtube.com/watch?v=rLs-iUWtumE

import android.media.Image
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.MagnifierStyle
import androidx.compose.foundation.gestures.detectDragGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.magnifier
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.res.painterResource
import com.example.lupa.ui.theme.LupaTheme

@OptIn(ExperimentalFoundationApi::class)
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            LupaTheme {
                // A surface container using the 'background' color from the theme
                Column(
                    modifier = Modifier
                        .fillMaxSize()
                ) {
                    val image = painterResource(R.drawable.szymonnodpi)
                    var offset by remember {
                        mutableStateOf(Offset.Zero)
                    }
                    Box(
                        modifier = Modifier
                            .fillMaxWidth()
                            .pointerInput(true) {
                                detectDragGestures { change, _ ->
                                    offset = change.position
                                }
                            }
                            .magnifier(
                                sourceCenter = {
                                    offset
                                },
                                magnifierCenter = {
                                    offset - Offset(x = 0f, y = 200f)
                                },
                                style = MagnifierStyle(
                                    //size = DpSize(100.dp, 200.dp)
                                )
                            )

                    ) {
                        Image(
                            painter = image,
                            contentDiscription = null,
                            modifier = Modifier.fillMaxSize(),
                            contentScale = ContentScale.FillWidth
                        )

                    }
                }
            }
        }
    }
}

我也更改了导入导入 androidx.compose.foundation.Image & 现在它抛出其他异常:

不能使用提供的参数调用以下函数: 公共乐趣图像(位图:ImageBitmap,contentDescription:字符串?,修饰符:Modifier = ...,对齐:Alignment = ...,contentScale:ContentScale = ...,alpha:Float = ...,colorFilter:ColorFilter?= ..., filterQuality: FilterQuality = ...): androidx.compose.foundation 中定义的单位 公共乐趣图像(画家:画家,contentDescription:字符串?,修饰符:Modifier = ...,对齐:Alignment = ...,contentScale:ContentScale = ...,alpha:Float = ...,colorFilter:ColorFilter?= ...): androidx.compose.foundation 中定义的单位 公共乐趣图像(imageVector:ImageVector,contentDescription:String?,修饰符:Modifier = ...,对齐:Alignment = ...,contentScale:ContentScale = ...,alpha:Float = ...,colorFilter:ColorFilter?= ...): 在 androidx.compose.foundation 中定义的单位

https://github.com/sierzputowskisz/magnifyingGlass

android image
1个回答
0
投票

在拉出项目后,我重新创建了图像,它对我有用,在比较两者之后,我注意到

contentDescription
中的
Image
看起来有点时髦

工作代码:

Image(
    painter = image,
    contentDescription = null,
    modifier = Modifier.fillMaxSize(),
    contentScale = ContentScale.FillWidth
)
© www.soinside.com 2019 - 2024. All rights reserved.