I have the following line in my CameraXFragment and Android Studio is showing me an error:
videoCapture = VideoCaptureConfig.Builder() // <--- Builder is in red
.setTargetRotation(binding.previewView.display.rotation)
.setCameraSelector(cameraSelector)
.setTargetAspectRatio(screenAspectRatio)
.build()
Android Studio does not recognize Builder after updating the camerax version from '1.0.0-beta04' to '1.0.0-beta12'.
Does somebody know how to create a VideoCaptureConfig in the latest version ?
Use VideoCapture.Builder():
videoCapture = VideoCapture.Builder()
.setTargetRotation(binding.previewView.display.rotation)
.setCameraSelector(cameraSelector)
.setTargetAspectRatio(screenAspectRatio)
.build()
You could use this in order to utilize the library's restricted api. That doesn't mean it's gonna work, though.
#SuppressLint("RestrictedApi")
Related
I am working on a Jetpack Project which downloads an image from API using Coil Library.
I have confirmed that valid image URLs and related data are being returned from the API call successfully. I am able to view the image on my browser using the returned URL.
This is my Image Composable:
#Composable
fun AstroPhoto(picture: AstroPicture) {
val imgUrl = picture.url.toUri()
.buildUpon()
.scheme("https")
.build()
AsyncImage(model = ImageRequest.Builder(LocalContext.current)
.data(imgUrl)
.size(Size.ORIGINAL)
.crossfade(true).build(),
placeholder = painterResource(R.drawable.loading_animation),
contentDescription = picture.title,
contentScale = ContentScale.Crop,
)
}
I call the above image composable in a Lazy Column:
....
Box( ... ) {
LazyColumn(content = {
items(state.astroPictures) {
AstroPhoto(picture = it)
} })
}
This is the exception at I am getting:
FATAL EXCEPTION: main Process: com.uxstate, PID: 31790
java.lang.IllegalArgumentException: Only VectorDrawables and
rasterized asset types are supported ex. PNG, JPG
at androidx.compose.ui.res.PainterResources_androidKt.loadVectorResource(PainterResources.android.kt:93)
I am on compose_version = '1.1.1' working with kotlin_version = '1.6.10'. My coil version is "io.coil-kt:coil-compose:2.1.0" and compileSdk 32 and AS Chipmunk. Source code can be found here.
I have checked the docs and searched online but cannot resolve the error. Please help me to go about the error, Thanks.
if you are using png and jpg with painterResource but still face this issue. Change your image, It happened when there is something wrong with the image.
painterResource converts png, and jpg in the bitmap. Its throws that error if it fails to convert any Resource
My project worked correctly before, but after I changed some code (just add a fucntion, it is not about png or jpg or other things about image), my app crash when render a png. But after i reinstall the project in the emulator, it is fixed.
It seems like a bug in Compose? I dont know, may be a bug in gradle?
Just try to reinstall your app, i think it will be fixed.
in my previous projects, there is no problem passing drawable resources to painterResource function. But when I create a new jetpack-compose project, the problem you describe occurs.
In my new project, this problem only happens in preview phase. When I firstly build and run my app in emulator, the problem suddenly disappears.
so this is my solution: if you haven't run you app in emulator, build and run it in emulator.
Just encountered this error and see if anyone had the same error as me.
I just re-opened the Android Studio, and after that, I use Clean Project and Rebuild Project. Now the project and the compose preview are working fine.
Tried to use shape drawable as a placeholder and it caused this error.
If I set the same placeholder to ImageRequest.Builder instead, the code works fine.
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(imageUrl)
.placeholder(R.drawable.placeholder_rect)
.error(R.drawable.placeholder_rect)
.build(),
contentDescription = "",
)
I am following this explanation and having a problem with this code:
val options = TranslatorOptions.Builder()
.setSourceLanguage(TranslateLanguage.ENGLISH)
.setTargetLanguage(TranslateLanguage.GERMAN) .build()
val englishGermanTranslator = Translator.getClient(options)
Only getClient() remained in red. Everything else was properly imported with Alt+Enter.
Am I missing something?
Seems to be an error/typo in the documentation. Translator should be changed to Translation:
val englishGermanTranslator = Translation.getClient(options)
You might want to create an issue.
I'm trying to integrate camerax into my app. I followed the official documentation given here. In the example code the second line mentions:
val viewFinder: PreviewView = findViewById(R.id.previewView)
But PreviewView is not found. I went to the official class definition documentation here and found that the hierarchy is androidx.camera.view.PreviewView. So I tried adding it explicitly
import androidx.camera.view.PreviewView
But androidx.camera.view is not found.
PreviewView was added to androidx.camera:camera-view starting with version 1.0.0-alpha04. So, make sure
that your CameraX dependencies in Gradle are at 1.0.0-alpha04 and that you have androidx.camera:camera-view as one of those dependencies.
I'm novice in Android development (more Python and ML engineer) but wanted to try this example from TensorFlow: TF Lite Transfer Learning.
I succesfully run it on Android Studio but spotted that I cannot do anything with the app as it works extraordinary slow. I was digging through the code to find a root cause a found out this.
In function CameraFragment::startCamera() a preview context is created
PreviewConfig config = new PreviewConfig.Builder()
.setLensFacing(LENS_FACING)
.setTargetAspectRatio(screenAspectRatio)
.setTargetRotation(viewFinder.getDisplay().getRotation())
.build();
Preview preview = new Preview(config);
preview.setOnPreviewOutputUpdateListener(previewOutput -> {
ViewGroup parent = (ViewGroup) viewFinder.getParent();
parent.removeView(viewFinder);
parent.addView(viewFinder, 0);
As well as other use case that we can keep empty:
final ImageAnalysisConfig imageAnalysisConfig =
new ImageAnalysisConfig.Builder()
.setLensFacing(LENS_FACING)
.setTargetResolution(new Size(224, 224))
.setCallbackHandler(new Handler(inferenceThread.getLooper()))
.setImageReaderMode(ImageAnalysis.ImageReaderMode.ACQUIRE_LATEST_IMAGE)
.build();
final ImageAnalysis imageAnalysis2 = new ImageAnalysis(imageAnalysisConfig);
imageAnalysis2.setAnalyzer((image, rotationDegrees) -> { });
New we have a line to bring them to life:
CameraX.bindToLifecycle(this, preview, imageAnalysis2);
And here is where the problem starts. If we keep them like that the application is unusable. But if we keep only one (either one) we can use the app to the point that all novigation works normally. Do you know what is causing this behaviour?
This build.gradle uses a rather old version; migrate to version 1.0.0-beta01.
I created an application that use viewrenderable to show Gif in ARCore, but after 90-100 or more the app will crash. How to reuse viewrenderable in ARCore?
ViewRenderable.builder()
.setView(fragment.context, gifObject)
.build()
.thenAccept { viewRenderable ->
viewRenderable.view
... //create anchor and node
}
Please help me, I'm using ARCore Android SDK
Maybe you create too many anchors,It's very resource intensive,you could create an anchor,an anchorNode as global,then every frame,you detach last anchor,then create a new anchor,and use anchorNode.setAnchor(anchor). have a try,maybe it works.
Incase you haven't found a solution yet, I recommend debugging and find out any rendering related issues using Graphics API Debugger (GAPID). It comes with an interface that lets you view and inspect frame by frame