Java Code Examples for android.graphics.BitmapFactory#decodeResource()

The following examples show how to use android.graphics.BitmapFactory#decodeResource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SunRefreshView.java    From TLint with Apache License 2.0 6 votes vote down vote up
private void createBitmaps() {
    Logger.d("createBitmaps");
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Bitmap.Config.RGB_565;

    mSky = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.sky, options);
    mSky = Bitmap.createScaledBitmap(mSky, mScreenWidth, mSkyHeight, true);
    mTown =
            BitmapFactory.decodeResource(getContext().getResources(), R.drawable.buildings, options);
    mTown = Bitmap.createScaledBitmap(mTown, mScreenWidth, (int) (mScreenWidth * TOWN_RATIO), true);

    mSun = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.sun, options);
    mSun = Bitmap.createScaledBitmap(mSun, mSunSize, mSunSize, true);

    Logger.d("mTown:" + mTown.toString());
    Logger.d("mSky:" + mSky.toString());
    Logger.d("mSun:" + mSun.toString());
    isCreateBitmap = true;
}
 
Example 2
Source File: BearSceneView.java    From Depth with MIT License 6 votes vote down vote up
private void init() {
    renderables = new Renderable[17];
    Bitmap threeB = BitmapFactory.decodeResource(getResources(), R.mipmap.tree);
    addThree(threeB,getMeasuredWidth() * 0.18f, getMeasuredHeight() * -0.65f, 0.28f, 0.46f);
    addThree(threeB,getMeasuredWidth() * 0.6f, getMeasuredHeight() * -0.65f, 0.33f, 0.46f);
    addThree(threeB,getMeasuredWidth() * 0.45f, getMeasuredHeight() * -0.45f, 0.5f, 0.8f);
    addThree(threeB,getMeasuredWidth() * 0.13f, getMeasuredHeight() * -0.65f, 0.3f, 0.46f);
    addThree(threeB,getMeasuredWidth() * 0.83f, getMeasuredHeight() * -0.2f, 0.5f, 1f);
    addThree(threeB,getMeasuredWidth() * 0.02f, getMeasuredHeight() * -0.1f, 0.8f, 1f);
    addThree(threeB,getMeasuredWidth() * 0.18f, getMeasuredHeight() * 0.15f, 0.8f, 1f);
    addThree(threeB,getMeasuredWidth() * 0.7f, getMeasuredHeight() * -0.1f, 0.8f, 1f);

    Bitmap bear1 = BitmapFactory.decodeResource(getResources(), R.mipmap.bear_1);
    Bitmap bear2 = BitmapFactory.decodeResource(getResources(), R.mipmap.bear_2);
    Bitmap bear3 = BitmapFactory.decodeResource(getResources(), R.mipmap.bear_white);
    Bitmap stones = BitmapFactory.decodeResource(getResources(), R.drawable.stones);
    Bitmap smoke = BitmapFactory.decodeResource(getResources(), R.drawable.smoke);
    Bitmap grunge = BitmapFactory.decodeResource(getResources(), R.drawable.grunge);
    addFire(smoke, stones, getMeasuredWidth() * 0.61f, getMeasuredHeight() * 0.8f);
    addBear(getMeasuredWidth() * 0.636f, getMeasuredHeight() * 0.59f, bear1, bear2);
    addWhiteBear(getMeasuredWidth() * 0.44f, getMeasuredHeight() * 0.66f, bear3);
    setLayerType(View.LAYER_TYPE_HARDWARE, null);
    addGrunge(grunge);
}
 
Example 3
Source File: EmoticonsTextView.java    From FlyWoo with Apache License 2.0 6 votes vote down vote up
private CharSequence replace(String text) {
	try {
		SpannableString spannableString = new SpannableString(text);
		int start = 0;
		Pattern pattern = buildPattern();
		Matcher matcher = pattern.matcher(text);
		while (matcher.find()) {
			String faceText = matcher.group();
			String key = faceText.substring(1);
			BitmapFactory.Options options = new BitmapFactory.Options();
			Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(),
					getContext().getResources().getIdentifier(key, "drawable", getContext().getPackageName()), options);
			ImageSpan imageSpan = new ImageSpan(getContext(), bitmap);
			int startIndex = text.indexOf(faceText, start);
			int endIndex = startIndex + faceText.length();
			if (startIndex >= 0)
				spannableString.setSpan(imageSpan, startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			start = (endIndex - 1);
		}
		return spannableString;
	} catch (Exception e) {
		return text;
	}
}
 
