Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加Content Decoder #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions image/src/main/java/me/kareluo/imaging/IMGEditActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import me.kareluo.imaging.core.file.IMGAssetFileDecoder;
import me.kareluo.imaging.core.file.IMGDecoder;
import me.kareluo.imaging.core.file.IMGFileDecoder;
import me.kareluo.imaging.core.file.IMGContentDecoder;
import me.kareluo.imaging.core.util.IMGUtils;

import java.io.FileNotFoundException;
Expand Down Expand Up @@ -59,6 +60,9 @@ public Bitmap getBitmap() {
case "file":
decoder = new IMGFileDecoder(uri);
break;
case "content":
decoder = new IMGContentDecoder(uri, getContentResolver());
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package me.kareluo.imaging.core.file;

import android.content.ContentResolver;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;

import java.io.FileNotFoundException;
import java.io.InputStream;

public class IMGContentDecoder extends IMGDecoder {

private ContentResolver _resolver;

public IMGContentDecoder(Uri uri) {
super(uri);
}

public IMGContentDecoder(Uri uri,ContentResolver resolver){
super(uri);
_resolver = resolver;
}


@Override
public Bitmap decode(BitmapFactory.Options options) {
if(_resolver == null)
return null;
InputStream is;
try {
is = _resolver.openInputStream(getUri());
} catch (FileNotFoundException e) {
return null;
}
return BitmapFactory.decodeStream(is,null,options);
}

public ContentResolver getResolver(){
return _resolver;
}

public void setResolver(ContentResolver resolver){
_resolver = resolver;
}
}