BitmapUtils.java 文件源码

java
阅读 33 收藏 0 点赞 0 评论 0

项目:DocuTranslator 作者:
/**
 * Loads cropped bitmap from the disk.
 * @param region Region to be cropped
 * @param imageWidth Width of original image
 * @param imageHeight Height of original image
 * @param rotation rotation applied to width and height
 * @param imagePath Path to the image on disk.
 * @param opts Options for loading the image
 * @return
 */
public static Bitmap loadCroppedBitmap(
        Rect region, 
        int imageWidth, 
        int imageHeight,
        int rotation,
        String imagePath, 
        BitmapFactory.Options opts){

    Bitmap bmap = null;
    try {

        BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(imagePath, false);

        // inversely rotate the crop region to undo the rotation applied to image width and height
        int invRotation = (-rotation + 360) %360;
        Rect rect = applyRotation(invRotation, imageWidth, imageHeight, region);

        // Load the cropped bitmap
        bmap = decoder.decodeRegion(rect, opts);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return bmap;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号