Example 4
Source File: MainActivity.java    From Watch-Me-Build-a-Finance-Startup with MIT License 6 votes vote down vote up
private void initChatView() {
    int myId = 0;
    Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_user);
    String myName = "Siraj";
    myAccount = new User(myId, myName, icon);

    int botId = 1;
    String botName = "Artificial Advisor";
    droidKaigiBot = new User(botId, botName, icon);

    chatView = findViewById(R.id.chat_view);
    chatView.setRightBubbleColor(ContextCompat.getColor(this, R.color.green500));
    chatView.setLeftBubbleColor(Color.WHITE);
    chatView.setBackgroundColor(ContextCompat.getColor(this, R.color.blueGray500));
    chatView.setSendButtonColor(ContextCompat.getColor(this, R.color.lightBlue500));
    chatView.setSendIcon(R.drawable.ic_action_send);
    chatView.setRightMessageTextColor(Color.WHITE);
    chatView.setLeftMessageTextColor(Color.BLACK);
    chatView.setUsernameTextColor(Color.WHITE);
    chatView.setSendTimeTextColor(Color.WHITE);
    chatView.setDateSeparatorColor(Color.WHITE);
    chatView.setInputTextHint("new message...");
    chatView.setMessageMarginTop(5);
    chatView.setMessageMarginBottom(5);
    chatView.setOnClickSendButtonListener(this);
}
 
Example 5
Source File: MyCompressUtil.java    From star-zone-android with Apache License 2.0 5 votes vote down vote up
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
                                                     int reqWidth, int reqHeight) {
    // 第一次解析将inJustDecodeBounds设置为true,来获取图片大小
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(res, resId, options);
    // 调用上面定义的方法计算inSampleSize值
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
    // 使用获取到的inSampleSize值再次解析图片
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeResource(res, resId, options);
}
 
Example 6
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView( R.layout.activity_main );

    initViews();

    mAdapter = new SwatchAdapter( this );
    mListView.setAdapter( mAdapter );

    Bitmap bitmap = BitmapFactory.decodeResource( getResources(), R.drawable.union_station );
    Palette.from( bitmap ).generate( new Palette.PaletteAsyncListener() {
        @Override
        public void onGenerated( Palette palette ) {

            setViewSwatch( mVibrantTextView, palette.getVibrantSwatch() );
            setViewSwatch( mLightVibrantTextView, palette.getLightVibrantSwatch() );
            setViewSwatch( mDarkVibrantTextView, palette.getDarkVibrantSwatch() );
            setViewSwatch( mMutedTextView, palette.getMutedSwatch() );
            setViewSwatch( mLightMutedTextView, palette.getLightMutedSwatch() );
            setViewSwatch( mDarkMutedTextView, palette.getDarkMutedSwatch() );

            for( Palette.Swatch swatch : palette.getSwatches() ) {
                mAdapter.add(swatch);
            }

            mAdapter.sortSwatches();
            mAdapter.notifyDataSetChanged();


        }
    });
}
 
Example 7
Source File: AsyncTaskFragment.java    From coursera-android with MIT License 5 votes vote down vote up
@Override
protected Bitmap doInBackground(Integer... resId) {
    // simulating long-running operation
    for (int i = 1; i < 11; i++) {
        sleep();
        publishProgress(i * 10);
    }
    return BitmapFactory.decodeResource(mAsyncTaskFragment.get().getResources(), resId[0]);
}
 
Example 8
Source File: DirectoryEntry.java    From androidtestdebug with MIT License 5 votes vote down vote up
public Bitmap getBitmap(Resources res) {
    return BitmapFactory.decodeResource(res, resID);
}
 
Example 9
Source File: BitmapUtil.java    From RxAndroidBootstrap with Apache License 2.0 5 votes vote down vote up
/**
 * Get width and height of the bitmap specified with the resource id.
 *
 * @param res   resource accessor.
 * @param resId the resource id of the drawable.
 * @return the drawable bitmap size.
 */
