Android BitmapFactory.Options - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android BitmapFactory.Options class.

This code example shows how to use the following methods:decodeByteArray
     * @param image 
     * @param sampleSize 
     * @return bitmap or null if read fails 
     */ 
    public static Bitmap getBitmap(final byte[] image, int sampleSize) {
        final Options options = new Options();
        options.inDither = false;
        options.inSampleSize = sampleSize;
        return BitmapFactory.decodeByteArray(image, 0, image.length, options);
    } 
 
    /** 
     * Get scale for image of size and max height/width 
     * 
     * @param size 
     * @param width 
     * @param height 
     * @return scale 
     */ 
    public static int getScale(Point size, int width, int height) {
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:decodeFile
        } 
    } 
 
    public static Bitmap requestDecode(JobContext jc, final String filePath,
            Options options) {
        if (options == null) options = new Options();
        jc.setCancelListener(new DecodeCanceller(options));
        return ensureGLCompatibleBitmap( 
                BitmapFactory.decodeFile(filePath, options));
    } 
 
    public static Bitmap requestDecode(JobContext jc, FileDescriptor fd, Options options) {
        if (options == null) options = new Options();
        jc.setCancelListener(new DecodeCanceller(options));
        return ensureGLCompatibleBitmap( 
                BitmapFactory.decodeFileDescriptor(fd, null, options));
    } 
 
    public static Bitmap requestDecode(JobContext jc, byte[] bytes,
            Options options) {
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
This code example shows how to use the following methods:decodeFileDescriptor
     * @param imagePath 
     * @param sampleSize 
     * @return bitmap or null if read fails 
     */ 
    public static Bitmap getBitmap(final String imagePath, int sampleSize) {
        final Options options = new Options();
        options.inDither = false;
        options.inSampleSize = sampleSize;
 
        RandomAccessFile file = null;
        try { 
            file = new RandomAccessFile(imagePath, "r");
            return BitmapFactory.decodeFileDescriptor(file.getFD(), null,
                    options);
        } catch (IOException e) {
            Log.d(TAG, e.getMessage(), e);
            return null; 
        } finally { 
            if (file != null)
                try { 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:decodeResource
			return ShortcutIconResource.fromContext(IconPack.this,
                    mThumbs.get(position));
		} 
		@Override 
		public Object getItem(int position) {
		    Options opts=new BitmapFactory.Options();
		    opts.inPreferredConfig=Bitmap.Config.ARGB_8888;
		    return BitmapFactory.decodeResource(mContext.getResources(), mThumbs.get(position), opts);
		} 
 
		@Override 
		public long getItemId(int position) {
			return position;
		} 
 
		@Override 
		public View getView(int position, View convertView, ViewGroup parent) {
            ImageView imageView;
            if (convertView == null) {
                imageView = new ImageView(mContext);
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:decodeResource, getClass
 
    private static class New extends UnscaledBitmapOperations { 
 
        @Override 
        Bitmap load(Resources resources, int resId, Options options) {
            if (options == null) options = new BitmapFactory.Options();
            try { 
                Class<?> c = options.getClass();
                Field isScaledField = c.getDeclaredField("isScaled");
                isScaledField.setBoolean(c, true);
            } 
            catch (Throwable e) {
                System.err.println(e);
            } 
            return BitmapFactory.decodeResource(resources, resId, options);
        } 
 
    } 
 
    abstract Bitmap load(Resources resources, int resId, BitmapFactory.Options options);
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:decodeFile
    /** 
     * Get the size of a bitmap from disk 
     * @param absoluteFileName 
     */ 
    public static BitmapSize getBitmapSizeFromFile(String absoluteFileName) {
		Options opts = new Options();
		opts.inJustDecodeBounds = true;
		BitmapFactory.decodeFile(absoluteFileName, opts);
		return new BitmapSize(opts.outWidth, opts.outHeight);
    } 
     
	public static void writeBitmapInFile(String absoluteFileName, Bitmap bitmap) throws IOException {
		writeBitmapInFile(new File(absoluteFileName), bitmap);
	} 
	 
	public static void writeBitmapInFile(String absoluteFileName, Bitmap bitmap, CompressFormat compressFormat) throws IOException {
		writeBitmapInFile(new File(absoluteFileName), bitmap, compressFormat, null);
	} 
	 
	public static void writeBitmapInFile(File file, Bitmap bitmap) throws IOException {
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:decodeByteArray
     * @return The initialized BitmapDrawable. 
     */ 
    public static BitmapDrawable byteArrayToDrawable(byte[] image, Options opts, Context context) {
        if (opts == null) {
            Log.v(TAG, "opts is null, initializing without scaling");
            opts = new Options();
            opts.inScaled = false;
        } 
        Bitmap bmp = BitmapFactory.decodeByteArray(image, 0, image.length, opts);
        // bmp.setDensity(DisplayMetrics.DENSITY_HIGH); 
        return new BitmapDrawable(context.getResources(), bmp);
    } 
 
    /** 
     * Converts a byte array into a Bitmap, using the provided options. 
     * 
     * @param image The byte array representing the image. 
     * @param opts  The decoding options to use, or null if you'd like to use predefined 
     *              options (scaling will be not active). 
     * 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:decodeResource
            return false; 
        } 
    } 
 
    private Bitmap getResBitmap(int bmpResId) {
        Options opts = new Options();
        opts.inDither = false;
 
        Resources res = getResources();
        Bitmap bmp = BitmapFactory.decodeResource(res, bmpResId, opts);
 
        if (bmp == null && isInEditMode()) {
            // BitmapFactory.decodeResource doesn't work from the rendering 
            // library in Eclipse's Graphical Layout Editor. Use this workaround instead. 
 
            Drawable d = res.getDrawable(bmpResId);
            int w = d.getIntrinsicWidth();
            int h = d.getIntrinsicHeight();
            bmp = Bitmap.createBitmap(w, h, Config.ARGB_8888);
            Canvas c = new Canvas(bmp);
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:decodeResource
 
    /** 
     * Converts a bitmap resource ID to a valid Bitmap object. 
     */ 
    private Bitmap getResBitmap(int bmpResId) {
        Options opts = new Options();
        opts.inDither = false;
 
        Resources res = getResources();
        Bitmap bmp = BitmapFactory.decodeResource(res, bmpResId, opts);
 
        if (bmp == null && isInEditMode()) {
            Drawable d = res.getDrawable(bmpResId);
            int w = d.getIntrinsicWidth();
            int h = d.getIntrinsicHeight();
            bmp = Bitmap.createBitmap(w, h, Config.ARGB_8888);
            Canvas c = new Canvas(bmp);
            d.setBounds(0, 0, w - 1, h - 1);
            d.draw(c);
        } 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android BitmapFactory.Options Questions & Answers:

Other Android BitmapFactory.Options Examples

9:	
10:				// bimatp factory
11:				BitmapFactory.Options options = new BitmapFactory.Options();
12:	
13:				// downsizing image as it throws OutOfMemory Exception for larger
-
9:	
10:				// bimatp factory
11:				BitmapFactory.Options options = new BitmapFactory.Options();
12:	
13:				// downsizing image as it throws OutOfMemory Exception for larger

Read More

98:				File f = new File(filePath);
99:	
100:				BitmapFactory.Options o = new BitmapFactory.Options();
101:				o.inJustDecodeBounds = true;
102:				BitmapFactory.decodeStream(new FileInputStream(f), null, o);
-
98:				File f = new File(filePath);
99:	
100:				BitmapFactory.Options o = new BitmapFactory.Options();
101:				o.inJustDecodeBounds = true;
102:				BitmapFactory.decodeStream(new FileInputStream(f), null, o);
-
109:					scale *= 2;
110:	
111:				BitmapFactory.Options o2 = new BitmapFactory.Options();
112:				o2.inSampleSize = scale;
113:				return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
-
109:					scale *= 2;
110:	
111:				BitmapFactory.Options o2 = new BitmapFactory.Options();
112:				o2.inSampleSize = scale;
113:				return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);

Read More

53:	        btnClose = (Button) viewLayout.findViewById(R.id.btnClose);
54:	        
55:	        BitmapFactory.Options options = new BitmapFactory.Options();
56:	        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
57:	        Bitmap bitmap = BitmapFactory.decodeFile(_imagePaths.get(position), options);
-
53:	        btnClose = (Button) viewLayout.findViewById(R.id.btnClose);
54:	        
55:	        BitmapFactory.Options options = new BitmapFactory.Options();
56:	        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
57:	        Bitmap bitmap = BitmapFactory.decodeFile(_imagePaths.get(position), options);

Read More

See Code Examples for Android BitmapFactory.Options Methods: