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


Java BitmapRegionDecoder.decodeRegion方法代码示例

本文整理汇总了Java中android.graphics.BitmapRegionDecoder.decodeRegion方法的典型用法代码示例。如果您正苦于以下问题:Java BitmapRegionDecoder.decodeRegion方法的具体用法?Java BitmapRegionDecoder.decodeRegion怎么用?Java BitmapRegionDecoder.decodeRegion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.BitmapRegionDecoder的用法示例。


在下文中一共展示了BitmapRegionDecoder.decodeRegion方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decodeRegion

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
private static Bitmap decodeRegion(BitmapRegionDecoder decoder, Rect rect, BitmapFactory.Options options) {
    Bitmap bitmap = null;
    options.inPreferredConfig = Constants.PREFERRED_CONFIG;
    if (options.inPreferredConfig == Bitmap.Config.RGB_565) {
        options.inDither = true;
    }
    synchronized (sDecodeLock) {
        bitmap = decoder.decodeRegion(rect, options);
    }
    if (options.inBitmap != null) {
        if (bitmap != options.inBitmap) {
            Log.d("LocalRunnable", "decodeRegion inBitmap failed");
            options.inBitmap.recycle();
        } else {
            Log.d("LocalRunnable", "decodeRegion inBitmap success");
        }
    }
    return bitmap;
}
 
开发者ID:qii,项目名称:BitmapView,代码行数:20,代码来源:LocalRunnable.java

示例2: loadCroppedBitmap

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:fouady,项目名称:DocuTranslator,代码行数:35,代码来源:BitmapUtils.java

示例3: buildBlocksFromImage

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
public void buildBlocksFromImage(InputStream imageStream) {

        this.originalImageInputStream = imageStream;

        BitmapRegionDecoder brp = null;

        try {
            brp = BitmapRegionDecoder.newInstance(imageStream, false);
        } catch (IOException e) {
            e.printStackTrace();
        }

        for (int row = 0; row < this.rowCount; row++) {
            for (int col = 0; col < this.columnCount; col++) {
                int left = col * subdivisionWidth, top = row * subdivisionWidth;
                int right = left + subdivisionWidth, bottom = top + subdivisionWidth;
                Bitmap region = brp.decodeRegion(new Rect(left, top, right, bottom), null);
                RgbColor averageColor = calculateAverageColor(region);
                Block bestBlock = Block.bestMatchedBlock(averageColor);
                this.setBlockAtIndices(row, col, bestBlock);
            }
        }

        return;
    }
 
开发者ID:bcaudell95,项目名称:HackISU3,代码行数:26,代码来源:BlockBitmap.java

示例4: buildBlocksFromImage

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
public void buildBlocksFromImage(InputStream imageStream) {

        this.originalImageInputStream = imageStream;

        BitmapRegionDecoder brp = null;

        try {
            brp = BitmapRegionDecoder.newInstance(imageStream, false);
        } catch (IOException e) {
            e.printStackTrace();
        }

        for(int row = 0;row<this.rowCount;row++) {
            for(int col=0;col<this.columnCount; col++) {
                int left = col*subdivisionWidth, top = row*subdivisionWidth;
                int right = left + subdivisionWidth, bottom = top  + subdivisionWidth;
                Bitmap region = brp.decodeRegion(new Rect(left, top, right, bottom), null);
                RgbColor averageColor = calculateAverageColor(region);
                Block bestBlock = Block.bestMatchedBlock(averageColor);
                this.setBlockAtIndices(row, col, bestBlock);
            }
        }

        return;
    }
 
开发者ID:bcaudell95,项目名称:HackISU,代码行数:26,代码来源:BlockBitmap.java

示例5: readBitmap

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
private Bitmap readBitmap (final int scalePercentage, final Rect cropRect) throws IOException {
	if (100 % scalePercentage != 0) throw new IllegalArgumentException("scalePercentage " + scalePercentage + " is not a int ratio.");
	final Options opts = new Options();
	opts.inPurgeable = true;
	opts.inInputShareable = true;
	opts.inSampleSize = 100 / scalePercentage;

	if (cropRect != null) {
		final BitmapRegionDecoder dec = BitmapRegionDecoder.newInstance(openFileDescriptor().getFileDescriptor(), true);
		try {
			return dec.decodeRegion(cropRect, opts);
		}
		finally {
			dec.recycle();
		}
	}

	return BitmapFactory.decodeFileDescriptor(openFileDescriptor().getFileDescriptor(), null, opts);
}
 
开发者ID:haku,项目名称:Onosendai,代码行数:20,代码来源:ImageMetadata.java

示例6: cropImage

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
public static Bitmap cropImage(String path, int top, int left, int right, int bottom) throws IOException {
    // only accept file path.
    if(path.startsWith("file:/")) {
        path = path.substring("file:/".length());
    }
    BitmapRegionDecoder regionDecoder = BitmapRegionDecoder.newInstance(path, false);
    Rect rect = new Rect(left, top, right, bottom);
    return regionDecoder.decodeRegion(rect, new BitmapFactory.Options());
}
 
