Check if the Bitmap file is corrupted - Android Graphics

Android examples for Graphics:Bitmap File

Description

Check if the Bitmap file is corrupted

Demo Code


//package com.java2s;
import android.graphics.BitmapFactory;

public class Main {

    public static boolean checkImgCorrupted(String filePath) {
        BitmapFactory.Options options = null;
        if (options == null) {
            options = new BitmapFactory.Options();
        }//  ww w. j  av a 2 s  . c om
        options.inJustDecodeBounds = true;

        BitmapFactory.decodeFile(filePath, options);
        if (options.mCancel || options.outWidth == -1
                || options.outHeight == -1) {
            return true;
        }
        return false;
    }
}

Related Tutorials