Skip to content

Instantly share code, notes, and snippets.

@abhinav272
Created August 7, 2018 12:19
Show Gist options
  • Save abhinav272/5c32e158fbf2aaa5a044280e3c073444 to your computer and use it in GitHub Desktop.
Save abhinav272/5c32e158fbf2aaa5a044280e3c073444 to your computer and use it in GitHub Desktop.
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