public static Point getSize(Resources res, int resId) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(res, resId, options);
    int width = options.outWidth;
    int height = options.outHeight;
    return new Point(width, height);
}
 
Example 10
Source File: RxSeekBar.java    From RxTools-master with Apache License 2.0 5 votes vote down vote up
/**
 * 计算每个按钮的位置和尺寸
 * Calculates the position and size of each button
 *
 * @param x
 * @param y
 * @param hSize
 * @param parentLineWidth
 * @param cellsMode
 * @param bmpResId
 * @param context
 */
protected void onSizeChanged(int x, int y, int hSize, int parentLineWidth, boolean cellsMode, int bmpResId, Context context) {
    heightSize = hSize;
    widthSize = heightSize;
    left = x - widthSize / 2;
    right = x + widthSize / 2;
    top = y - heightSize / 2;
    bottom = y + heightSize / 2;

    if (cellsMode) {
        lineWidth = parentLineWidth;
    } else {
        lineWidth = parentLineWidth;
    }

    if (bmpResId > 0) {
        Bitmap original = BitmapFactory.decodeResource(context.getResources(), bmpResId);

        if (original != null) {
            Matrix matrix = new Matrix();
            float scaleHeight = mThumbSize * 1.0f / original.getHeight();
            float scaleWidth = scaleHeight;
            matrix.postScale(scaleWidth, scaleHeight);
            bmp = Bitmap.createBitmap(original, 0, 0, original.getWidth(), original.getHeight(), matrix, true);
        }

    } else {
        defaultPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        int radius = (int) (widthSize * DEFAULT_RADIUS);
        int barShadowRadius = (int) (radius * 0.95f);
        int mShadowCenterX = widthSize / 2;
        int mShadowCenterY = heightSize / 2;
        shadowGradient = new RadialGradient(mShadowCenterX, mShadowCenterY, barShadowRadius, Color.BLACK, Color.TRANSPARENT, Shader.TileMode.CLAMP);
    }
}
 
Example 11
Source File: ColorMatrixActivity.java    From AndroidDemo with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_color_matrix);
    img_new = (ImageView) findViewById(R.id.img_new);

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.sophie);
    img_new.setImageBitmap(getGreyBitmap(bitmap));
}
 
Example 12
Source File: ToastedMarkerOptionsChooser.java    From clusterkraf with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
private Bitmap getClusterBitmap(Resources res, int resourceId, int clusterSize) {
	BitmapFactory.Options options = new BitmapFactory.Options();

	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
		options.inMutable = true;
	}
	Bitmap bitmap = BitmapFactory.decodeResource(res, resourceId, options);
	if (bitmap.isMutable() == false) {
		bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
	}

	Canvas canvas = new Canvas(bitmap);

	Paint paint = null;
	float originY;
	if (clusterSize < 100) {
		paint = clusterPaintLarge;
		originY = bitmap.getHeight() * 0.64f;
	} else if (clusterSize < 1000) {
		paint = clusterPaintMedium;
		originY = bitmap.getHeight() * 0.6f;
	} else {
		paint = clusterPaintSmall;
		originY = bitmap.getHeight() * 0.56f;
	}

	canvas.drawText(String.valueOf(clusterSize), bitmap.getWidth() * 0.5f, originY, paint);

	return bitmap;
}
 
Example 13
Source File: PatternedTextActivity.java    From advanced-textview with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_patterned_text);

  TextView textView = (TextView) findViewById(R.id.text);

  Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.cheetah_tile);
  Shader shader = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
  textView.getPaint().setShader(shader);
}
 
Example 14
Source File: Bitmaps.java    From Simple-Solitaire with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the card backgrounds
 *
 * @param posX X-coordinate of the background in the file
 * @param posY Y-coordinate of the background in the file
 * @return a single bitmap
 */
public Bitmap getCardBack(int posX, int posY) {

    if (cardBack == null) {
        cardBack = BitmapFactory.decodeResource(res, R.drawable.backgrounds_cards);
        cardBackWidth = cardBack.getWidth() / NUM_CARD_BACKGROUNDS;
        cardBackHeight = cardBack.getHeight() / 4;
    }

    return Bitmap.createBitmap(cardBack, posX * cardBackWidth,
            posY * cardBackHeight, cardBackWidth, cardBackHeight);
}
 
