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


Java Bitmap.eraseColor方法代码示例

本文整理汇总了Java中android.graphics.Bitmap.eraseColor方法的典型用法代码示例。如果您正苦于以下问题:Java Bitmap.eraseColor方法的具体用法?Java Bitmap.eraseColor怎么用?Java Bitmap.eraseColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.Bitmap的用法示例。


在下文中一共展示了Bitmap.eraseColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createViewBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
public Bitmap createViewBitmap(View view, Layout textLayout, int bitmapWidth, int bitmapHeight, int vertical_align) {
	final int actualBitmapWidth = getPowerOfTwo(bitmapWidth);
	final int actualBitmapHeight = getPowerOfTwo(bitmapHeight);
	Bitmap destBitmap = Bitmap.createBitmap( actualBitmapWidth, actualBitmapHeight, Bitmap.Config.ARGB_8888 );
	destBitmap.eraseColor(Color.TRANSPARENT);

	synchronized (mCanvas) {
		mCanvas.setBitmap(destBitmap);
		mCanvas.save();

		// Center the bitmap horizontally inside the "powerOfTwo" texture bitmap
           mCanvas.translate((actualBitmapWidth - bitmapWidth) / 2, 0);

		// Align vertically depending of the argument
		switch (vertical_align) {
		case ALIGN_BOTTOM:
			mCanvas.translate(0,actualBitmapHeight - bitmapHeight);
			break;
		case ALIGN_TOP:
			break;
		case ALIGN_CENTER:
		default:
			mCanvas.translate(0, (actualBitmapHeight - bitmapHeight) / 2);
		}

		view.draw(mCanvas);
           if (textLayout != null) {
               // Draw the text using the TextLayout if one is provided
               mCanvas.translate(0, (actualBitmapHeight - bitmapHeight) / 2);
               textLayout.draw(mCanvas);
           }

		mCanvas.restore();
	}
	return destBitmap;
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:37,代码来源:ArtworkFactory.java

示例2: getUpdatePageTask

import android.graphics.Bitmap; //导入方法依赖的package包/类
protected CancellableTaskDefinition<Void, Void> getUpdatePageTask(final Bitmap bm, final int sizeX, final int sizeY,
		final int patchX, final int patchY, final int patchWidth, final int patchHeight)
{
	return new MuPDFCancellableTaskDefinition<Void, Void>(mCore) {

		@Override
		public Void doInBackground(MuPDFCore.Cookie cookie, Void ... params) {
			// Workaround bug in Android Honeycomb 3.x, where the bitmap generation count
			// is not incremented when drawing.
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB &&
					Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH)
				bm.eraseColor(0);
			mCore.updatePage(bm, mPageNumber, sizeX, sizeY, patchX, patchY, patchWidth, patchHeight, cookie);
			return null;
		}
	};
}
 
开发者ID:ArtifexSoftware,项目名称:mupdf-android-viewer-old,代码行数:18,代码来源:MuPDFPageView.java

示例3: getUpdatePageTask

import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override
protected CancellableTaskDefinition<Void, Void> getUpdatePageTask(final Bitmap bm, final int sizeX, final int sizeY,
		final int patchX, final int patchY, final int patchWidth, final int patchHeight)
{
	return new MuPDFCancellableTaskDefinition<Void, Void>(mCore) {

		@Override
		public Void doInBackground(MuPDFCore.Cookie cookie, Void ... params) {
			// Workaround bug in Android Honeycomb 3.x, where the bitmap generation count
			// is not incremented when drawing.
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB &&
					Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH)
				bm.eraseColor(0);
			mCore.updatePage(bm, mPageNumber, sizeX, sizeY, patchX, patchY, patchWidth, patchHeight, cookie);
			return null;
		}
	};
}
 
开发者ID:do-android,项目名称:do_PDFView,代码行数:19,代码来源:MuPDFPageView.java

