Android Crop Image And Assign Wallpaper

On September 11, 2014, in Android, by James Liu

New Update Version 1.6:

  • Add cropping function
  • Scale bitmap data before setting as wallpaper

To create an Android wallpaper app, the cropping picture function is quite necessary. To support multiple Android screens, I have to make sure to assign the right size pictures to Android wallpaper. In my solution, I will prepare a set of high resolution pictures to fit the majority Android screen size. When users choose one picture, I will let them to trim the pictures in a specific aspect ratio to perfectly fit the screen size. For example, I will prepare the big image in 1600×1000. When users want to set wallpaper on their 480×800 Android phone, I will provide a cropping tool which can only trims the image in 3:5 aspect ratio. Now, let me show you how I add this cropping feature in my Android Wallpaper app.

This Android Wallpaper App example includes four tutorials:

Adding Cropper Project in Eclipse

I am using the 3rd party Android library to implement the cropping function in my Wallpaper project. When you get my source code zip package, you will find there are two project, one is Cropper library project. You follow these steps to import the library project in Eclipse.

  • Choose File -> Import menu item
  • Select “Archive File” in the popup window
  • Choose the file in the next window
  • Click finish to import the project in Eclipse


import cropper 2

import cropper 3

You can use the same steps to import my project in the Eclipse. After that, you need to add Cropper library in Android Wallpaper example project. Here are the steps:

  • Right click on Android Wallpaper project
  • Select Properties option
  • Go to Android section and add Cropper library

add cropper library

Using CropImageView in previewpanel.xml

When users select one picture, I will show the image in the preview panel. In this preview panel, I will provide a crop tool for them to trim the image. Here is the layout xml example source code:

<RelativeLayout xmlns:android=""
    android:orientation="vertical" >

Load Image into Cropper

Now, let’s talk about how to load the image into cropper image widget. Actually it is very simple. But here I will set the crop widget to keep aspect ratio. Android requires the wallpaper resolution 2 times wider than the actually screen resolution. So I have to set the crop ratio 2 times wider than the Android screen size resolution aspect ratio. Here is some example code:

File cacheDir = GlobalClass.instance().getCacheFolder(this);
File cacheFile = new File(cacheDir, wallpaperFilePath);
InputStream fileInputStream = new FileInputStream(cacheFile);
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
bitmapOptions.inSampleSize = scale;
bitmapOptions.inJustDecodeBounds = false;
Bitmap wallpaperBitmap = BitmapFactory.decodeStream(fileInputStream, null, bitmapOptions);

cropImageView = (CropImageView)this.findViewById(;
cropImageView.setAspectRatio(screenWidth * 2, screenHeight);

crop image

Crop Image to Prepare Wallpaper For Android

Now, users can crop the images by dragging the corner. After users decide the size and area they want to set as wallpaper, they can click “set wallpaper” menu to set the Android wallpaper. Here is the android example source code to demonstrate how to trim the bitmap from original image.

RectF rect = cropImageView.getActualCropRect();
int cropx = (int) rect.left * scale;
int cropy = (int) * scale;
int cropw = (int) rect.width() * scale;
int croph = (int) rect.height() * scale;
Bitmap bitmapSource = BitmapFactory.decodeStream(fileInputStream);
final Bitmap croppedBitmap = Bitmap.createBitmap(bitmapSource, cropx, cropy, cropw, croph);

Try Example Android App

You can download and install this android app by click the following link, or scan the following QR code to download and install on your android phone simply. If you feel it is helpful, please support me by clicking the banner inside the app.
Download and Run This Example on Your Android Phone

Get Full Source Code under $6.99

You will get whole Android Wallpaper App source code at $6.99. With this source code, you can do everything you want:

  • Load your own wallpaper;
  • Monetize the app with your own AdMob publish id;
  • Use the source code in your own project;
  • Publish this app in your android develop account;

50 Responses to “Android Crop Image And Assign Wallpaper”

  1. thibautfrance says:

    Hi james,

    Very Good U did IT :-D, How to get the link of download ? (given that I already buy in step 4) ?

    Thanks Man 🙂

  2. thibautfrance says:

    Just a last answer how to display the ad because I ha an error :p but I think it’s easy to resolve, I tried but I didn’t success to resolve :p Check the picture in link pls :p

  3. thibautfrance says:

    I found it ! 😉

    You need to change


  4. thibautfrance says:


  5. thibautfrance says:

    Hi James,
    Given that I already paid, can you send me the link for the update 1.6 package by email please.

    Thank you 🙂

  6. prabu says:

    i need this source code bt i haven’t paypal account …can u please sent ur account number i ll transfer u..thanks for advance

  7. yudined says:

    Hi! Say me please this wallpaper app can use images as animated Gif? Maybe html ?

  8. Milap says:

    i want a link for download can you send me bro.

    thank you.

  9. Angels says:

    Hello I bought your code but I cannot run the ads. It gives me the error “There was a problem getting an ad response. ErrorCode: 0”. I changed the error in manifest so this is not the problem.

    In addition, I tried to install the example but I cannot. Could you please fix it?

    • James says:

      What do you mean “I tried to install the example”? You are able to debug the app in your device, aren’t you? After you build an apk file, you’d better uninstall the debug version on your device, then install the released apk file.

  10. Akash Singh says:

    hi there,
    On 21-4-2015 i had paid for this Android Wallpaper App full source code
    twice by mistake,But still my Purchase Failed to Download and i was unable to Get this Source Code.
    In other words…I have paid $6.99 + $6.99 to you…and i have nothing.
    Please check this Problem and i am requesting you to solve this
    problem and Refund my Money back.

  11. Loki says:

    hi James, thanks for the template. I paid your fee and I did get the the main but I did not receive the that you said was included. Would you be able to email me a copy please? Thank you!

  12. Diaz says:

    amazing work . But i want link to cropper .zip file .So that i can use it . Please send me the Link.

  13. dankeyz says:

    Hi James I see u are doing a great job here. OK am really new to android development and I wanna created a wallpaper app. Ok I have android studio and eclipse on my PC . it looks like d tutorial is broken into parts(example) can u compile d whole source code into one downloadable file so I can download and import directly to my eclipse . to avoid concussion cuz am kind of confused looking at it example by example. Thanks

  14. dankeyz says:

    And pls how can I set image wallpaper from my resources drawable directly instead downloading I want something completely off line. Thanks in advance

  15. dankeyz says:

    Ok thanks for ur reply. But what I dont understand is I want create a wallpaper app. In my eclipse project and u have d source code broken can I get d full source code download to important in my eclipse or is there a way to join or merge each example together to get work. Thanks

  16. dankeyz says:

    Ok which of d pay pal button? Is it d one for expample 1,2,3,4, or 5?

  17. dankeyz says:

    Hello I just paid for d source code but it refuses to download. How can I get it?

    • James Liu says:


      My website is too busy and the download service goes unfunctional. Now everything is going well. For your purchased source code, I will send it to your email.


  18. dankeyz says:

    Hello James pls do I have to buy souce code for example 2,3,4 or d source code for example 5 covers all

Leave a Reply