本文整理汇总了Java中android.graphics.drawable.BitmapDrawable.setBounds方法的典型用法代码示例。如果您正苦于以下问题:Java BitmapDrawable.setBounds方法的具体用法?Java BitmapDrawable.setBounds怎么用?Java BitmapDrawable.setBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.drawable.BitmapDrawable
的用法示例。
在下文中一共展示了BitmapDrawable.setBounds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
private void load(Context context, @DrawableRes int drawableRes, int textSize, String url) {
if (!nativeLoad(handle, url)) {
nativeClose(handle);
throw new RuntimeException("not gif");
} else {
frameNum = nativeGetFrameCount(handle);
for (int i = 0; i < frameNum; i++) {
BitmapDrawable drawable = new BitmapDrawable(context.getResources(), nativeGetFrame(handle, i));
int width = (textSize * drawable.getIntrinsicWidth()) / drawable.getIntrinsicHeight();
drawable.setBounds(0, 0, width, textSize);
EmoticonCache.saveDrawable(drawableRes, i, drawable);
delay = nativeGetDelay(handle, i);
}
nativeClose(handle);
}
}
示例2: createAndPutChipForUser
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
private ChipSpan createAndPutChipForUser(TLRPC.User user) {
LayoutInflater lf = (LayoutInflater) ApplicationLoader.applicationContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View textView = lf.inflate(R.layout.group_create_bubble, null);
TextView text = (TextView)textView.findViewById(R.id.bubble_text_view);
String name = UserObject.getUserName(user);
if (name.length() == 0 && user.phone != null && user.phone.length() != 0) {
name = PhoneFormat.getInstance().format("+" + user.phone);
}
text.setText(name + ", ");
int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
textView.measure(spec, spec);
textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(b);
canvas.translate(-textView.getScrollX(), -textView.getScrollY());
textView.draw(canvas);
textView.setDrawingCacheEnabled(true);
Bitmap cacheBmp = textView.getDrawingCache();
Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
textView.destroyDrawingCache();
final BitmapDrawable bmpDrawable = new BitmapDrawable(b);
bmpDrawable.setBounds(0, 0, b.getWidth(), b.getHeight());
SpannableStringBuilder ssb = new SpannableStringBuilder("");
ChipSpan span = new ChipSpan(bmpDrawable, ImageSpan.ALIGN_BASELINE);
allSpans.add(span);
selectedContacts.put(user.id, span);
for (ImageSpan sp : allSpans) {
ssb.append("<<");
ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
}
userSelectEditText.setText(ssb);
userSelectEditText.setSelection(ssb.length());
return span;
}
示例3: createFloatingBitmap
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
private BitmapDrawable createFloatingBitmap(View v) {
floatingItemStatingBounds = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
floatingItemBounds = new Rect(floatingItemStatingBounds);
Bitmap bitmap = Bitmap.createBitmap(floatingItemStatingBounds.width(),
floatingItemStatingBounds.height(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
v.draw(canvas);
BitmapDrawable retDrawable = new BitmapDrawable(v.getResources(), bitmap);
retDrawable.setBounds(floatingItemBounds);
return retDrawable;
}
示例4: fetchCompressedDrawable
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
/**
* Get the compressed image with specific quality from URL
*/
public Drawable fetchCompressedDrawable(Resources res, String urlString) {
try {
InputStream is = fetch(urlString);
Bitmap original = new BitmapDrawable(res, is).getBitmap();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Bitmap.CompressFormat compressFormat = (urlString.endsWith(".png") || urlString.endsWith(".PNG"))
? Bitmap.CompressFormat.PNG
: Bitmap.CompressFormat.JPEG;
original.compress(compressFormat, qualityImage, out);
original.recycle();
is.close();
Bitmap decoded = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()));
out.close();
scale = getScale(decoded.getWidth());
BitmapDrawable b = new BitmapDrawable(res, decoded);
b.setBounds(0, 0, (int) (b.getIntrinsicWidth() * scale), (int) (b.getIntrinsicHeight() * scale));
return b;
} catch (Exception e) {
return null;
}
}
示例5: AnimatedGifDrawable
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
public AnimatedGifDrawable(InputStream source, UpdateListener listener) {
mListener = listener;
GifDecoder decoder = new GifDecoder();
decoder.read(source);
// Iterate through the gif frames, add each as animation frame
for (int i = 0; i < decoder.getFrameCount(); i++) {
Bitmap bitmap = decoder.getFrame(i);
BitmapDrawable drawable = new BitmapDrawable(bitmap);
// Explicitly set the bounds in order for the frames to display
drawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
addFrame(drawable, decoder.getDelay(i));
if (i == 0) {
// Also set the bounds for this container drawable
setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
}
}
}
示例6: fetchCompressedDrawable
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
/**
* Get the compressed image with specific quality from URL
*/
public Drawable fetchCompressedDrawable(Resources res, String urlString) {
try {
InputStream is = fetch(urlString);
Bitmap original = new BitmapDrawable(res, is).getBitmap();
ByteArrayOutputStream out = new ByteArrayOutputStream();
original.compress(Bitmap.CompressFormat.JPEG, qualityImage, out);
original.recycle();
is.close();
Bitmap decoded = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()));
out.close();
scale = getScale(decoded);
BitmapDrawable b = new BitmapDrawable(res, decoded);
b.setBounds(0, 0, (int) (b.getIntrinsicWidth() * scale), (int) (b.getIntrinsicHeight() * scale));
return b;
} catch (Exception e) {
return null;
}
}
示例7: centerCrop
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
/**
* 居中剪切图片
*/
public static Bitmap centerCrop(Resources res, Bitmap bitmap, int width, int height) {
if (bitmap == null) {
return null;
}
Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Matrix matrix = new Matrix();
float scale;
float dx = 0, dy = 0;
final int dwidth = bitmap.getWidth();
final int dheight = bitmap.getHeight();
final int vwidth = width;
final int vheight = height;
if (dwidth * vheight > vwidth * dheight) {
scale = (float) vheight / (float) dheight;
dx = (vwidth - dwidth * scale) * 0.5f;
} else {
scale = (float) vwidth / (float) dwidth;
dy = (vheight - dheight * scale) * 0.5f;
}
matrix.setScale(scale, scale);
matrix.postTranslate(Math.round(dx), Math.round(dy));
Canvas canvas = new Canvas(result);
canvas.concat(matrix);
BitmapDrawable bitmapDrawable = new BitmapDrawable(res, bitmap);
bitmapDrawable.setBounds(0, 0, dwidth, dheight);
bitmapDrawable.draw(canvas);
return result;
}
示例8: getDrawable
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
public Drawable getDrawable(Resources resources) {
if (gifDrawable == null) {
BitmapDrawable bitmapDrawable = new BitmapDrawable(resources, bitmap);
bitmapDrawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
return bitmapDrawable;
} else {
return gifDrawable;
}
}
示例9: loadFromMemory
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
@NonNull
private Drawable loadFromMemory(ImageHolder holder, TextView textView, DrawableWrapper drawableWrapper) {
BitmapWrapper bitmapWrapper = BitmapPool.getPool().get(holder.getKey(), false, true);
Bitmap bitmap = bitmapWrapper.getBitmap();
BitmapDrawable bitmapDrawable = new BitmapDrawable(textView.getResources(), bitmap);
bitmapDrawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
drawableWrapper.setDrawable(bitmapDrawable);
BitmapWrapper.SizeCacheHolder sizeCacheHolder = bitmapWrapper.getSizeCacheHolder();
drawableWrapper.setBounds(sizeCacheHolder.rect);
drawableWrapper.setScaleType(sizeCacheHolder.scaleType);
drawableWrapper.calculate();
return drawableWrapper;
}
示例10: getAndAddHoverView
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
private BitmapDrawable getAndAddHoverView(View v, float scale){
int w = v.getWidth();
int h = v.getHeight();
int top = v.getTop();
int left = v.getLeft();
Bitmap b = getBitmapWithBorder(v,scale);
BitmapDrawable drawable = new BitmapDrawable(getResources(),b);
mHoverCellOriginalBounds = new Rect(left,top,left+w,top+h);
mHoverCellCurrentBounds = new Rect(mHoverCellOriginalBounds);
drawable.setBounds(mHoverCellCurrentBounds);
return drawable;
}
示例11: createAndPutChipForUser
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
private ChipSpan createAndPutChipForUser(TLRPC.User user) {
try {
LayoutInflater lf = (LayoutInflater) ApplicationLoader.applicationContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View textView = lf.inflate(R.layout.group_create_bubble, null);
TextView text = (TextView)textView.findViewById(R.id.bubble_text_view);
String name = UserObject.getUserName(user);
if (name.length() == 0 && user.phone != null && user.phone.length() != 0) {
name = PhoneFormat.getInstance().format("+" + user.phone);
}
text.setText(name + ", ");
int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
textView.measure(spec, spec);
textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(b);
canvas.translate(-textView.getScrollX(), -textView.getScrollY());
textView.draw(canvas);
textView.setDrawingCacheEnabled(true);
Bitmap cacheBmp = textView.getDrawingCache();
Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
textView.destroyDrawingCache();
final BitmapDrawable bmpDrawable = new BitmapDrawable(b);
bmpDrawable.setBounds(0, 0, b.getWidth(), b.getHeight());
SpannableStringBuilder ssb = new SpannableStringBuilder("");
ChipSpan span = new ChipSpan(bmpDrawable, ImageSpan.ALIGN_BASELINE);
allSpans.add(span);
selectedContacts.put(user.id, span);
for (ImageSpan sp : allSpans) {
ssb.append("<<");
ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
}
nameTextView.setText(ssb);
nameTextView.setSelection(ssb.length());
return span;
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return null;
}
示例12: processImageResponse
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
private void processImageResponse(String id, ImageResponse response) {
if (response != null) {
Bitmap bitmap = response.getBitmap();
if (bitmap != null) {
BitmapDrawable drawable = new BitmapDrawable(UserSettingsFragment.this.getResources(), bitmap);
drawable.setBounds(0, 0,
getResources().getDimensionPixelSize(R.dimen.com_facebook_usersettingsfragment_profile_picture_width),
getResources().getDimensionPixelSize(R.dimen.com_facebook_usersettingsfragment_profile_picture_height));
userProfilePic = drawable;
userProfilePicID = id;
connectedStateLabel.setCompoundDrawables(null, drawable, null, null);
connectedStateLabel.setTag(response.getRequest().getImageUri());
}
}
}
示例13: createAndPutChipForUser
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
private ChipSpan createAndPutChipForUser(TLRPC.User user) {
LayoutInflater lf = (LayoutInflater) ApplicationLoader.applicationContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View textView = lf.inflate(R.layout.group_create_bubble, null);
TextView text = (TextView) textView.findViewById(R.id.bubble_text_view);
String name = UserObject.getUserName(user);
if (name.length() == 0 && user.phone != null && user.phone.length() != 0) {
name = PhoneFormat.getInstance().format("+" + user.phone);
}
text.setText(name + ", ");
int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
textView.measure(spec, spec);
textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(b);
canvas.translate(-textView.getScrollX(), -textView.getScrollY());
textView.draw(canvas);
textView.setDrawingCacheEnabled(true);
Bitmap cacheBmp = textView.getDrawingCache();
Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
textView.destroyDrawingCache();
final BitmapDrawable bmpDrawable = new BitmapDrawable(b);
bmpDrawable.setBounds(0, 0, b.getWidth(), b.getHeight());
SpannableStringBuilder ssb = new SpannableStringBuilder("");
ChipSpan span = new ChipSpan(bmpDrawable, ImageSpan.ALIGN_BASELINE);
allSpans.add(span);
selectedContacts.put(user.id, span);
for (ImageSpan sp : allSpans) {
ssb.append("<<");
ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
}
userSelectEditText.setText(ssb);
userSelectEditText.setSelection(ssb.length());
return span;
}
示例14: getAndAddHoverView
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
/**
* Creates the hover cell with the appropriate bitmap and of appropriate
* size. The hover cell's BitmapDrawable is drawn on top of the bitmap every
* single time an invalidate call is made.
*/
private BitmapDrawable getAndAddHoverView(View v) {
int w = v.getWidth();
int h = v.getHeight();
int top = v.getTop();
int left = v.getLeft();
Bitmap b = getBitmapFromView(v);
BitmapDrawable drawable = new BitmapDrawable(getResources(), b);
mHoverCellOriginalBounds = new Rect(left, top, left + w, top + h);
mHoverCellCurrentBounds = new Rect(mHoverCellOriginalBounds);
drawable.setBounds(mHoverCellCurrentBounds);
return drawable;
}
示例15: getAndAddHoverView
import android.graphics.drawable.BitmapDrawable; //导入方法依赖的package包/类
/**
* Creates the hover cell with the appropriate bitmap and of appropriate
* size. The hover cell's BitmapDrawable is drawn on top of the bitmap every
* single time an invalidate call is made.
*/
private BitmapDrawable getAndAddHoverView(View v) {
int w = v.getWidth();
int h = v.getHeight();
int top = v.getTop();
int left = v.getLeft();
Bitmap b = getBitmapWithBorder(v);
BitmapDrawable drawable = new BitmapDrawable(getResources(), b);
mHoverCellOriginalBounds = new Rect(left, top, left + w, top + h);
mHoverCellCurrentBounds = new Rect(mHoverCellOriginalBounds);
drawable.setBounds(mHoverCellCurrentBounds);
return drawable;
}