示例4: createBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
public static Bitmap createBitmap(int width, int height, Bitmap.Config config) {
    Bitmap bitmap;
    if (Build.VERSION.SDK_INT < 21) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inDither = true;
        options.inPreferredConfig = config;
        options.inPurgeable = true;
        options.inSampleSize = 1;
        options.inMutable = true;
        byte[] array = jpegData.get();
        array[76] = (byte) (height >> 8);
        array[77] = (byte) (height & 0x00ff);
        array[78] = (byte) (width >> 8);
        array[79] = (byte) (width & 0x00ff);
        bitmap = BitmapFactory.decodeByteArray(array, 0, array.length, options);
        Utilities.pinBitmap(bitmap);
        bitmap.setHasAlpha(true);
        bitmap.eraseColor(0);
    } else {
        bitmap = Bitmap.createBitmap(width, height, config);
    }
    if (config == Bitmap.Config.ARGB_8888 || config == Bitmap.Config.ARGB_4444) {
        bitmap.eraseColor(Color.TRANSPARENT);
    }
    return bitmap;
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:27,代码来源:Bitmaps.java

示例5: getThumbnailImage

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * as a side effect - the method deselects Entity (if any selected)
 * @return bitmap with all the Entities at their current positions
 */
public Bitmap getThumbnailImage() {
  selectEntity(null, false);

  Bitmap bmp = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
  // IMPORTANT: always create white background, cos if the image is saved in JPEG format,
  // which doesn't have transparent pixels, the background will be black
  bmp.eraseColor(Color.WHITE);
  Canvas canvas = new Canvas(bmp);
  drawAllEntities(canvas);

  return bmp;
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:17,代码来源:MotionView.java

示例6: get

import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override
@NonNull
public Bitmap get(int width, int height, Bitmap.Config config) {
  Bitmap result = getDirtyOrNull(width, height, config);
  if (result != null) {
    // Bitmaps in the pool contain random data that in some cases must be cleared for an image
    // to be rendered correctly. we shouldn't force all consumers to independently erase the
    // contents individually, so we do so here. See issue #131.
    result.eraseColor(Color.TRANSPARENT);
  } else {
    result = Bitmap.createBitmap(width, height, config);
  }

  return result;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:LruBitmapPool.java

示例7: createBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * Creates a bitmap with the specified width and height.  Its initial density is
 * determined from the given DisplayMetrics.
 *
 * @param display Display metrics for the display this bitmap will be drawn on
 * @param width The width of the bitmap
 * @param height The height of the bitmap
 * @param config The bitmap config to create
 * @param hasAlpha If the bitmap is ARGB_8888 this flag can be used to mark the bitmap as opaque
 * Doing so will clear the bitmap in black instead of transparent
 * @param callerContext the Tag to track who create the Bitmap
 * @return a reference to the bitmap
 * @throws IllegalArgumentException if the width or height are <= 0
 * @throws TooManyBitmapsException if the pool is full
 * @throws java.lang.OutOfMemoryError if the Bitmap cannot be allocated
 */
private CloseableReference<Bitmap> createBitmap(
    DisplayMetrics display,
    int width,
    int height,
    Bitmap.Config config,
    boolean hasAlpha,
    @Nullable Object callerContext) {
  checkWidthHeight(width, height);
  CloseableReference<Bitmap> bitmapRef = createBitmapInternal(width, height, config);

  Bitmap bitmap = bitmapRef.get();
  if (display != null) {
    bitmap.setDensity(display.densityDpi);
  }

  if (Build.VERSION.SDK_INT >= 12) {
    bitmap.setHasAlpha(hasAlpha);
  }

  if (config == Bitmap.Config.ARGB_8888 && !hasAlpha) {
    bitmap.eraseColor(0xff000000);
  }

  addBitmapReference(bitmapRef.get(), callerContext);
  return bitmapRef;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:43,代码来源:PlatformBitmapFactory.java

示例8: getBadgeBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override
public Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap,
        int imageWidth, int imageHeight) {
    if (info.isCustomWidget || info.getProfile().equals(android.os.Process.myUserHandle())) {
        return bitmap;
    }

    // Add a user badge in the bottom right of the image.
    final Resources res = mContext.getResources();
    final int badgeMinTop = res.getDimensionPixelSize(R.dimen.profile_badge_minimum_top);

    // choose min between badge size defined for widget tray versus width, height of the image.
    // Width, height of the image can be smaller than widget tray badge size when being dropped
    // to the workspace.
    final int badgeSize = Math.min(res.getDimensionPixelSize(R.dimen.profile_badge_size),
            Math.min(imageWidth, imageHeight - badgeMinTop));
    final Rect badgeLocation = new Rect(0, 0, badgeSize, badgeSize);

    final int top = Math.max(imageHeight - badgeSize, badgeMinTop);

    if (res.getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
        badgeLocation.offset(0, top);
    } else {
        badgeLocation.offset(bitmap.getWidth() - badgeSize, top);
    }

    Drawable drawable = mPm.getUserBadgedDrawableForDensity(
            new BitmapDrawable(res, bitmap), info.getProfile(), badgeLocation, 0);

    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }

    bitmap.eraseColor(Color.TRANSPARENT);
    Canvas c = new Canvas(bitmap);
    drawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
    drawable.draw(c);
    c.setBitmap(null);
    return bitmap;
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:41,代码来源:AppWidgetManagerCompatVL.java

示例9: capture

import android.graphics.Bitmap; //导入方法依赖的package包/类
public static Bitmap capture(View view, float width, float height, boolean scroll, Bitmap.Config config) {
    if (!view.isDrawingCacheEnabled()) {
        view.setDrawingCacheEnabled(true);
    }
    if(width==0){
        width= MainApp.getInstance().getScreenWidth();
    }
    if(height==0){
        height= MainApp.getInstance().getScreenHeight();
    }

    Bitmap bitmap = Bitmap.createBitmap((int) width, (int) height, config);
    bitmap.eraseColor(Color.WHITE);
    Canvas canvas = new Canvas(bitmap);
    int left = view.getLeft();
    int top = view.getTop();
    if (scroll) {
        left = view.getScrollX();
        top = view.getScrollY();
    }
    int status = canvas.save();
    canvas.translate(-left, -top);
    float scale = width / view.getWidth();
    canvas.scale(scale, scale, left, top);
    view.draw(canvas);
    canvas.restoreToCount(status);
    Paint alphaPaint = new Paint();
    alphaPaint.setColor(Color.TRANSPARENT);
    canvas.drawRect(0f, 0f, 1f, height, alphaPaint);
    canvas.drawRect(width - 1f, 0f, width, height, alphaPaint);
    canvas.drawRect(0f, 0f, width, 1f, alphaPaint);
    canvas.drawRect(0f, height - 1f, width, height, alphaPaint);
    canvas.setBitmap(null);
    return bitmap;
}
 
开发者ID:NewCasino,项目名称:browser,代码行数:36,代码来源:ScreenShotUtil.java

示例10: loadBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
private Bitmap loadBitmap(int width, int height, int index) {
	Bitmap b = Bitmap.createBitmap(width, height,
			Bitmap.Config.ARGB_8888);
	b.eraseColor(0xFFFFFFFF);
	Canvas c = new Canvas(b);
	Drawable d = getResources().getDrawable(mBitmapIds[index]);

	int margin = 7;
	int border = 3;
	Rect r = new Rect(margin, margin, width - margin, height - margin);

	int imageWidth = r.width() - (border * 2);
	int imageHeight = imageWidth * d.getIntrinsicHeight()
			/ d.getIntrinsicWidth();
	if (imageHeight > r.height() - (border * 2)) {
		imageHeight = r.height() - (border * 2);
		imageWidth = imageHeight * d.getIntrinsicWidth()
				/ d.getIntrinsicHeight();
	}

	r.left += ((r.width() - imageWidth) / 2) - border;
	r.right = r.left + imageWidth + border + border;
	r.top += ((r.height() - imageHeight) / 2) - border;
	r.bottom = r.top + imageHeight + border + border;

	Paint p = new Paint();
	p.setColor(0xFFC0C0C0);
	c.drawRect(r, p);
	r.left += border;
	r.right -= border;
	r.top += border;
	r.bottom -= border;

	d.setBounds(r);
	d.draw(c);

	return b;
}
 
开发者ID:ichason,项目名称:PageCurl,代码行数:39,代码来源:CurlActivity.java

示例11: makeIcon

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * Creates an icon with the current content and style.
 * <p/>
 * This method is useful if a custom view has previously been set, or if text content is not
 * applicable.
 */
public Bitmap makeIcon() {
  int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
  mContainer.measure(measureSpec, measureSpec);

  int measuredWidth = mContainer.getMeasuredWidth();
  int measuredHeight = mContainer.getMeasuredHeight();

  mContainer.layout(0, 0, measuredWidth, measuredHeight);

  if (mRotation == 1 || mRotation == 3) {
    measuredHeight = mContainer.getMeasuredWidth();
    measuredWidth = mContainer.getMeasuredHeight();
  }

  Bitmap r = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888);
  r.eraseColor(Color.TRANSPARENT);

  Canvas canvas = new Canvas(r);

  if (mRotation == 0) {
    // do nothing
  } else if (mRotation == 1) {
    canvas.translate(measuredWidth, 0);
    canvas.rotate(90);
  } else if (mRotation == 2) {
    canvas.rotate(180, measuredWidth / 2, measuredHeight / 2);
  } else {
    canvas.translate(0, measuredHeight);
    canvas.rotate(270);
  }
  mContainer.draw(canvas);
  return r;
}
 
开发者ID:mapbox,项目名称:mapbox-plugins-android,代码行数:40,代码来源:IconGenerator.java

示例12: setTexture

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * Setter for textures.
 */
public void setTexture(Bitmap texture, int side) {
	if (texture == null) {
		texture = Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565);
		if (side == SIDE_BACK) {
			texture.eraseColor(mColorBack);
		} else {
			texture.eraseColor(mColorFront);
		}
	}
	switch (side) {
	case SIDE_FRONT:
		if (mTextureFront != null)
			mTextureFront.recycle();
		mTextureFront = texture;
		break;
	case SIDE_BACK:
		if (mTextureBack != null)
			mTextureBack.recycle();
		mTextureBack = texture;
		break;
	case SIDE_BOTH:
		if (mTextureFront != null)
			mTextureFront.recycle();
		if (mTextureBack != null)
			mTextureBack.recycle();
		mTextureFront = mTextureBack = texture;
		break;
	}
	mTexturesChanged = true;
}
 
