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


Java BitmapRegionDecoder.newInstance方法代码示例

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


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

示例1: init

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.GINGERBREAD_MR1)
@Override
public Point init(Context context, Uri uri) throws Exception {
  Log.w(TAG, "Init!");
  if (!PartAuthority.isLocalUri(uri)) {
    passthrough = new SkiaImageRegionDecoder();
    return passthrough.init(context, uri);
  }

  MasterSecret masterSecret = KeyCachingService.getMasterSecret(context);

  if (masterSecret == null) {
    throw new IllegalStateException("No master secret available...");
  }

  InputStream inputStream = PartAuthority.getAttachmentStream(context, masterSecret, uri);

  this.bitmapRegionDecoder = BitmapRegionDecoder.newInstance(inputStream, false);
  inputStream.close();

  return new Point(bitmapRegionDecoder.getWidth(), bitmapRegionDecoder.getHeight());
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:23,代码来源:AttachmentRegionDecoder.java

示例2: intercept

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
@Override
public BitmapRegionDecoder intercept(Chain chain) throws IOException {
    final Uri uri = chain.uri();
    BitmapRegionDecoder decoder = chain.chain(uri);
    if (decoder != null){
        return decoder;
    }

    if (UriUtil.isNetworkUri(uri)){
        if (BuildConfig.DEBUG) {
            Log.d("NetworkInterceptor", "从我这加载");
        }
        File file = processFile(uri.toString());
        try {
            //InputStream inputStream = processBitmap(uri.toString());
            return BitmapRegionDecoder.newInstance(new FileInputStream(file),false);
        } catch (IOException e) {
            //e.printStackTrace();
            return Interceptors.fixJPEGDecoder(file,e);
        }
    }
    return null;
}
 
开发者ID:EvilBT,项目名称:HDImageView,代码行数:24,代码来源:NetworkInterceptor.java

示例3: fixJPEGDecoder

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
public static BitmapRegionDecoder fixJPEGDecoder(File file, IOException e) throws IOException {

        if (file == null || !file.exists()){
            throw e;
        }

        Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(),new BitmapFactory.Options());
        if (bitmap == null) {
            if (BuildConfig.DEBUG) {
                Log.d(TAG, "加载缓存失败:" + file.getAbsolutePath());
            }
            throw e;
        }
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 85, baos);
        BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(baos.toByteArray(),0,baos.size(),false);
        bitmap.recycle();
        if (BuildConfig.DEBUG) {
            Log.d(TAG, "fixJPEGDecoder: 从此处修复Bitmap");
        }
        return decoder;
    }
 
开发者ID:EvilBT,项目名称:HDImageView,代码行数:23,代码来源:Interceptors.java

示例4: intercept

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
@Override
public BitmapRegionDecoder intercept(Chain chain) throws IOException {
    final Uri uri = chain.uri();
    BitmapRegionDecoder decoder = chain.chain(uri);
    if (decoder != null){
        return decoder;
    }


    if (UriUtil.isLocalFileUri(uri)){
        File file = new File(uri.getPath());
        if (BuildConfig.DEBUG) {
            Log.d("FileInterceptor", "从我这加载");
        }
        try {
            return BitmapRegionDecoder.newInstance(new FileInputStream(file.toString()),false);
        } catch (IOException e) {
            return Interceptors.fixJPEGDecoder(file,e);
        }
    }
    return null;
}
 
开发者ID:EvilBT,项目名称:HDImageView,代码行数:23,代码来源:FileInterceptor.java

示例5: createBitmapRegionDecoder

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
public static BitmapRegionDecoder createBitmapRegionDecoder(
        ThreadPool.JobContext jc, byte[] bytes, int offset, int length,
        boolean shareable) {
    if (offset < 0 || length <= 0 || offset + length > bytes.length) {
        throw new IllegalArgumentException(String.format(
                "offset = %s, length = %s, bytes = %s",
                offset, length, bytes.length));
    }

    try {
        return BitmapRegionDecoder.newInstance(
                bytes, offset, length, shareable);
    } catch (Throwable t)  {
        Log.w(TAG, t);
        return null;
    }
}
 
