本文整理匯總了Java中android.graphics.BitmapFactory.decodeStream方法的典型用法代碼示例。如果您正苦於以下問題:Java BitmapFactory.decodeStream方法的具體用法?Java BitmapFactory.decodeStream怎麽用?Java BitmapFactory.decodeStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.BitmapFactory
的用法示例。
在下文中一共展示了BitmapFactory.decodeStream方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: scanningImage
import android.graphics.BitmapFactory; //導入方法依賴的package包/類
protected Result scanningImage(Uri path) {
if (path == null || path.equals("")) {
return null;
}
// DecodeHintType 和EncodeHintType
Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
hints.put(DecodeHintType.CHARACTER_SET, "utf-8"); // 設置二維碼內容的編碼
try {
Bitmap scanBitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap);
BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
QRCodeReader reader = new QRCodeReader();
return reader.decode(bitmap1, hints);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例2: defineImageSizeAndRotation
import android.graphics.BitmapFactory; //導入方法依賴的package包/類
protected ImageFileInfo defineImageSizeAndRotation(InputStream imageStream, ImageDecodingInfo
decodingInfo) throws IOException {
ExifInfo exif;
Options options = new Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(imageStream, null, options);
String imageUri = decodingInfo.getImageUri();
if (decodingInfo.shouldConsiderExifParams() && canDefineExifParams(imageUri, options
.outMimeType)) {
exif = defineExifOrientation(imageUri);
} else {
exif = new ExifInfo();
}
return new ImageFileInfo(new ImageSize(options.outWidth, options.outHeight, exif
.rotation), exif);
}
示例3: verifyBitmap
import android.graphics.BitmapFactory; //導入方法依賴的package包/類
public static boolean verifyBitmap(InputStream input) {
if (input == null) {
return false;
}
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
input = input instanceof BufferedInputStream ? input
: new BufferedInputStream(input);
BitmapFactory.decodeStream(input, null, options);
try {
input.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return (options.outHeight > 0) && (options.outWidth > 0);
}
示例4: decodeBitmapFromInputStream
import android.graphics.BitmapFactory; //導入方法依賴的package包/類
/**
* Decode and sample down a bitmap from an input stream to the requested width and height.
*
* @param is The input stream to read from
* @param reqWidth The requested width of the resulting bitmap
* @param reqHeight The requested height of the resulting bitmap
* @return A bitmap sampled down from the original with the same aspect ratio and dimensions
* that are equal to or greater than the requested width and height
*/
public static Bitmap decodeBitmapFromInputStream(InputStream is, int reqWidth, int reqHeight) {
// Bitmap m = BitmapFactory.decodeStream(is);
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(is, null, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
Bitmap mm = BitmapFactory.decodeStream(is, null, options);
return mm;
}
示例5: getBitmapFromAsset
import android.graphics.BitmapFactory; //導入方法依賴的package包/類
public static Bitmap getBitmapFromAsset(Context context, String filePath) {
AssetManager assetManager = context.getAssets();
InputStream istr;
Bitmap bitmap = null;
try {
istr = assetManager.open(filePath);
bitmap = BitmapFactory.decodeStream(istr);
} catch (IOException e) {
// handle exception
}
return bitmap;
}
示例6: getImageSize
import android.graphics.BitmapFactory; //導入方法依賴的package包/類
/**
* 根據InputStream獲取圖片實際的寬度和高度
*
* @param imageStream
* @return
*/
public static ImageSize getImageSize(InputStream imageStream) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(imageStream, null, options);
return new ImageSize(options.outWidth, options.outHeight);
}
示例7: getImageSize
import android.graphics.BitmapFactory; //導入方法依賴的package包/類
/**
* 根據InputStream獲取圖片實際的寬度和高度
*
* @param imageStream
* @return
*/
public static ImageSize getImageSize(InputStream imageStream)
{
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(imageStream, null, options);
return new ImageSize(options.outWidth, options.outHeight);
}
示例8: getAppInfoFromValue
import android.graphics.BitmapFactory; //導入方法依賴的package包/類
private AppInfo getAppInfoFromValue(String value) {
AppInfo appInfo = new AppInfo();
if (value == null) return appInfo;
try {
Intent intent = Intent.parseUri(value, 0);
int iconResId = intent.getStringExtra("iconResName") != null ?
mResources.getIdentifier(intent.getStringExtra("iconResName"),
"drawable", mContext.getPackageName()) : 0;
if (iconResId != 0) {
appInfo.icon = mResources.getDrawable(iconResId);
} else if (intent.hasExtra("icon")) {
final String appIconPath = intent.getStringExtra("icon");
if (appIconPath != null) {
File f = new File(appIconPath);
if (f.exists() && f.canRead()) {
FileInputStream fis = new FileInputStream(f);
appInfo.icon = new BitmapDrawable(mResources, BitmapFactory.decodeStream(fis));
fis.close();
}
}
}
int mode = intent.getIntExtra("mode", MODE_APP);
if (mode == MODE_APP) {
ComponentName cn = intent.getComponent();
ActivityInfo ai = mPackageManager.getActivityInfo(cn, 0);
appInfo.name = (ai.loadLabel(mPackageManager).toString());
if (appInfo.icon == null) {
appInfo.icon = ai.loadIcon(mPackageManager);
}
} else if (mode == MODE_SHORTCUT) {
appInfo.name = intent.getStringExtra("prefLabel");
}
return appInfo;
} catch (Exception e) {
e.printStackTrace();
return appInfo;
}
}
示例9: getBitmap
import android.graphics.BitmapFactory; //導入方法依賴的package包/類
@SuppressWarnings("unused")
private static Bitmap getBitmap(InputStream fs) {
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = 1;
Bitmap imgBitmap = BitmapFactory.decodeStream(fs, null, opts);
if (imgBitmap != null) {
int width = imgBitmap.getWidth();
int height = imgBitmap.getHeight();
imgBitmap = Bitmap.createScaledBitmap(imgBitmap, width, height,
true);
}
return imgBitmap;
}
示例10: readBitmap
import android.graphics.BitmapFactory; //導入方法依賴的package包/類
private static Bitmap readBitmap(InputStream pInputStream) {
if (pInputStream == null) {
return null;
}
try {
return BitmapFactory.decodeStream(pInputStream);
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
close(pInputStream);
}
}
示例11: getImageDimensions
import android.graphics.BitmapFactory; //導入方法依賴的package包/類
public static int[] getImageDimensions(Context context, Uri uri) {
int[] dimensions = new int[]{0, 0};
try {
InputStream is = context.getContentResolver().openInputStream(uri);
//try exif
String mimeType = MediaType.getMimeType(context, uri);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
&& MediaType.doesSupportExifMimeType(mimeType)
&& is != null) {
ExifInterface exif = new ExifInterface(is);
if (exif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH) != null
&& exif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH) != null) {
int width = (int) ExifUtil.getCastValue(exif, ExifInterface.TAG_IMAGE_WIDTH);
int height = (int) ExifUtil.getCastValue(exif, ExifInterface.TAG_IMAGE_LENGTH);
if (width != 0 && height != 0) {
return new int[]{width, height};
}
}
}
//exif didn't work
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(is, new Rect(0, 0, 0, 0), options);
dimensions[0] = options.outWidth;
dimensions[1] = options.outHeight;
if (is != null) {
is.close();
}
} catch (IOException e) {
e.printStackTrace();
}
return dimensions;
}
示例12: compressImage
import android.graphics.BitmapFactory; //導入方法依賴的package包/類
public static Bitmap compressImage(Bitmap image) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 100, baos);
int options = 100;
while (baos.toByteArray().length / 1024 > 100) {
options -= 10;
if (options > 0) {
baos.reset();
image.compress(Bitmap.CompressFormat.JPEG, options, baos);
}
}
ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());
return BitmapFactory.decodeStream(isBm, null, null);
}
示例13: a
import android.graphics.BitmapFactory; //導入方法依賴的package包/類
private Drawable a(String str, Context context) {
IOException e;
Drawable createFromStream;
try {
InputStream open = context.getApplicationContext().getAssets().open(str);
if (open == null) {
return null;
}
if (str.endsWith(".9.png")) {
Bitmap decodeStream = BitmapFactory.decodeStream(open);
if (decodeStream == null) {
return null;
}
byte[] ninePatchChunk = decodeStream.getNinePatchChunk();
NinePatch.isNinePatchChunk(ninePatchChunk);
return new NinePatchDrawable(decodeStream, ninePatchChunk, new Rect(), null);
}
createFromStream = Drawable.createFromStream(open, str);
try {
open.close();
return createFromStream;
} catch (IOException e2) {
e = e2;
e.printStackTrace();
return createFromStream;
}
} catch (IOException e3) {
IOException iOException = e3;
createFromStream = null;
e = iOException;
e.printStackTrace();
return createFromStream;
}
}
示例14: getImageToShare
import android.graphics.BitmapFactory; //導入方法依賴的package包/類
public static void getImageToShare(Context mContext, ImageView imageView) {
//1.拿到string
String imgString = ShareUtil.getString(mContext, "image_title", "");
if (!imgString.equals("")) {
//2.利用Base64將我們string轉換
byte[] byteArray = Base64.decode(imgString, Base64.DEFAULT);
ByteArrayInputStream byStream = new ByteArrayInputStream(byteArray);
//3.生成bitmap
Bitmap bitmap = BitmapFactory.decodeStream(byStream);
imageView.setImageBitmap(bitmap);
}
}
示例15: restoreFromCache
import android.graphics.BitmapFactory; //導入方法依賴的package包/類
public Bitmap restoreFromCache(Card card, Cache cache) throws IOException {
String fileName = cache.getCacheLocation(getFileName(card));
FileInputStream in = context.openFileInput(fileName);
Bitmap out = BitmapFactory.decodeStream(in);
in.close();
return out;
}