本文整理汇总了Java中android.graphics.BitmapFactory.decodeResource方法的典型用法代码示例。如果您正苦于以下问题:Java BitmapFactory.decodeResource方法的具体用法?Java BitmapFactory.decodeResource怎么用?Java BitmapFactory.decodeResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.BitmapFactory
的用法示例。
在下文中一共展示了BitmapFactory.decodeResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showNotification
import android.graphics.BitmapFactory; //导入方法依赖的package包/类
private void showNotification(String title, String description, Intent intent) {
String channelID = getNotificationChannelID();
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Bitmap largeNotificationImage = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelID)
.setContentIntent(pendingIntent)
.setContentTitle(title)
.setContentText(description)
.setDefaults(Notification.DEFAULT_ALL)
.setLargeIcon(largeNotificationImage)
.setSmallIcon(R.drawable.ic_logo);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
builder.setColor(ContextCompat.getColor(this, R.color.colorPrimary));
Notification notification = builder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Get the notification manager & publish the notification
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(Constants.ID_NOTIFICATION_BROADCAST, notification);
}
示例2: decodeSampledBitmapFromResource
import android.graphics.BitmapFactory; //导入方法依赖的package包/类
/**
* Decode and sample down a bitmap from resources to the requested width and
* height.
*
* @param res
* The resources object containing the image data
* @param resId
* The resource id of the image data
* @param reqWidth
* The requested width of the resulting bitmap
* @param reqHeight
* The requested height of the resulting bitmap
* @param cache
* The ImageCache used to find candidate bitmaps for use with
* inBitmap
* @return A bitmap sampled down from the original with the same aspect
* ratio and dimensions that are equal to or greater than the
* requested width and height
*/
public static Bitmap decodeSampledBitmapFromResource(Resources res,
int resId, int reqWidth, int reqHeight, ImageCache cache) {
// BEGIN_INCLUDE (read_bitmap_dimensions)
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth,
reqHeight);
// END_INCLUDE (read_bitmap_dimensions)
// If we're running on Honeycomb or newer, try to use inBitmap
if (Utils.hasHoneycomb()) {
addInBitmapOptions(options, cache);
}
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}
示例3: initialize
import android.graphics.BitmapFactory; //导入方法依赖的package包/类
public void initialize() {
// mcontext should be always not null.
mcfgImage_24 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.setting_gear_24);
mcfgImage_32 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.setting_gear_32);
mcfgImage_48 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.setting_gear_48);
mcfgImage_64 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.setting_gear_64);
mzoomInImage_24 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_in_24);
mzoomInImage_32 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_in_32);
mzoomInImage_48 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_in_48);
mzoomInImage_64 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_in_64);
mzoomOutImage_24 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_out_24);
mzoomOutImage_32 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_out_32);
mzoomOutImage_48 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_out_48);
mzoomOutImage_64 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_out_64);
mxy1To1ZoomImage_24 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_1_24);
mxy1To1ZoomImage_32 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_1_32);
mxy1To1ZoomImage_48 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_1_48);
mxy1To1ZoomImage_64 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_1_64);
mfitZoomImage_24 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_fit_24);
mfitZoomImage_32 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_fit_32);
mfitZoomImage_48 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_fit_48);
mfitZoomImage_64 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_fit_64);
}
示例4: getPlatLogo
import android.graphics.BitmapFactory; //导入方法依赖的package包/类
private Bitmap getPlatLogo(Platform plat) {
if (plat == null) {
return null;
}
String name = plat.getName();
if (name == null) {
return null;
}
String resName = "logo_" + plat.getName();
int resId = getBitmapRes(activity, resName);
if(resId > 0) {
return BitmapFactory.decodeResource(activity.getResources(), resId);
}
return null;
}
示例5: setIcon
import android.graphics.BitmapFactory; //导入方法依赖的package包/类
@Override
public void setIcon(Uri uri) {
if (mIconUri != null && mIconUri.equals(uri)) {
return;
}
mIconUri = uri;
if (mFetchBitmapTask != null) {
mFetchBitmapTask.cancel(true);
}
mFetchBitmapTask = new FetchBitmapTask() {
@Override
protected void onPostExecute(Bitmap bitmap) {
if (bitmap == null) {
bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.album_art_placeholder);
}
setIcon(bitmap);
if (this == mFetchBitmapTask) {
mFetchBitmapTask = null;
}
}
};
mFetchBitmapTask.execute(uri);
}
示例6: initView
import android.graphics.BitmapFactory; //导入方法依赖的package包/类
private void initView() {
//模糊化背景图片
int w = windowManager.getDefaultDisplay().getWidth();
int h = windowManager.getDefaultDisplay().getHeight();
// Bitmap bitmap = BitmapFactory.decodeFile(music.getAlbumImgUrl());
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), bcpic[random.nextInt(5)]);
BlurBitmap blurBitmap = new BlurBitmap();
bitmap = blurBitmap.blur(bitmap, w, h);
BGrRelativeLayout.setBackground(new BitmapDrawable(getResources(), bitmap));
//歌词名
toolbar_tv.setText(music.getMusicName());
circleSeekBar.setHan(0);
//歌词作者
circleSeekBar.setsingername(music.getSinger());
lrcTextView.setVisibility(View.INVISIBLE);
Loadlrc.setVisibility(View.VISIBLE);
Loadlrc.setText("加载歌词......");
InitExPlayer();
}
示例7: decodeSampledBitmapFromResource
import android.graphics.BitmapFactory; //导入方法依赖的package包/类
public static Bitmap decodeSampledBitmapFromResource(Resources res,
int resId, int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth,
reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}
示例8: getPlatLogo
import android.graphics.BitmapFactory; //导入方法依赖的package包/类
private Bitmap getPlatLogo(Platform plat) {
if (plat == null || plat.getName() == null) {
return null;
}
int resId = R.getBitmapRes(this.activity, ("logo_" + plat.getName()).toLowerCase());
if (resId > 0) {
return BitmapFactory.decodeResource(this.activity.getResources(), resId);
}
return null;
}
示例9: initEndAnimationBitmaps
import android.graphics.BitmapFactory; //导入方法依赖的package包/类
/**
* 初始化最后的爆炸动画
*/
private void initEndAnimationBitmaps() {
mDataBean.mBitmapsExplodes = new Bitmap[5];
for (int i = 0; i < 5; i++) {
int identifier = getContext().getResources().getIdentifier("burst_" + (i + 1), "drawable", getContext().getPackageName());
Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(), identifier);
mDataBean.mBitmapsExplodes[i] = bitmap;
}
}
示例10: onPostExecute
import android.graphics.BitmapFactory; //导入方法依赖的package包/类
@Override
protected void onPostExecute(Bitmap result) {
super.onPostExecute(result);
pb.setVisibility(View.INVISIBLE);
photoView.setVisibility(View.VISIBLE);
if (result != null)
EaseImageCache.getInstance().put(path, result);
else
result = BitmapFactory.decodeResource(context.getResources(),
R.drawable.ease_default_image);
photoView.setImageBitmap(result);
}
示例11: FriendListItem
import android.graphics.BitmapFactory; //导入方法依赖的package包/类
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);
LayoutParams lp = new 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 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 LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.CENTER_VERTICAL;
lp.weight = 1;
addView(tvName, lp);
int resId = ResHelper.getBitmapRes(context, "ssdk_oks_classic_check_checked");
if (resId > 0) {
bmChd = BitmapFactory.decodeResource(context.getResources(), resId);
}
resId = ResHelper.getBitmapRes(getContext(), "ssdk_oks_classic_check_default");
if (resId > 0) {
bmUnch = BitmapFactory.decodeResource(context.getResources(), resId);
}
}
示例12: onCreateInit
import android.graphics.BitmapFactory; //导入方法依赖的package包/类
@Override
protected void onCreateInit() {
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = 6; //这个的值压缩的倍数(2的整数倍),数值越小,压缩率越小,图片越清晰
mBgBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.login_bg,opts);
//模糊
Bitmap mFinalMap= BlurBitmap.blur(this,mBgBitmap);
mLoginBackgroundView.setImageBitmap(mFinalMap);
popCurrentActivity();
initPresenter();
initListener();
}
示例13: loadTexture
import android.graphics.BitmapFactory; //导入方法依赖的package包/类
public static int loadTexture(Context context, int resourceId) {
final int[] textureObjectId = new int[1];
glGenTextures(1, textureObjectId, 0);
if (textureObjectId[0] == 0) {
Log.d(TAG, "can't generate a new opengl texture");
return 0;
}
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;
final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);
if (bitmap == null) {
Log.d(TAG, "resource id" + resourceId + " can't be decoded");
glDeleteTextures(1, textureObjectId, 0);
return 0;
}
glBindTexture(GL_TEXTURE_2D, textureObjectId[0]);
//下面是设置图片放大缩小后如何选择像素点进行优化处理来让图片尽量保持清晰
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
texImage2D(GL_TEXTURE_2D, 0, bitmap, 0);
bitmap.recycle();
glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);
return textureObjectId[0];
}
示例14: shareToWechat
import android.graphics.BitmapFactory; //导入方法依赖的package包/类
private void shareToWechat(boolean timeline) {
if (isPkgInstalled("com.tencent.mm")) {
// 初始化一个WXTextObject对象
Bitmap bmp = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_launcher);
//WXImageObject imgObj = new WXImageObject(bmp);
WXWebpageObject webObj = new WXWebpageObject();
webObj.webpageUrl = shareLink;
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject = webObj;
Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 150, 150, true);
bmp.recycle();
msg.thumbData = Util.bmpToByteArray(thumbBmp, true); // 设置缩略图
msg.description = mContext.getResources().getString(R.string.shareDescription);
msg.title = shareText;
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("webpage");
req.message = msg;
req.scene = timeline ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;
// 调用api接口发送数据到微信
wAPI.sendReq(req);
} else {
new CommonDialog(getActivity(), "温馨提示", "未检测到“微信”应用", "确定").show();
}
}
示例15: generateIconBitmaps
import android.graphics.BitmapFactory; //导入方法依赖的package包/类
private Bitmap[] generateIconBitmaps(@DrawableRes int origin) {
if (origin == -1) {
return null;
}
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), origin, options);
int size = Math.max(options.outWidth, options.outHeight);
options.inSampleSize = size > iconSize ? size / iconSize : 1;
options.inJustDecodeBounds = false;
return generateIconBitmaps(BitmapFactory.decodeResource(getResources(), origin, options));
}