开发者ID:ichason,项目名称:PageCurl,代码行数:34,代码来源:CurlPage.java

示例13: GifDrawable

import android.graphics.Bitmap; //导入方法依赖的package包/类
GifDrawable(GifInfoHandle gifInfoHandle, final GifDrawable oldDrawable,
		ScheduledThreadPoolExecutor executor,
		boolean isRenderingTriggeredOnDraw) {
	mIsRenderingTriggeredOnDraw = isRenderingTriggeredOnDraw;
	mExecutor = executor != null ? executor : GifRenderingExecutor
			.getInstance();
	mNativeInfoHandle = gifInfoHandle;
	Bitmap oldBitmap = null;
	if (oldDrawable != null) {
		synchronized (oldDrawable.mNativeInfoHandle) {
			if (!oldDrawable.mNativeInfoHandle.isRecycled()) {
				if (oldDrawable.mNativeInfoHandle.height >= mNativeInfoHandle.height
						&& oldDrawable.mNativeInfoHandle.width >= mNativeInfoHandle.width) {
					oldDrawable.shutdown();
					oldBitmap = oldDrawable.mBuffer;
					oldBitmap.eraseColor(Color.TRANSPARENT);
				}
			}
		}
	}

	if (oldBitmap == null) {
		mBuffer = Bitmap.createBitmap(mNativeInfoHandle.width,
				mNativeInfoHandle.height, Bitmap.Config.ARGB_8888);
	} else {
		mBuffer = oldBitmap;
	}

	mSrcRect = new Rect(0, 0, mNativeInfoHandle.width,
			mNativeInfoHandle.height);
	mInvalidationHandler = new InvalidationHandler(this);
	if (mIsRenderingTriggeredOnDraw) {
		mNextFrameRenderTime = 0;
	} else {
		mExecutor.execute(mRenderTask);
	}
}
 
