当前位置: 首页>>代码示例>>Java>>正文


Java BitmapFactory.decodeStream方法代码示例

本文整理汇总了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;
}
 
开发者ID:guzhigang001,项目名称:Zxing,代码行数:21,代码来源:CaptureActivity.java

示例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);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:17,代码来源:BaseImageDecoder.java

示例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);
}
 
开发者ID:miLLlulei,项目名称:Accessibility,代码行数:18,代码来源:BitmapUtils.java

示例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;
}
 
开发者ID:Kaufland,项目名称:andcouchbaseentity,代码行数:27,代码来源:ImageUtil.java

示例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;
}
 
开发者ID:lovetomatoo,项目名称:RxReview,代码行数:15,代码来源:BitmapUtil.java

示例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);
}
 
开发者ID:stytooldex,项目名称:stynico,代码行数:13,代码来源:ImageUtils.java

示例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);
}
 
开发者ID:gaolhjy,项目名称:cniao5,代码行数:14,代码来源:ImageUtils.java

示例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;
    }
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:42,代码来源:AppPickerPreference.java

示例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;
}
 
开发者ID:ccfish86,项目名称:sctalk,代码行数:14,代码来源:FileUtil.java

示例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);
    }
}
 
开发者ID:zeng3234,项目名称:GrowingProject,代码行数:14,代码来源:AssetUtils.java

示例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;
}
 
开发者ID:kollerlukas,项目名称:Camera-Roll-Android-App,代码行数:39,代码来源:Util.java

示例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);
}
 
开发者ID:jeasinlee,项目名称:AndroidBasicLibs,代码行数:15,代码来源:ImageUtils.java

示例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;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:35,代码来源:AuthAgent.java

示例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);
    }
}
 
开发者ID:lijizhi,项目名称:studydemo,代码行数:13,代码来源:UtilTools.java

示例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;
}
 
开发者ID:AbyxBelgium,项目名称:Loyalty,代码行数:8,代码来源:CacheManager.java


注:本文中的android.graphics.BitmapFactory.decodeStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。