开发者ID:cuonghuynhvan,项目名称:react-native-camera-android-simple,代码行数:10,代码来源:ImageUtils.java

示例7: getHotseatPalette

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.N)
private Palette getHotseatPalette() {
    WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
    if (AndroidVersion.isAtLeastNougat) {
        try (ParcelFileDescriptor fd = wallpaperManager
                .getWallpaperFile(WallpaperManager.FLAG_SYSTEM)) {
            BitmapRegionDecoder decoder = BitmapRegionDecoder
                    .newInstance(fd.getFileDescriptor(), false);
            int height = decoder.getHeight();
            Rect decodeRegion = new Rect(0, (int) (height * (1f - HOTSEAT_FRACTION)),
                    decoder.getWidth(), height);
            Bitmap bitmap = decoder.decodeRegion(decodeRegion, null);
            decoder.recycle();
            if (bitmap != null) {
                return Palette.from(bitmap).clearFilters().generate();
            }
        } catch (IOException | NullPointerException e) {
            e.printStackTrace();
        }
    }

    Bitmap wallpaper = ((BitmapDrawable) wallpaperManager.getDrawable()).getBitmap();
    return Palette.from(wallpaper)
            .setRegion(0, (int) (wallpaper.getHeight() * (1f - HOTSEAT_FRACTION)),
                    wallpaper.getWidth(), wallpaper.getHeight())
            .clearFilters()
            .generate();
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:29,代码来源:ColorExtractionService.java

示例8: getStatusBarPalette

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.N)
private Palette getStatusBarPalette() {
    WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
    int statusBarHeight = getResources()
            .getDimensionPixelSize(R.dimen.status_bar_height);

    if (AndroidVersion.isAtLeastNougat) {
        try (ParcelFileDescriptor fd = wallpaperManager
                .getWallpaperFile(WallpaperManager.FLAG_SYSTEM)) {
            BitmapRegionDecoder decoder = BitmapRegionDecoder
                    .newInstance(fd.getFileDescriptor(), false);
            Rect decodeRegion = new Rect(0, 0,
                    decoder.getWidth(), statusBarHeight);
            Bitmap bitmap = decoder.decodeRegion(decodeRegion, null);
            decoder.recycle();
            if (bitmap != null) {
                return Palette.from(bitmap).clearFilters().generate();
            }
        } catch (IOException | NullPointerException e) {
            e.printStackTrace();
        }
    }

    Bitmap wallpaper = ((BitmapDrawable) wallpaperManager.getDrawable()).getBitmap();
    return Palette.from(wallpaper)
            .setRegion(0, 0, wallpaper.getWidth(), statusBarHeight)
            .clearFilters()
            .generate();
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:30,代码来源:ColorExtractionService.java

示例9: getBitmapWith

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
public Bitmap getBitmapWith(InputStream inputStream, Rect rect) {
    try {
        BitmapRegionDecoder bitmapRegionDecoder = BitmapRegionDecoder.newInstance(inputStream, false);
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPreferredConfig = Bitmap.Config.RGB_565;
        Bitmap bitmap = bitmapRegionDecoder.decodeRegion(rect, options);
        return bitmap;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:jopenbox,项目名称:android-lite-utils,代码行数:13,代码来源:BitmapUtils.java

示例10: decodeRegion

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
/**
 * Acquire a read lock to prevent decoding overlapping with recycling, then check the pool still
 * exists and acquire a decoder to load the requested region. There is no check whether the pool
 * currently has decoders, because it's guaranteed to have one decoder after {@link #init(Context, Uri)}
 * is called and be null once {@link #recycle()} is called. In practice the view can't call this
 * method until after {@link #init(Context, Uri)}, so there will be no blocking on an empty pool.
 */
@Override
public Bitmap decodeRegion(Rect sRect, int sampleSize) {
    debug("Decode region " + sRect + " on thread " + Thread.currentThread().getName());
    if (sRect.width() < imageDimensions.x || sRect.height() < imageDimensions.y) {
        lazyInit();
    }
    decoderLock.readLock().lock();
    try {
        if (decoderPool != null) {
            BitmapRegionDecoder decoder = decoderPool.acquire();
            try {
                // Decoder can't be null or recycled in practice
                if (decoder != null && !decoder.isRecycled()) {
                    BitmapFactory.Options options = new BitmapFactory.Options();
                    options.inSampleSize = sampleSize;
                    options.inPreferredConfig = bitmapConfig;
                    Bitmap bitmap = decoder.decodeRegion(sRect, options);
                    if (bitmap == null) {
                        throw new RuntimeException("Skia image decoder returned null bitmap - image format may not be supported");
                    }
                    return bitmap;
                }
            } finally {
                if (decoder != null) {
                    decoderPool.release(decoder);
                }
            }
        }
        throw new IllegalStateException("Cannot decode region after decoder has been recycled");
    } finally {
        decoderLock.readLock().unlock();
    }
}
 
开发者ID:alphater,项目名称:garras,代码行数:41,代码来源:SkiaPooledImageRegionDecoder.java

示例11: decodeRegionCrop

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
@TargetApi(10)
private Bitmap decodeRegionCrop(ImageViewTouch cropImage) {
    int width = initWidth > initHeight ? initHeight : initWidth;
    int screenWidth = DemoApplication.getApp().getScreenWidth();
    float scale = cropImage.getScale() / getImageRadio();
    RectF rectf = cropImage.getBitmapRect();
    int left = -(int) (rectf.left * width / screenWidth / scale);
    int top = -(int) (rectf.top * width / screenWidth / scale);
    int right = left + (int) (width / scale);
    int bottom = top + (int) (width / scale);
    Rect rect = new Rect(left, top, right, bottom);
    InputStream is = null;
    System.gc();
    Bitmap croppedImage = null;
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        oriBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        is = new ByteArrayInputStream(baos.toByteArray());
        BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(is, false);
        croppedImage = decoder.decodeRegion(rect, new BitmapFactory.Options());
    } catch (Throwable e) {

    } finally {
        IOUtil.closeStream(is);
    }
    return croppedImage;
}
 
开发者ID:macyuan,项目名称:TAG,代码行数:28,代码来源:CropPhotoActivity.java

示例12: onFutureDone

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
@Override
public void onFutureDone(Future<BitmapRegionDecoder> future) {
    BitmapRegionDecoder decoder = future.get();
    if (decoder == null) return;
    int width = decoder.getWidth();
    int height = decoder.getHeight();
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = BitmapUtils.computeSampleSize(
            (float) SIZE_BACKUP / Math.max(width, height));
    Bitmap bitmap = decoder.decodeRegion(new Rect(0, 0, width, height), options);
    mHandler.sendMessage(mHandler.obtainMessage(
            MSG_UPDATE_IMAGE, new ImageBundle(decoder, bitmap)));
}
 
开发者ID:asm-products,项目名称:nexus-gallery,代码行数:14,代码来源:SinglePhotoDataAdapter.java

示例13: getTileWithoutReusingBitmap

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
private Bitmap getTileWithoutReusingBitmap(
        int level, int x, int y, int tileSize) {
    int t = tileSize << level;
    Rect wantRegion = new Rect(x, y, x + t, y + t);

    BitmapRegionDecoder regionDecoder;
    Rect overlapRegion;

    synchronized (this) {
        regionDecoder = mRegionDecoder;
        if (regionDecoder == null) return null;
        overlapRegion = new Rect(0, 0, mImageWidth, mImageHeight);
        Utils.assertTrue(overlapRegion.intersect(wantRegion));
    }

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Config.ARGB_8888;
    options.inPreferQualityOverSpeed = true;
    options.inSampleSize =  (1 << level);
    Bitmap bitmap = null;

    // In CropImage, we may call the decodeRegion() concurrently.
    synchronized (regionDecoder) {
        bitmap = regionDecoder.decodeRegion(overlapRegion, options);
    }

    if (bitmap == null) {
        Log.w(TAG, "fail in decoding region");
    }

    if (wantRegion.equals(overlapRegion)) return bitmap;

    Bitmap result = Bitmap.createBitmap(tileSize, tileSize, Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    canvas.drawBitmap(bitmap,
            (overlapRegion.left - wantRegion.left) >> level,
            (overlapRegion.top - wantRegion.top) >> level, null);
    return result;
}
 
开发者ID:asm-products,项目名称:nexus-gallery,代码行数:40,代码来源:TileImageViewAdapter.java

示例14: buildTimeLine

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
private void buildTimeLine() {
    Bitmap source = BitmapFactory.decodeResource(getActivity().getResources(), R.drawable.time_line_6_am);
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    source.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
    try {
        BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()), true);
        imageLength = decoder.getHeight();
        int regionCount = 3;
        int height = decoder.getHeight() / regionCount;
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        for (int i = 0; i < 3; i++) {
            TimeLineLayout[i].removeAllViews();
        }
        for (int i = 0; i < regionCount; i++) {
            Bitmap bitmap;
            if (i == regionCount - 1) {
                bitmap = decoder.decodeRegion(new Rect(0, i * height, decoder.getWidth(), decoder.getHeight()), null);
            } else {
                bitmap = decoder.decodeRegion(new Rect(0, i * height, decoder.getWidth(), (i + 1) * height), null);
            }
            for (int j = 0; j < 3; j++) {
                ImageView imageView = new ImageView(getActivity());
                imageView.setImageBitmap(bitmap);
                imageView.setLayoutParams(params);
                TimeLineLayout[j].addView(imageView);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:UtopiaGroup,项目名称:Utopia,代码行数:32,代码来源:ViewPagerFragment2.java

示例15: setImageViewSrc

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
public void setImageViewSrc(String link) {
    try {
        FileInputStream fin = openFileInput(link);
        //获取文件长度
        int length = fin.available();
        byte[] in = new byte[length];
        fin.read(in);
        BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(new ByteArrayInputStream(in), true);
        Bitmap bitmap = decoder.decodeRegion(new Rect(0, 0, decoder.getWidth(), decoder.getHeight()), null);
        imageView.setImageBitmap(bitmap);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:UtopiaGroup,项目名称:Utopia,代码行数:15,代码来源:ArticleReadingActivity.java


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