当前位置: 首页>>代码示例>>Java>>正文


Java Bitmap.isMutable方法代码示例

本文整理汇总了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;
}
 
开发者ID:A-Miracle,项目名称:QiangHongBao,代码行数:23,代码来源:BorderImageView.java

示例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;
}
 
开发者ID:viseator,项目名称:MontageCam,代码行数:23,代码来源:PhotoProcessing.java

示例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();
}
 
开发者ID:starcor-company,项目名称:starcor.xul,代码行数:25,代码来源:BitmapTools.java

示例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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:35,代码来源:LruBitmapPool.java

示例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)
}
 
开发者ID:liuyanggithub,项目名称:SuperSelector,代码行数:41,代码来源:ImageCache.java

示例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;
}
 
开发者ID:TheAndroidMaster,项目名称:AdaptiveIconView,代码行数:22,代码来源:ImageUtils.java

示例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;
}
 
开发者ID:Mr-wangyong,项目名称:ImageFrame,代码行数:29,代码来源:ImageCache.java

示例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)
}
 
开发者ID:gavinking,项目名称:DisplayingBitmaps,代码行数:37,代码来源:ImageCache.java

示例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);
            }
        }
    }
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:11,代码来源:WallpaperCropActivity.java

示例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);
}
 
开发者ID:starcor-company,项目名称:starcor.xul,代码行数:16,代码来源:XulWorker.java

示例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;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:46,代码来源:WidgetPreviewLoader.java

示例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;
  }
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:64,代码来源:Canvas.java

示例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;
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:45,代码来源:WidgetPreviewLoader.java

示例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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:BitmapPool.java

示例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);
}
 
开发者ID:52inc,项目名称:CanvasScript,代码行数:15,代码来源:CanvasScript.java


注:本文中的android.graphics.Bitmap.isMutable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。