BitmapFactory decodeResource - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for BitmapFactory decodeResource method.

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:getIdentifier, decodeResource
  public static Bitmap decodeResource(final Context context, final String resourceName) {
    Resources resources = context.getResources();
    String packageName = context.getPackageName();
    BitmapFactory.Options opt = new BitmapFactory.Options();
    opt.inMutable = true;
    return BitmapFactory.decodeResource(resources,
        resources.getIdentifier(resourceName, "drawable", packageName), opt);
  } 
 
  /** https://developer.android.com/training/displaying-bitmaps/load-bitmap.html */ 
  private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth,
      int reqHeight) {
    // Raw height and width of image 
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;
 
    if (height > reqHeight || width > reqWidth) {
 
      // Calculate ratios of height and width to requested height and width 
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:getDisplayMetrics, decodeResource
          int thumbImageNormal,
          int thumbImagePressed) {
 
        final Resources res = ctx.getResources();
 
        mImageNormal = BitmapFactory.decodeResource(res, thumbImageNormal);
        mImagePressed = BitmapFactory.decodeResource(res, thumbImagePressed);
 
        // If any of the attributes are set, toggle bitmap off 
        if (thumbRadiusDP == -1 && thumbColorNormal == -1 && thumbColorPressed == -1) {
 
            mUseBitmap = true;
 
        } else { 
 
            mUseBitmap = false;
 
            // If one of the attributes are set, but the others aren't, set the 
            // attributes to default 
            if (thumbRadiusDP == -1)

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:getIdentifier, decodeResource
   * (all output) 
   * @return true on success 
   */ 
  private boolean loadResourceTexture(String name, int[] result) {
    /* find the resource */ 
    int resourceId = resources.getIdentifier(name, "drawable", "org.xcsoarte");
    if (resourceId == 0) {
      resourceId = resources.getIdentifier(name, "drawable",
                                           "org.xcsoarte.testing"); 
      if (resourceId == 0)
        return false; 
    } 
 
    /* load the Bitmap from the resource */ 
    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inScaled = false;
 
    Bitmap bmp = BitmapFactory.decodeResource(resources, resourceId, opts);
 
    return BitmapUtil.bitmapToOpenGL(bmp, result);

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
		 
		if(drawable != null && !drawable.isRecycled()) {
			return drawable;
		} 
 
		Bitmap bmp = BitmapFactory.decodeResource(resources, resourceId);
		 
		drawable = createDrawable(bmp, key);
		 
		if(tileX) {
			drawable.setTileModeX(Shader.TileMode.REPEAT);
		} 
		 
		if(tileY) {
			drawable.setTileModeY(Shader.TileMode.REPEAT);
		} 
		 
		addToCache(key, drawable, eternal);
		 
		return drawable;			

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
This code example shows how to use the following methods:getIdentifier, decodeResource
    } 
 
    public void initStockBatteryColor(Context context) {
        try { 
            final Resources res = context.getResources();
            final int resId = res.getIdentifier(
                    "stat_sys_battery_100", "drawable", "com.android.systemui"); 
            if (resId != 0) {
                final Bitmap b = BitmapFactory.decodeResource(res, resId);
                final int x = b.getWidth() / 2;
                final int y = b.getHeight() / 2;
                mStockBatteryColor = b.getPixel(x, y);
            } 
            if (DEBUG) log("mStockBatteryColor = " + 
                    ((mStockBatteryColor != null ) ? Integer.toHexString(mStockBatteryColor) : "NULL"));
        } catch (Throwable t) {
            log("Error initializing stock battery color: " + t.getMessage());
        } 
    } 
 
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:getDisplayMetrics, decodeResource
	 * http://stackoverflow.com/questions/18335642/how-to-draw-text-in-default-marker-of-google-map-v2?lq=1 
	 */ 
	private static Bitmap drawTextToBitmap(Context gContext, int gResId,
			String gText) {
		Resources resources = gContext.getResources();
		float scale = resources.getDisplayMetrics().density;
		Bitmap bitmap = BitmapFactory.decodeResource(resources, gResId);
 
		android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig();
		if (bitmapConfig == null) {
			bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;
		} 
		bitmap = bitmap.copy(bitmapConfig, true);
 
		Canvas canvas = new Canvas(bitmap);
		Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
		paint.setColor(Color.BLACK);
		paint.setTextSize((int) (15 * scale));
		paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);
 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related BitmapFactory decodeResource Questions & Answers:

decodeResource Method Overview
Synonym for opening the given resource and calling decodeResourceStream(Resources, TypedValue, InputStream, Rect, BitmapFactory.Options).
See Code Examples for other Android BitmapFactory Methods: