本文整理汇总了Java中android.graphics.Bitmap.isMutable方法的典型用法代码示例。如果您正苦于以下问题:Java Bitmap.isMutable方法的具体用法?Java Bitmap.isMutable怎么用?Java Bitmap.isMutable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Bitmap
的用法示例。
在下文中一共展示了Bitmap.isMutable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBitmapFromDrawable
import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override
protected Bitmap getBitmapFromDrawable(Drawable drawable) {
Bitmap bitmap = super.getBitmapFromDrawable(drawable);
if (mBorderSize <= 0) {
return bitmap;
}
if(!bitmap.isMutable()){
bitmap = bitmap.copy(bitmap.getConfig(), true);
}
Canvas canvas = new Canvas(bitmap);
// draw border
mBorderPaint.setColor(mBorderColor);
mBorderPaint.setStrokeWidth(mBorderSize + 2);
mPath.reset();
mPathFactory.planRoundPath(mRadius, getRectF(), mPath, mBorderSize / 2 - 1);
canvas.drawPath(mPath, mBorderPaint);
return bitmap;
}
示例2: getBitmapFromNative
import android.graphics.Bitmap; //导入方法依赖的package包/类
private static Bitmap getBitmapFromNative(Bitmap bitmap) {
int width = nativeGetBitmapWidth();
int height = nativeGetBitmapHeight();
if (bitmap == null || width != bitmap.getWidth()
|| height != bitmap.getHeight() || !bitmap.isMutable()) { // in
Config config = Config.ARGB_8888;
if (bitmap != null) {
config = bitmap.getConfig();
bitmap.recycle();
}
bitmap = Bitmap.createBitmap(width, height, config);
}
int[] pixels = new int[width];
for (int y = 0; y < height; y++) {
nativeGetBitmapRow(y, pixels);
bitmap.setPixels(pixels, 0, width, 0, y, width, 1);
}
return bitmap;
}
示例3: countGCBitmap
import android.graphics.Bitmap; //导入方法依赖的package包/类
public static int countGCBitmap() {
synchronized (_weakGCBitmapQueue) {
for (int i = 0, gcBitmapQueueSize = _weakGCBitmapQueue.size(); i < gcBitmapQueueSize; i++) {
Pair<Long, SoftReference<Bitmap>> item = _weakGCBitmapQueue.get(i);
Bitmap bmp = item.second.get();
if (bmp == null || !bmp.isMutable() || bmp.isRecycled()) {
if (XulManager.DEBUG) {
if (bmp == null) {
} else if (!bmp.isMutable()) {
Log.e(TAG_RECYCLER, "invalid bitmap immutable(gc reuse phase)!!!");
} else {
Log.e(TAG_RECYCLER, "invalid bitmap recycled(gc reuse phase)!!!");
}
}
_weakGCBitmapQueue.remove(i);
--i;
--gcBitmapQueueSize;
continue;
}
}
}
return _weakGCBitmapQueue.size();
}
示例4: put
import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override
public synchronized void put(Bitmap bitmap) {
if (bitmap == null) {
throw new NullPointerException("Bitmap must not be null");
}
if (bitmap.isRecycled()) {
throw new IllegalStateException("Cannot pool recycled bitmap");
}
if (!bitmap.isMutable() || strategy.getSize(bitmap) > maxSize
|| !allowedConfigs.contains(bitmap.getConfig())) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "Reject bitmap from pool"
+ ", bitmap: " + strategy.logBitmap(bitmap)
+ ", is mutable: " + bitmap.isMutable()
+ ", is allowed config: " + allowedConfigs.contains(bitmap.getConfig()));
}
bitmap.recycle();
return;
}
final int size = strategy.getSize(bitmap);
strategy.put(bitmap);
tracker.add(bitmap);
puts++;
currentSize += size;
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "Put bitmap in pool=" + strategy.logBitmap(bitmap));
}
dump();
evict();
}
示例5: getBitmapFromReusableSet
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* @param options
* - BitmapFactory.Options with out* options populated
* @return Bitmap that case be used for inBitmap
*/
protected Bitmap getBitmapFromReusableSet(BitmapFactory.Options options) {
// BEGIN_INCLUDE(get_bitmap_from_reusable_set)
Bitmap bitmap = null;
if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) {
synchronized (mReusableBitmaps) {
final Iterator<SoftReference<Bitmap>> iterator = mReusableBitmaps
.iterator();
Bitmap item;
while (iterator.hasNext()) {
item = iterator.next().get();
if (null != item && item.isMutable()) {
// Check to see it the item can be used for inBitmap
if (canUseForInBitmap(item, options)) {
bitmap = item;
// Remove from reusable set so it can't be used
// again
iterator.remove();
break;
}
} else {
// Remove from the set if the reference has been
// cleared.
iterator.remove();
}
}
}
}
return bitmap;
// END_INCLUDE(get_bitmap_from_reusable_set)
}
示例6: removeShadow
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* Removes the shadow (and any other transparent parts)
* from a bitmap.
*
* @param bitmap the original bitmap
* @return the bitmap with the shadow removed
*/
public static Bitmap removeShadow(Bitmap bitmap) {
if (!bitmap.isMutable())
bitmap = bitmap.copy(bitmap.getConfig(), true);
int[] pixels = new int[bitmap.getWidth() * bitmap.getHeight()];
bitmap.getPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
for (int i = 0; i < pixels.length; i++) {
if (Color.alpha(pixels[i]) < 255)
pixels[i] = Color.TRANSPARENT;
}
bitmap.setPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
return bitmap;
}
示例7: getBitmapFromReusableSet
import android.graphics.Bitmap; //导入方法依赖的package包/类
Bitmap getBitmapFromReusableSet(BitmapFactory.Options options) {
Bitmap bitmap = null;
if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) {
synchronized (mReusableBitmaps) {
final Iterator<SoftReference<Bitmap>> iterator = mReusableBitmaps.iterator();
Bitmap item;
while (iterator.hasNext()) {
item = iterator.next().get();
if (null != item && item.isMutable()) {
// Check to see it the item can be used for inBitmap.
if (canUseForInBitmap(item, options)) {
bitmap = item;
// Remove from reusable set so it can't be used again.
iterator.remove();
break;
}
} else {
// Remove from the set if the reference has been cleared.
iterator.remove();
}
}
}
}
return bitmap;
}
示例8: getBitmapFromReusableSet
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* @param options - BitmapFactory.Options with out* options populated
* @return Bitmap that case be used for inBitmap
*/
protected Bitmap getBitmapFromReusableSet(BitmapFactory.Options options) {
//BEGIN_INCLUDE(get_bitmap_from_reusable_set)
Bitmap bitmap = null;
if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) {
synchronized (mReusableBitmaps) {
final Iterator<SoftReference<Bitmap>> iterator = mReusableBitmaps.iterator();
Bitmap item;
while (iterator.hasNext()) {
item = iterator.next().get();
if (null != item && item.isMutable()) {
// Check to see it the item can be used for inBitmap
if (canUseForInBitmap(item, options)) {
bitmap = item;
// Remove from reusable set so it can't be used again
iterator.remove();
break;
}
} else {
// Remove from the set if the reference has been cleared.
iterator.remove();
}
}
}
}
return bitmap;
//END_INCLUDE(get_bitmap_from_reusable_set)
}
示例9: addReusableBitmap
import android.graphics.Bitmap; //导入方法依赖的package包/类
private void addReusableBitmap(TileSource src) {
synchronized (mReusableBitmaps) {
if (src instanceof BitmapRegionTileSource) {
Bitmap preview = ((BitmapRegionTileSource) src).getBitmap();
if (preview != null && preview.isMutable()) {
mReusableBitmaps.add(preview);
}
}
}
}
示例10: toRoundCornerBitmap
import android.graphics.Bitmap; //导入方法依赖的package包/类
private static Bitmap toRoundCornerBitmap(Canvas canvas, Paint paintClear, Bitmap srcBitmap, float[] roundRadius) {
if (srcBitmap.isMutable() && srcBitmap.hasAlpha()) {
return toRoundCornerMutableBitmap(canvas, paintClear, srcBitmap, roundRadius);
}
Bitmap output;
if (false) {
output = BitmapTools.createBitmapFromRecycledBitmaps(srcBitmap.getWidth(), srcBitmap.getHeight(), XulManager.DEF_PIXEL_FMT);
} else {
output = BitmapTools.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), XulManager.DEF_PIXEL_FMT);
}
canvas.setBitmap(output);
Rect rect = new Rect(0, 0, srcBitmap.getWidth(), srcBitmap.getHeight());
canvas.drawBitmap(srcBitmap, rect, rect, null);
return toRoundCornerMutableBitmap(canvas, paintClear, output, roundRadius);
}
示例11: doInBackground
import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override
protected Bitmap doInBackground(Void... params) {
Bitmap unusedBitmap = null;
// If already cancelled before this gets to run in the background, then return early
if (isCancelled()) {
return null;
}
synchronized (mUnusedBitmaps) {
// Check if we can re-use a bitmap
for (Bitmap candidate : mUnusedBitmaps) {
if (candidate != null && candidate.isMutable() &&
candidate.getWidth() == mPreviewWidth &&
candidate.getHeight() == mPreviewHeight) {
unusedBitmap = candidate;
mUnusedBitmaps.remove(unusedBitmap);
break;
}
}
}
// creating a bitmap is expensive. Do not do this inside synchronized block.
if (unusedBitmap == null) {
unusedBitmap = Bitmap.createBitmap(mPreviewWidth, mPreviewHeight, Config.ARGB_8888);
}
// If cancelled now, don't bother reading the preview from the DB
if (isCancelled()) {
return unusedBitmap;
}
Bitmap preview = readFromDb(mKey, unusedBitmap, this);
// Only consider generating the preview if we have not cancelled the task already
if (!isCancelled() && preview == null) {
// Fetch the version info before we generate the preview, so that, in-case the
// app was updated while we are generating the preview, we use the old version info,
// which would gets re-written next time.
boolean persistable = mInfo.activityInfo == null
|| mInfo.activityInfo.isPersistable();
mVersions = persistable ? getPackageVersion(mKey.componentName.getPackageName())
: null;
// it's not in the db... we need to generate it
preview = generatePreview(mActivity, mInfo, unusedBitmap, mPreviewWidth, mPreviewHeight);
}
return preview;
}
示例12: onSizeChanged
import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override
protected void onSizeChanged(int w, int h, int oldW, int oldH) {
int oldBitmapWidth = bitmap.getWidth();
int oldBitmapHeight = bitmap.getHeight();
if (w != oldBitmapWidth || h != oldBitmapHeight) {
Bitmap oldBitmap = bitmap;
// Create a new bitmap by scaling the old bitmap that contained the
// drawing layer (points, lines, text, etc.).
// The documentation for Bitmap.createScaledBitmap doesn't specify whether it creates a
// mutable or immutable bitmap. Looking at the source code shows that it calls
// Bitmap.createBitmap(Bitmap, int, int, int, int, Matrix, boolean), which is documented as
// returning an immutable bitmap. However, it actually returns a mutable bitmap.
// It's possible that the behavior could change in the future if they "fix" that bug.
// Try Bitmap.createScaledBitmap, but if it gives us an immutable bitmap, we'll have to
// create a mutable bitmap and scale the old bitmap using Canvas.drawBitmap.
try {
// See comment at the catch below
Bitmap scaledBitmap = Bitmap.createScaledBitmap(oldBitmap, w, h, false);
if (scaledBitmap.isMutable()) {
// scaledBitmap is mutable; we can use it in a canvas.
bitmap = scaledBitmap;
// NOTE(lizlooney) - I tried just doing canvas.setBitmap(bitmap), but after that the
// canvas.drawCircle() method did not work correctly. So, we need to create a whole new
// canvas.
canvas = new android.graphics.Canvas(bitmap);
} else {
// scaledBitmap is immutable; we can't use it in a canvas.
bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
// NOTE(lizlooney) - I tried just doing canvas.setBitmap(bitmap), but after that the
// canvas.drawCircle() method did not work correctly. So, we need to create a whole new
// canvas.
canvas = new android.graphics.Canvas(bitmap);
// Draw the old bitmap into the new canvas, scaling as necessary.
Rect src = new Rect(0, 0, oldBitmapWidth, oldBitmapHeight);
RectF dst = new RectF(0, 0, w, h);
canvas.drawBitmap(oldBitmap, src, dst, null);
}
} catch (IllegalArgumentException ioe) {
// There's some kind of order of events issue that results in w or h being zero.
// I'm guessing that this is a result of specifying width or height as FILL_PARRENT on an
// opening screen. In any case, w<=0 or h<=0 causes the call to createScaledBitmap
// to throw an illegal argument. If this happens we simply don't draw the bitmap
// (which would be of width or height 0)
// TODO(hal): Investigate this further to see what is causes the w=0 or h=0 and see if
// there is a more high-level fix.
Log.e(LOG_TAG, "Bad values to createScaledBimap w = " + w + ", h = " + h);
}
// The following has nothing to do with the scaling in this method.
// It has to do with scaling the background image for GetColor().
// Specifically, it says we need to regenerate the bitmap representing
// the background color/image if a call to GetColor() is made.
scaledBackgroundBitmap = null;
}
}
示例13: doInBackground
import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override
protected Bitmap doInBackground(Void... params) {
Bitmap unusedBitmap = null;
// If already cancelled before this gets to run in the background, then return early
if (isCancelled()) {
return null;
}
synchronized (mUnusedBitmaps) {
// Check if we can re-use a bitmap
for (Bitmap candidate : mUnusedBitmaps) {
if (candidate != null && candidate.isMutable() &&
candidate.getWidth() == mPreviewWidth &&
candidate.getHeight() == mPreviewHeight) {
unusedBitmap = candidate;
mUnusedBitmaps.remove(unusedBitmap);
break;
}
}
}
// creating a bitmap is expensive. Do not do this inside synchronized block.
if (unusedBitmap == null) {
unusedBitmap = Bitmap.createBitmap(mPreviewWidth, mPreviewHeight, Config.ARGB_8888);
}
// If cancelled now, don't bother reading the preview from the DB
if (isCancelled()) {
return unusedBitmap;
}
Bitmap preview = readFromDb(mKey, unusedBitmap, this);
// Only consider generating the preview if we have not cancelled the task already
if (!isCancelled() && preview == null) {
// Fetch the version info before we generate the preview, so that, in-case the
// app was updated while we are generating the preview, we use the old version info,
// which would gets re-written next time.
mVersions = getPackageVersion(mKey.componentName.getPackageName());
Launcher launcher = Launcher.getLauncher(mCaller.getContext());
// it's not in the db... we need to generate it
preview = generatePreview(launcher, mInfo, unusedBitmap, mPreviewWidth, mPreviewHeight);
}
return preview;
}
示例14: isReusable
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* Determine if this bitmap is reusable (i.e.) if subsequent {@link #get(int)} requests can
* use this value.
* The bitmap is reusable if
* - it has not already been recycled AND
* - it is mutable
* @param value the value to test for reusability
* @return true, if the bitmap can be reused
*/
@Override
protected boolean isReusable(Bitmap value) {
Preconditions.checkNotNull(value);
return !value.isRecycled() &&
value.isMutable();
}
示例15: create
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* Create a new instance with a bitmap instance that will be the root of the
* {@link Canvas} created
* @param bitmap the base drawing bitmap
* @return self for chaining
* @throws IllegalArgumentException if bitmap is not mutable or is recycled
* @see Canvas
*/
public static CanvasScript create(@NonNull Bitmap bitmap) {
if (!bitmap.isMutable() || bitmap.isRecycled()) {
throw new IllegalArgumentException("Bitmap must be mutable and unrecycled");
}
return new CanvasScript(bitmap);
}