开发者ID:mayurkaul,项目名称:medialibrary,代码行数:18,代码来源:DecodeUtils.java

示例6: getTileImage

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
public TileImage getTileImage() {
    if (mIsGif) {
        return null;
    }

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(this.mFilePath, options);
    int width = options.outWidth;
    int height = options.outHeight;

    if (width <= 0 || height <= 0) {
        return null;
    }

    try {
        BitmapRegionDecoder bitmapRegionDecoder = BitmapRegionDecoder.newInstance(this.mFilePath, false);
        return TileImage.newInstance(width, height, OrientationInfoUtility.getOrientation(this.mFilePath), bitmapRegionDecoder);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:qii,项目名称:BitmapView,代码行数:24,代码来源:BitmapSource.java

示例7: ViewportWithCache

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
ViewportWithCache(Point sceneSize, String filepath) throws IOException {
    mSceneSize = sceneSize;

    mVisibleViewport = new Viewport();
    mVisibleViewport.CONFIG = DEFAULT_CONFIG;

    mCachedBitmap = null;
    mCachedWindow = null;

    mDecoder = BitmapRegionDecoder.newInstance(filepath, false);

    // TODO Create the sample image, should calculate DOWN_SAMPLE_SHIFT here
    Options opts = new Options();
    opts.inPreferredConfig = DEFAULT_CONFIG;
    opts.inSampleSize = (1 << DOWN_SAMPLE_SHIFT);
    mSampledBitmap = BitmapFactory.decodeFile(filepath, opts);
}
 
开发者ID:LouisPeng,项目名称:HugePhotoView,代码行数:18,代码来源:ViewportWithCache.java

示例8: createBitmapRegionDecoder

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
public static BitmapRegionDecoder createBitmapRegionDecoder(
        JobContext jc, byte[] bytes, int offset, int length,
        boolean shareable) {
    if (offset < 0 || length <= 0 || offset + length > bytes.length) {
        throw new IllegalArgumentException(String.format(
                "offset = %s, length = %s, bytes = %s",
                offset, length, bytes.length));
    }

    try {
        return BitmapRegionDecoder.newInstance(
                bytes, offset, length, shareable);
    } catch (Throwable t)  {
        WLog.w(TAG, t);
        return null;
    }
}
 
开发者ID:jituo666,项目名称:WoTu,代码行数:18,代码来源:BitmapDecoder.java

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: setBitmap

import android.graphics.BitmapRegionDecoder; //导入方法依赖的package包/类
/**
 * Set the Background bitmap
 *
 * @param inputStream InputStream to the raw data of the bitmap
 */
public void setBitmap(InputStream inputStream) throws IOException {
  FlushedInputStream fixedInput = new FlushedInputStream(inputStream);
  BitmapFactory.Options opt = new BitmapFactory.Options();
  decoder = BitmapRegionDecoder.newInstance(fixedInput, false);
  fixedInput.reset();
  // Grab the bounds of the background bitmap
  opt.inPreferredConfig = DEFAULT_CONFIG;
  opt.inJustDecodeBounds = true;
  GameLog.d(TAG, "Decode inputStream for Background Bitmap");
  BitmapFactory.decodeStream(fixedInput, null, opt);
  fixedInput.reset();
  backgroundSize.set(opt.outWidth, opt.outHeight);
  GameLog.d(TAG, "Background Image: w=" + opt.outWidth + " h=" + opt.outHeight);
  // Create the low resolution background
  opt.inJustDecodeBounds = false;
  opt.inSampleSize = 1 << sampleSize;
  lowResBitmap = BitmapFactory.decodeStream(fixedInput, null, opt);
  GameLog.d(TAG, "Low Res Image: w=" + lowResBitmap.getWidth() + " h=" + lowResBitmap.getHeight());
  // Initialize cache
  if (cachedBitmap.getState() == CacheState.NOT_INITIALIZED) {
    synchronized (cachedBitmap) {
      cachedBitmap.setState(CacheState.IS_INITIALIZED);
    }
  }
}
 
开发者ID:micabytes,项目名称:lib_game,代码行数:31,代码来源:BitmapSurfaceRenderer.java

示例14: 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

示例15: 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


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