
----
20241222_0232
1. The drawable-nodpi folder has to be used for keeping images, otherwise, android rescales images according to screen density..
2. If the overlay function is not working, check the function by passing opposite paraments, like overlay(layer 2, layer 1) .. as it could be putting the needed top layer in bottom otherwise..
3. I tried rotating the image (original image, without rotation) in activity_main.xml with chatgpt's help, but the rotated image is smaller than the one that loads form frame_rotated image file, not full screen.. so reverted back to using a already rotated copy of the image file (for overlay, the image has to be in horizontal direction)
20241222_0344
* Found a bug, its again rotated in Realme.. But the older App (landscape) where it was reading image from disk was working correctly... Fixing now...
----
* The xml file that draws the red (3:2 or 1.4:1 ) rectangle is at app/src/main/res/layout/activity_main.xml
* If you want to change applicationID so that more than one installation can be done, change it in 'build.gradle' app level file.
* Change the name of the App, in res/values/strings.xml file, in app_name attribute.
* If you want to change the project name (in android studio), do this:
Step 1: Update the settings.gradle File

    Locate settings.gradle: In the Gradle Scripts folder, find the settings.gradle file.
    Edit the File: Open settings.gradle and change the rootProject.name to your new project name:

    rootProject.name = 'NewProjectName'

Step 2: Sync and Rebuild the Project

     Sync Gradle: After making all the changes, click on the Sync Now link that appears at the top of the editor to sync your Gradle files.
     Rebuild the Project: Go to Build > Rebuild Project to ensure everything is working correctly.

* The overlay wasn't working at all for hours, finally turned out, i had not given it Photos permission in App info in phone... Duh...

TO DO
Checked: Creates directory. Check if directory gets created on phone, where images have to be saved, if its not there intially.
Done: Change App Icon (Changed via res- right click, add new image asset... Replacing files with needed sized didn't work.
Not needed: It asks already. Write code for App to ask for permissions on first time, rather than manually having to set photo permissions.
Add changable camera resolution feature.
Add contact me option in app.
Add option to keep original camera photo file.
No auto rotate, as outline rectangle becomes portrait in landscape mode.
Fix for Image becomes portrait in Landscape upon Auto Rotate being on. Right now Orientation is set to portrait, using AndroidManifest.xml file.
Add exif information to cropped image. Preferably all camera info (like in Huawei Tablet editor, that saves all exif info)..
There is some discripancy between camera viewed orientation and saved file orienation. When i rotated my photo on the computer image viewer (to right), a click of it got saved on the camera as an image 'rotate left' of the view in display. When auto rotate is on, it aligns correctly when phone is in Landscape way. The photo taken was in Portrait way, of portrait image on photo. Needs some tweaking. Landscape photos are showing in Landscape when holding the phone in portrait way, which is correct. This problem is in Samsung, haven't checked on realme.

UPDATES
2024-12-18
The filename is like this -> 3-2-camera_2024-12-18_10-30-18.jpg

--
Done: Changed App Icon (Changed via res- right click, add new image asset... Replacing files with needed sized didn't work.
Changed saving location to DCIM/3-2 Camera
Hard coded cropping logic, as the image on realme is 1080x1920 rather than 1920x1080 (as in samsung m21)... So it crops only the side which is 1920
Set orientation to portrait in app. No auto rotate, as outline rectangle becomes portrait in landscape mode. However image becomes portrait in Landscape upon Auto Rotate being on.
TimeStamp: 2024-12-05 17.25
Changed version to 2, as google needed it for second upload in console, internal testing.


To modify the overlayImage function to overlay two images with the behavior you described, we need to include logic to check if the dimensions of the two images are the same. If the dimensions are the same, the function overlays them directly. If they are not the same but one dimension matches while the other does not, the function rotates the overlay image before applying it.

Here’s how the updated function might look:

import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Matrix

public fun overlayImage(croppedBitmap: Bitmap, overlayBitmap: Bitmap): Bitmap {
    val width1 = croppedBitmap.width
    val height1 = croppedBitmap.height
    val width2 = overlayBitmap.width
    val height2 = overlayBitmap.height

    val rotatedOverlayBitmap = if (width1 == height2 && height1 == width2) {
        // Rotate the overlayBitmap 90 degrees to match the croppedBitmap dimensions
        val matrix = Matrix()
        matrix.postRotate(90f)
        Bitmap.createBitmap(overlayBitmap, 0, 0, width2, height2, matrix, true)
    } else if (width1 == width2 && height1 == height2) {
        // No rotation needed
        overlayBitmap
    } else {
        throw IllegalArgumentException("The overlayBitmap dimensions are incompatible for overlaying.")
    }

    val combinedBitmap = Bitmap.createBitmap(
        croppedBitmap.width,
        croppedBitmap.height,
        croppedBitmap.config ?: Bitmap.Config.ARGB_8888 // Use a default config if null
    )

    val canvas = Canvas(combinedBitmap)
    canvas.drawBitmap(croppedBitmap, 0f, 0f, null)

    val overlayX = (croppedBitmap.width - rotatedOverlayBitmap.width) / 2f
    val overlayY = (croppedBitmap.height - rotatedOverlayBitmap.height) / 2f
    canvas.drawBitmap(rotatedOverlayBitmap, overlayX, overlayY, null)

    return combinedBitmap
}

Explanation:

    Dimension Check:
        If width1 == width2 and height1 == height2, the images are directly overlaid.
        If width1 == height2 and height1 == width2, the overlayBitmap is rotated by 90° to align dimensions before overlaying.

    Rotation:
        A Matrix is used to rotate the overlayBitmap by 90 degrees.

    Overlay Positioning:
        The overlayBitmap is centered on the croppedBitmap by calculating its top-left corner coordinates (overlayX, overlayY).

    Error Handling:
        If the dimensions are incompatible for overlaying, an exception is thrown to alert the developer. This can be adjusted based on requirements.

This should handle your described behavior of matching and aligning images based on their dimensions.

