هل مكنك تعديل الكود class MainActivity : AppCompatActivity() {
    private lateinit var imageView: ImageView
    private lateinit var enhanceButton: Button

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        OpenCVLoader.initDebug()

        // Initialize the views and buttons
        imageView = findViewById(R.id.imageView)
        enhanceButton = findViewById(R.id.enhanceButton)

        // Set the onClickListener for the enhance button
        enhanceButton.setOnClickListener {
            Glide.with(this)
                .asBitmap()
                .load(R.drawable.test)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .centerCrop()
                .into(object : SimpleTarget<Bitmap>() {
                    override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
                        val enhancedBitmap = upscaleImage(resource, 2.0)
                        imageView.setImageBitmap(enhancedBitmap)

// Scale down the bitmap to prevent “Canvas: trying to draw too large bitmap” error
                        val scaledDownBitmap = Bitmap.createScaledBitmap(enhancedBitmap, imageView.width, imageView.height, false)
                        imageView.setImageBitmap(scaledDownBitmap)
                    }
                })
        }
    }

    private fun enhanceImage(bitmap: Bitmap): Bitmap {
        // Convert the Bitmap to an array of pixels and create a new Bitmap with the same dimensions
        val pixels = IntArray(bitmap.width * bitmap.height)
        bitmap.getPixels(pixels, 0, bitmap.width, 0, 0, bitmap.width, bitmap.height)
        val outputBitmap = Bitmap.createBitmap(bitmap.width, bitmap.height, Bitmap.Config.ARGB_8888)

        // Loop over the pixels and enhance the colors
        for (y in 0 until bitmap.height) {
            for (x in 0 until bitmap.width) {
                val index = y * bitmap.width + x
                val pixel = pixels[index]

                // Extract the red, green, and blue components from the pixel
                val red = (pixel shr 16) and 0xFF
                val green = (pixel shr 8) and 0xFF
                val blue = pixel and 0xFF

                // Enhance the colors by increasing the contrast
                val enhancedRed = enhanceColor(red)
                val enhancedGreen = enhanceColor(green)
                val enhancedBlue = enhanceColor(blue)

                // Combine the enhanced colors and set the pixel in the output Bitmap
                val enhancedPixel = (0xFF shl 24) or (enhancedRed shl 16) or (enhancedGreen shl 8) or enhancedBlue
                outputBitmap.setPixel(x, y, enhancedPixel)
            }
        }

        return outputBitmap
    }

    private fun enhanceColor(color: Int): Int {
        return if (color < 128) 0 else 255
    }

    private fun upscaleImage(bitmap: Bitmap, scale: Double): Bitmap {
        val inputMat = Mat()
        val outputMat = Mat()

        Utils.bitmapToMat(bitmap, inputMat)
        Imgproc.resize(inputMat, outputMat, Size(inputMat.width() * scale, inputMat.height() * scale), 0.0, 0.0, Imgproc.INTER_CUBIC)

// Create a new Bitmap with the scaled dimensions
        val scaledBitmap = Bitmap.createScaledBitmap(bitmap, (bitmap.width * scale).toInt(), (bitmap.height * scale).toInt(), false)

// Get the scaled bitmap using the outputMat
        val outputBitmap = Bitmap.createBitmap(scaledBitmap.width, scaledBitmap.height, Bitmap.Config.ARGB_8888)
        Utils.matToBitmap(outputMat, outputBitmap)

// Recycle the input bitmap to free up memory
        bitmap.recycle()
        scaledBitmap.recycle()

        return outputBitmap
    }



} لزيادة جودة الصورة اكثر لانها لا تزيد  يرجي تعديل الكود