burhanrashid52 / PhotoEditor

A Photo Editor library with simple, easy support for image editing using paints,text,filters,emoji and Sticker like stories.
MIT License
4.13k stars 991 forks source link

PhotoEditorView source image zoom. #179

Open usmanrana07 opened 5 years ago

usmanrana07 commented 5 years ago

Image in PhotoEditorView should be zoomable, this feature is missing in current version.

PedroBGDev commented 3 years ago

Is these issue solved?

ThuyKhanh commented 2 years ago

I googled this problem on the internet. There is a guy can do the zoom with this library: https://youtu.be/q7zPOtU4Mn8 But he just submitted the demo. If you resolve this problem, plz share

burhanrashid52 commented 2 years ago

@ThuyKhanh Thanks for the link. I don't have the solution for this right now. Feel free to open a PR when you find one.

NavjotSinghSeraphic commented 6 days ago

@burhanrashid52 this code is able to add zoom in and zoom out feature can you check please and implement this in library

import android.view.ScaleGestureDetector // Add this import

internal class PhotoEditorImpl @SuppressLint("ClickableViewAccessibility") constructor(
    builder: PhotoEditor.Builder
) : PhotoEditor {
    // Existing variables...
    private val context: Context = builder.context

    // Add variables for ScaleGestureDetector
    private var scaleFactor = 1.0f
    private val scaleGestureDetector: ScaleGestureDetector

    init {
        // Initialize the ScaleGestureDetector with a listener
        scaleGestureDetector = ScaleGestureDetector(context, object : ScaleGestureDetector.SimpleOnScaleGestureListener() {
            override fun onScale(detector: ScaleGestureDetector): Boolean {
                // Scale the image
                scaleFactor *= detector.scaleFactor
                // Set limits to prevent infinite zoom-in/out
                scaleFactor = scaleFactor.coerceIn(0.5f, 3.0f) 
                imageView?.scaleX = scaleFactor
                imageView?.scaleY = scaleFactor
                return true
            }
        })

        // Existing GestureDetector setup
        val mDetector = GestureDetector(
            context,
            PhotoEditorImageViewListener(
                viewState,
                object : OnSingleTapUpCallback {
                    override fun onSingleTapUp() {
                        clearHelperBox()
                    }
                }
            )
        )

        imageView?.setOnTouchListener { v, event ->
            mOnPhotoEditorListener?.onTouchSourceImage(event)
            // Pass touch events to both gesture detectors
            scaleGestureDetector.onTouchEvent(event) || mDetector.onTouchEvent(event)
        }

        // Other initializations...
        photoEditorView.setClipSourceImage(builder.clipSourceImage)
    }

    // Existing methods...
}

https://github.com/user-attachments/assets/42172fec-46b6-4027-bbe3-c65519846d81

burhanrashid52 commented 4 days ago

@NavjotSinghSeraphic Does it scale up/down the drawing on zoomin/zoomout image ? What is the usecase for this feature ?

NavjotSinghSeraphic commented 3 days ago

@burhanrashid52 If the user wants to zoom in or zoom out, they can easily do so, but it will only affect the image, not the drawing.