Android SharedPreferences Tutorial and Example

Creating a Photo Editor With Filters in Android

A photo editor is a practical Android project because it combines image loading, user interface design, bitmap processing, and file storage. A simple version can let users choose a picture, apply colour effects, compare the original with the edited result, and save a new copy without changing the source file.

This project suits Android beginners because each feature can be built separately. Kotlin, an ImageView, a few filter controls, and Android’s modern photo picker are enough to create a useful filter app. The same structure can later support cropping, brightness adjustment, stickers, and sharing.

Plan the editing workflow

Start with a clear editing pipeline: select an image, display it, apply a filter, preview the result, and export a separate file. Keeping the original bitmap unchanged makes it easy to reset the screen or switch between effects. Store the original image in memory and generate a new bitmap whenever the selected filter changes.

For current Android projects, use ActivityResultContracts.PickVisualMedia rather than requesting broad gallery access for a basic editor. This gives users a familiar system interface and reduces the amount of sensitive data your application can access. It is especially suitable for casual editing on phones commonly used in Sydney, Melbourne, Brisbane, and regional Australian areas.

A minimal activity layout might contain:

  • An ImageView for the preview
  • A horizontal filter selector
  • Reset and save buttons
  • A progress indicator for large images

Use ConstraintLayout or LinearLayout with content descriptions for controls. Filter names such as “Original”, “Warm”, “Cool”, “Mono”, and “Vintage” are easier to understand than technical names such as “Matrix 4”.

Load images safely with Kotlin

The photo picker returns a Uri, not a ready-to-use bitmap. Open the selected file through contentResolver, then decode it with BitmapFactory. Large phone images can consume significant memory, so avoid decoding a 50-megapixel image at its full size when the preview only occupies part of the screen.

private val pickImage =
    registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri ->
        uri?.let {
            contentResolver.openInputStream(it)?.use { stream ->
                val bitmap = BitmapFactory.decodeStream(stream)
                originalBitmap = bitmap
                binding.photoView.setImageBitmap(bitmap)
            }
        }
    }

Call the picker from a button click:

pickImage.launch(
    PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)
)

In a production application, decode the bitmap on a background dispatcher and scale it to a sensible preview size. This avoids freezing the interface when someone selects a high-resolution image from a recent Pixel or Samsung phone.

Apply colour filters to a bitmap

For a straightforward Android photo editor, ColorMatrix is a useful starting point. It can adjust saturation, brightness, contrast, and colour channels without requiring an external graphics library. A grayscale filter, for example, sets the saturation value to zero.

fun grayscale(source: Bitmap): Bitmap {
    val result = Bitmap.createBitmap(
        source.width,
        source.height,
        Bitmap.Config.ARGB_8888
    )

    val canvas = Canvas(result)
    val paint = Paint()
    val matrix = ColorMatrix().apply {
        setSaturation(0f)
    }

    paint.colorFilter = ColorMatrixColorFilter(matrix)
    canvas.drawBitmap(source, 0f, 0f, paint)
    return result
}

For a warm effect, increase red and slightly reduce blue. For a cool effect, do the reverse. A vintage filter can combine lower saturation with a contrast adjustment and a warm colour shift. Always create each result from originalBitmap, rather than applying a new matrix to the previous result, or repeated taps may gradually degrade the image.

Match filters to project requirements

Different filter techniques offer different balances between simplicity, speed, and control. The best option depends on whether your tutorial focuses on core Android APIs, advanced visual effects, or live camera editing.

Method Best use Advantages Limitations
ColorMatrix Basic colour presets Small amount of code, easy to explain Limited artistic effects
Canvas and Paint Custom overlays and blending Flexible for tints and textures More manual bitmap work
GPU shaders Real-time previews Fast and powerful Requires graphics knowledge
Open-source imaging library Advanced adjustments Many ready-made operations Adds dependency and licensing checks
CameraX effects Live camera filters Immediate preview experience More complex lifecycle and performance needs

A beginner tutorial should begin with ColorMatrix, then explain how Canvas drawing can add a translucent colour layer. This progression keeps the first project approachable while showing a path towards professional editing tools used by Australian content creators and small online retailers.

Build a responsive editing screen

Filter buttons should update the preview immediately, but heavy processing should not run on the main thread. Use Kotlin coroutines with Dispatchers.Default for bitmap work, then update the ImageView on the main dispatcher. Disable the save button while an export operation is running to prevent duplicate files.

lifecycleScope.launch {
    binding.progressBar.isVisible = true

    val filtered = withContext(Dispatchers.Default) {
        grayscale(originalBitmap)
    }

    binding.photoView.setImageBitmap(filtered)
    currentBitmap = filtered
    binding.progressBar.isVisible = false
}

A horizontal RecyclerView works well for filter presets because each item can show a small thumbnail and a label. Avoid generating full-size thumbnails for every option; a scaled preview bitmap keeps scrolling smooth on budget devices and older phones.

Save an edited copy responsibly

Save the result through MediaStore, which lets Android manage shared media without requiring broad storage access on modern versions. Place exported images in the Pictures collection and provide a useful display name, such as edited_2025_08_14.jpg.

val values = ContentValues().apply {
    put(MediaStore.Images.Media.DISPLAY_NAME, "edited_photo.jpg")
    put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg")
    put(MediaStore.Images.Media.RELATIVE_PATH, Environment.DIRECTORY_PICTURES)
}

val uri = contentResolver.insert(
    MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
    values
)

uri?.let {
    contentResolver.openOutputStream(it)?.use { output ->
        currentBitmap.compress(Bitmap.CompressFormat.JPEG, 92, output)
    }
}

JPEG compression is widely compatible, while PNG is better when transparency matters. Explain that repeated JPEG exports can reduce quality, so the application should retain the original and export from the current high-quality editing state whenever possible.

Protect privacy and personal images

Photos may contain faces, addresses, children, documents, or location metadata. The app should explain why it needs access to an image and should avoid uploading files unless cloud processing is an essential, clearly disclosed feature. A local-only filter editor is easier to trust and simpler to demonstrate.

Australian developers should consider the Privacy Act 1988 and the Australian Privacy Principles when collecting, transmitting, or storing personal information. If the app is distributed through Google Play to users in Australia, its privacy policy should accurately describe image handling, analytics, advertising, and deletion practices. Do not claim that photos stay private if an analytics or cloud service receives them.

Useful privacy decisions include:

  • Process filters on the device where practical
  • Remove temporary files after export
  • Preserve metadata only when the user expects it
  • Provide a clear delete or reset action

If an image is shared through another application, use Android’s share sheet rather than exposing a public file path. This also gives users control over whether an edited image goes to Messages, Gmail, Instagram, or another installed service.

Test filters across real devices

Test with portrait and landscape images, transparent PNG files, very large photographs, and images selected from cloud-backed providers. Check that rotation metadata is handled correctly; otherwise, a picture taken on a phone in Perth or Adelaide may appear sideways in the editor.

Also test dark mode, large font settings, TalkBack labels, and narrow screens. Australian users may have older or lower-cost devices, so measure memory usage instead of testing only on a recent flagship. Verify that the app behaves properly when the device rotates, the activity is recreated, or the user leaves the editor while processing is underway.

A reliable testing checklist includes:

  • Resetting from every filter state
  • Saving after multiple filter changes
  • Cancelling the photo picker
  • Handling a missing or unreadable file
  • Confirming the exported image appears in Gallery

Once the basic version works, you can extend it with sliders for saturation and brightness, undo and redo history, crop controls, stickers, or CameraX previews. The core separation between original image, edited bitmap, interface state, and exported file will make those additions much easier to maintain.