Cannot access '<init>': it is package-private in 'Image'

Android studio, I wanted to post a simple image with build-in method "Image". Compilator throws out something I posted in the title.

I was trying differ Image options and ImageView with no success. I tried to change size of picture and its density, didint help either. I expect simple help.

Today tried ImageReader and its this same error. I thought itll be dependecies, but they are fine. Iam using @OptIn(ExperimentalFoundationApi::class) but I think it dont matter anyway.:(

btw. thats my code Iam trying magnify glass from: 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
                        )

                    }
                }
            }
        }
    }
}

I changed Import too import androidx.compose.foundation.Image & now it throws other exception:

None of the following functions can be called with the arguments supplied: public fun Image(bitmap: ImageBitmap, contentDescription: String?, modifier: Modifier = ..., alignment: Alignment = ..., contentScale: ContentScale = ..., alpha: Float = ..., colorFilter: ColorFilter? = ..., filterQuality: FilterQuality = ...): Unit defined in androidx.compose.foundation public fun Image(painter: Painter, contentDescription: String?, modifier: Modifier = ..., alignment: Alignment = ..., contentScale: ContentScale = ..., alpha: Float = ..., colorFilter: ColorFilter? = ...): Unit defined in androidx.compose.foundation public fun Image(imageVector: ImageVector, contentDescription: String?, modifier: Modifier = ..., alignment: Alignment = ..., contentScale: ContentScale = ..., alpha: Float = ..., colorFilter: ColorFilter? = ...): Unit defined in androidx.compose.foundation

https://github.com/sierzputowskisz/magnifyingGlass

Upvotes: 0

Views: 668

Answers (1)

JustSightseeing
JustSightseeing

Reputation: 3025

enter image description here

after pulling the project I recreated the image and it was working for me, after comparing the two I noticed that the contentDescription in your Image was looking a bit funky

working code:

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

Upvotes: 0

Related Questions