I'm creating an Android app. So this is a small feature which is required. So this is like a small section image upload. Make the exact UI using XML. You are in android and also implement the feature like when you click when the user clicks on this like it will be a option if like whether to use camera or upload from gallery and if the user approach from gallery then let him upload and the image will be shown over there and only one image can be uploaded. One image should be uploaded and can be uploading so that is the limit. After uploading your image you can show across like if you want to change the image. Like you can delete and and change the image. I also implement this feature like I have given it the exact UI. How should it look? To use it implemented in XML and Kotlin.
I'll create an Android image upload feature that matches the UI in your screenshot and implements the functionality you described. I'll use XML for the layout and Kotlin for the implementation.
activity_image_upload.xml
Now let's create the necessary drawable resources:
drawable/ic_add.xml
drawable/ic_delete.xml
drawable/circle_background.xml
Now let's implement the Kotlin code for the functionality:
ImageUploadActivity.kt
Finally, let's add the necessary provider configuration to the AndroidManifest.xml:
AndroidManifest.xml (partial)
And create the file_paths.xml resource:
xml/file_paths.xml
Make sure to add the necessary dependencies in your app's build.gradle file:
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
Add the required permissions to your AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
This implementation follows modern Android development practices using Kotlin and handles all the edge cases for image capture and selection.
Canvas: trying to use a recycled bitmap 2025-03-28 14:01:04.988 11205-11205 System.err com.neoperk.neoperkscanner W java.lang.RuntimeException: Canvas: trying to draw too large(256872448bytes) bitmap. 2025-03-28 14:01:04.988 11205-11205 System.err com.neoperk.neoperkscanner W at android.graphics.RecordingCanvas.throwIfCannotDraw(RecordingCanvas.java:274) See when I try to upload image of large size. It doesn't upload but the previous screen appears with blank. So what I want to do see this warning is sent pad. But I what I want to do is previous screen shouldn't be visible and whenever the user selects a large photo just when this emanate fails and justice show a toast like the image size limit exceeded or image should be within basically within this test KB. Like like that show a message and also don't show a blank previous screen if if it now it is showing a bank through the screen so. Blank review screen now it is showing so the UI don't do anything just the logic you get it right the why the set is coming.
I see the issue. You're encountering a "Canvas: trying to draw too large bitmap" error when users try to upload large images. Let's modify the code to handle large images properly by:
Here's the updated implementation:
ImageUploadActivity.kt
Added Image Size Checking:
MAX_IMAGE_SIZE
constant (5MB) to limit file sizeAdded Bitmap Sampling and Resizing:
decodeSampledBitmapFromUri()
method to safely load large imagescalculateInSampleSize()
to determine optimal sampling rateImproved Error Handling:
Memory Management:
Image Processing Workflow:
processSelectedImage()
method that handles all validation and processingThese changes will prevent the "Canvas: trying to draw too large bitmap" error and provide a better user experience by:
The user will now see a toast message like "Image size exceeds limit (max 5MB). Please select a smaller image." instead of experiencing a crash or seeing a blank screen.
Canvas: trying to use a recycled bitmap 2025-03-28 14:14:24.142 18855-18855 System.err com.neoperk.neoperkscanner W java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@ca2b2df 2025-03-28 14:14:24.142 18855-18855 System.err com.neoperk.neoperkscanner W at android.graphics.BaseCanvas.throwIfCannotDraw(BaseCanvas.java:80) Now it is showing. Like if I exit Max 5B but if it is now not even showing the preview image for smaller images and like the taking photo then I click on take even then the blank previous finish shown. Even when I upload small sizes images a blank previous case is shown and this is the error which is coming. And for like only that issue is all but you have like messed up here. Don't change that much logic but. See like previously this was working even my like the smaller photo was working and like the camera when I when I click on. When I click on camera and take photo and then it appears on the preview but now even the camera and smaller image shows previous screen as blank.