Example 15
Source File: ResourceBitmapTextureAtlasSource.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
public static ResourceBitmapTextureAtlasSource create(final Resources pResources, final int pDrawableResourceID, final int pTextureX, final int pTextureY) {
		final BitmapFactory.Options decodeOptions = new BitmapFactory.Options();
		decodeOptions.inJustDecodeBounds = true;
//		decodeOptions.inScaled = false; // TODO Check how this behaves with drawable-""/nodpi/ldpi/mdpi/hdpi folders

		BitmapFactory.decodeResource(pResources, pDrawableResourceID, decodeOptions);

		return new ResourceBitmapTextureAtlasSource(pResources, pDrawableResourceID, pTextureX, pTextureY, decodeOptions.outWidth, decodeOptions.outHeight);
	}
 
Example 16
Source File: FriendListItem.java    From HHComicViewer with Apache License 2.0 5 votes vote down vote up
public FriendListItem(Context context, float ratio) {
	super(context);
	int itemPadding = (int) (ratio * DESIGN_ITEM_PADDING);
	setPadding(itemPadding, 0, itemPadding, 0);
	setMinimumHeight((int) (ratio * DESIGN_ITEM_HEIGHT));
	setBackgroundColor(0xffffffff);

	ivCheck = new ImageView(context);
	LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
			LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lp.gravity = Gravity.CENTER_VERTICAL;
	addView(ivCheck, lp);

	aivIcon = new AsyncImageView(context);
	int avatarWidth = (int) (ratio * DESIGN_AVATAR_WIDTH);
	lp = new LinearLayout.LayoutParams(avatarWidth, avatarWidth);
	lp.gravity = Gravity.CENTER_VERTICAL;
	int avatarMargin = (int) (ratio * DESIGN_AVATAR_PADDING);
	lp.setMargins(avatarMargin, 0, avatarMargin, 0);
	addView(aivIcon, lp);

	tvName = new TextView(context);
	tvName.setTextColor(0xff000000);
	tvName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
	tvName.setSingleLine();
	lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lp.gravity = Gravity.CENTER_VERTICAL;
	lp.weight = 1;
	addView(tvName, lp);

	int resId = R.getBitmapRes(context, "ssdk_oks_classic_check_checked");
	if (resId > 0) {
		bmChd = BitmapFactory.decodeResource(context.getResources(), resId);
	}
	resId = R.getBitmapRes(getContext(), "ssdk_oks_classic_check_default");
	if (resId > 0) {
		bmUnch = BitmapFactory.decodeResource(context.getResources(), resId);
	}
}
 
Example 17
Source File: WorkshopDetail.java    From Nimbus with GNU General Public License v3.0 5 votes vote down vote up
private void dynamicToolbarColor() {

        Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
                R.drawable.w1);
        Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {

            @Override
            public void onGenerated(Palette palette) {
                collapsingToolbarLayout.setContentScrimColor(palette.getMutedColor(getResources().getColor(R.color.colorPrimary)));
                collapsingToolbarLayout.setStatusBarScrimColor(palette.getMutedColor(getResources().getColor(R.color.colorPrimaryDark)));
            }
        });
    }
 
Example 18
Source File: RoundedFragment.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
StreamItem(Context c, int resid, String line1, String line2, ScaleType scaleType) {
  mBitmap = BitmapFactory.decodeResource(c.getResources(), resid);
  mLine1 = line1;
  mLine2 = line2;
  mScaleType = scaleType;
}
 
Example 19
Source File: BossTriangleBullet.java    From StormPlane with Apache License 2.0 4 votes vote down vote up
@Override
public void initBitmap() {
	bullet = BitmapFactory.decodeResource(resources, R.drawable.boss_bullet_triangle);
	object_width = bullet.getWidth();
	object_height = bullet.getHeight();
}
 
Example 20
Source File: LockPatternView.java    From quickmark with MIT License 4 votes vote down vote up
private Bitmap getBitmapFor(int resId) {
	return BitmapFactory.decodeResource(getContext().getResources(), resId);
}