开发者ID:smartbeng,项目名称:PaoMovie,代码行数:38,代码来源:GifDrawable.java

示例14: createSolid

import android.graphics.Bitmap; //导入方法依赖的package包/类
public static SmartTexture createSolid(int color) {
	final String key = "1x1:" + color;

	if (all.containsKey(key)) {

		return all.get(key);

	} else {

		Bitmap bmp = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
		bmp.eraseColor(color);

		SmartTexture tx = new SmartTexture(bmp);
		all.put(key, tx);

		return tx;
	}
}
 
开发者ID:G2159687,项目名称:ESPD,代码行数:19,代码来源:TextureCache.java

示例15: createTextBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * Draw a multiple lines text bitmap. The size of the bitmap is returned in rectTxtBox
 */
public Bitmap createTextBitmap(String text, Paint paint, com.cyzapps.VisualMFP.Color color, double dTextSize, Rect rectOrigTxtBox) {
	if (text == null)	{
		text = "";	// null pointer protection.
	}
    // First of all, calculate text bound
    int nPaintOriginalColor = paint.getColor();
    if (color != null)    {
        paint.setColor(color.getARGB());
    }    // otherwise, use paint's color.
    float fOriginalTxtSize = paint.getTextSize();
    paint.setTextSize((float) dTextSize);
    
    String[] lines = text.split("\n");
    double dSpaceBtwTxtLines = dTextSize/5.0;
    Rect rectTxtBox = calcTextBounds(text, paint, dTextSize, dSpaceBtwTxtLines);
    rectOrigTxtBox.set(rectTxtBox);
    Rect rectAdjustBox = new Rect();
    rectAdjustBox.left = 0;
    rectAdjustBox.top = 0;
    // need 2 ** integer power otherwise some devices cannot show.
    if (rectTxtBox.width() <= 0)	{
    	rectAdjustBox.right = 2;	// was 0, but createBitmap would fail if 0
    } else	{
    	rectAdjustBox.right = getNextHighestPO2(rectTxtBox.width());
    }
    if (rectTxtBox.height() <= 0)	{
    	rectAdjustBox.bottom = 2;	// was 0, but createBitmap would fail if 0
    } else	{
    	rectAdjustBox.bottom = getNextHighestPO2(rectTxtBox.height());
    }
   
    // Create an empty, mutable bitmap
    Bitmap bitmap = Bitmap.createBitmap(rectAdjustBox.width(), rectAdjustBox.height(), Bitmap.Config.ARGB_8888);
    // get a canvas to paint over the bitmap
    Canvas canvas = new Canvas(bitmap);
    bitmap.eraseColor(0);
    // get a background image from resources
    // note the image format must match the bitmap format

    Drawable background = new ColorDrawable(0x00000000);
    background.setBounds(0, 0, rectAdjustBox.width(), rectAdjustBox.height());
    background.draw(canvas); // draw the background to our bitmap
   
    float fX = 0, fY = /*rectTxtBox.height();*/-(float)paint.ascent();    // drawText's y parameter is the baseline of the character. Note that paint.ascent() is negative.
    int yOff = 0;   
    for (int i = 0; i < lines.length; ++i) {
        canvas.drawText(lines[i], fX, fY + yOff, paint);
        yOff = (int) (yOff + (int)Math.ceil(-paint.ascent() + paint.descent()) + dSpaceBtwTxtLines); // space between lines
    }

    paint.setTextSize(fOriginalTxtSize);
    paint.setColor(nPaintOriginalColor);
   
    return bitmap;
}
 
开发者ID:woshiwpa,项目名称:SmartMath,代码行数:59,代码来源:OGLChart.java


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