當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。