Created
August 7, 2018 12:19
-
-
Save abhinav272/5c32e158fbf2aaa5a044280e3c073444 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.graphics.BitmapFactory; | |
//Not thread safe | |
public class SizeFromImage implements ISize { | |
private String path; | |
private int width; | |
private int height; | |
public SizeFromImage(String path) { | |
this.path = path; | |
width = -1; | |
height = -1; | |
} | |
@Override | |
public int width() { | |
if (width == -1) { | |
init(); | |
} | |
return width; | |
} | |
@Override | |
public int height() { | |
if (height == -1) { | |
init(); | |
} | |
return height; | |
} | |
private void init() { | |
BitmapFactory.Options options = new BitmapFactory.Options(); | |
options.inJustDecodeBounds = true; | |
BitmapFactory.decodeFile(path, options); | |
width = options.outWidth; | |
height = options.outHeight; | |
} | |
@Override | |
public boolean equals(Object o) { | |
return SizeEqualsAndHashCode.equals(this, o); | |
} | |
@Override | |
public int hashCode() { | |
return SizeEqualsAndHashCode.hashCode(this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment