本文整理汇总了Java中android.graphics.Bitmap.setHasAlpha方法的典型用法代码示例。如果您正苦于以下问题:Java Bitmap.setHasAlpha方法的具体用法?Java Bitmap.setHasAlpha怎么用?Java Bitmap.setHasAlpha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Bitmap
的用法示例。
在下文中一共展示了Bitmap.setHasAlpha方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFitCenterSetsOutBitmapToHaveAlphaIfInBitmapHasAlphaAndOutBitmapIsReused
import android.graphics.Bitmap; //导入方法依赖的package包/类
@Test
public void testFitCenterSetsOutBitmapToHaveAlphaIfInBitmapHasAlphaAndOutBitmapIsReused() {
Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Bitmap toReuse = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
reset(bitmapPool);
when(bitmapPool.get(eq(toReuse.getWidth()), eq(toReuse.getHeight()), eq(toReuse.getConfig())))
.thenReturn(toReuse);
toReuse.setHasAlpha(false);
toTransform.setHasAlpha(true);
Bitmap result = TransformationUtils.fitCenter(bitmapPool, toTransform, toReuse.getWidth(),
toReuse.getHeight());
assertEquals(toReuse, result);
assertTrue(result.hasAlpha());
}
示例2: testCenterCropSetsOutBitmapToHaveAlphaIfInBitmapHasAlphaAndOutBitmapIsReused
import android.graphics.Bitmap; //导入方法依赖的package包/类
@Test
public void testCenterCropSetsOutBitmapToHaveAlphaIfInBitmapHasAlphaAndOutBitmapIsReused() {
Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Bitmap toReuse = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
reset(bitmapPool);
when(bitmapPool.get(eq(50), eq(50), eq(Bitmap.Config.ARGB_8888)))
.thenReturn(toReuse);
toReuse.setHasAlpha(false);
toTransform.setHasAlpha(true);
Bitmap result = TransformationUtils.centerCrop(bitmapPool, toTransform, toReuse.getWidth(),
toReuse.getHeight());
assertEquals(toReuse, result);
assertTrue(result.hasAlpha());
}
示例3: testCenterCropSetsOutBitmapToNotHaveAlphaIfInBitmapDoesNotHaveAlphaAndOutBitmapIsReused
import android.graphics.Bitmap; //导入方法依赖的package包/类
@Test
public void
testCenterCropSetsOutBitmapToNotHaveAlphaIfInBitmapDoesNotHaveAlphaAndOutBitmapIsReused() {
Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Bitmap toReuse = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
reset(bitmapPool);
when(bitmapPool.get(eq(50), eq(50), eq(Bitmap.Config.ARGB_8888))).thenReturn(toReuse);
toReuse.setHasAlpha(true);
toTransform.setHasAlpha(false);
Bitmap result = TransformationUtils.centerCrop(bitmapPool, toTransform, toReuse.getWidth(),
toReuse.getHeight());
assertEquals(toReuse, result);
assertFalse(result.hasAlpha());
}
示例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;
}
示例5: run
import android.graphics.Bitmap; //导入方法依赖的package包/类
public void run() {
Bitmap bitmap;
try {
bitmap = captureView(view);
}
catch (Exception e) {
return;
}
if (yflip) {
Matrix matrix = new Matrix();
matrix.postScale(1, -1);
boolean hasAlpha = bitmap.hasAlpha();
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
bitmap.setHasAlpha(hasAlpha);
}
int[] textures = new int[1];
glGenTextures(1, textures, 0);
glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
GLUtils.texImage2D(GL_TEXTURE_2D, 0, bitmap, 0);
this.attachTexture(textures[0]);
}
示例6: testFitCenterSetsOutBitmapToHaveAlphaIfInBitmapHasAlpha
import android.graphics.Bitmap; //导入方法依赖的package包/类
@Test
public void testFitCenterSetsOutBitmapToHaveAlphaIfInBitmapHasAlpha() {
Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
toTransform.setHasAlpha(true);
Bitmap result = TransformationUtils.fitCenter(bitmapPool, toTransform,
toTransform.getWidth() / 2, toTransform.getHeight() / 2);
assertTrue(result.hasAlpha());
}
示例7: testCenterCropSetsOutBitmapToNotHaveAlphaIfInBitmapDoesNotHaveAlpha
import android.graphics.Bitmap; //导入方法依赖的package包/类
@Test
public void testCenterCropSetsOutBitmapToNotHaveAlphaIfInBitmapDoesNotHaveAlpha() {
Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
toTransform.setHasAlpha(false);
Bitmap result = TransformationUtils.centerCrop(bitmapPool, toTransform,
toTransform.getWidth() / 2, toTransform.getHeight() / 2);
assertFalse(result.hasAlpha());
}
示例8: testCenterCropSetsOutBitmapToHaveAlphaIfInBitmapHasAlpha
import android.graphics.Bitmap; //导入方法依赖的package包/类
@Test
public void testCenterCropSetsOutBitmapToHaveAlphaIfInBitmapHasAlpha() {
Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
toTransform.setHasAlpha(true);
Bitmap result = TransformationUtils.centerCrop(bitmapPool, toTransform,
toTransform.getWidth() / 2, toTransform.getHeight() / 2);
assertTrue(result.hasAlpha());
}
示例9: 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;
}
示例10: process
import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override
public void process(Bitmap output, Bitmap source) {
cornerRadii(sComputedCornerRadii);
output.setHasAlpha(true);
if (FloatUtil.floatsEqual(sComputedCornerRadii[0], 0f) &&
FloatUtil.floatsEqual(sComputedCornerRadii[1], 0f) &&
FloatUtil.floatsEqual(sComputedCornerRadii[2], 0f) &&
FloatUtil.floatsEqual(sComputedCornerRadii[3], 0f)) {
super.process(output, source);
return;
}
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
Canvas canvas = new Canvas(output);
float[] radii = new float[8];
getRadii(source, sComputedCornerRadii, radii);
Path pathForBorderRadius = new Path();
pathForBorderRadius.addRoundRect(
new RectF(0, 0, source.getWidth(), source.getHeight()),
radii,
Path.Direction.CW);
canvas.drawPath(pathForBorderRadius, paint);
}
示例11: roundedCorners
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* Creates a bitmap from a source bitmap and rounds the corners.
*
* <p>This method does <em>NOT</em> resize the given {@link Bitmap}, it only rounds it's corners.
* To both resize and round the corners of an image, consider
* {@link com.bumptech.glide.request.RequestOptions#transforms(Transformation[])} and/or
* {@link com.bumptech.glide.load.MultiTransformation}.
*
* @param inBitmap the source bitmap to use as a basis for the created bitmap.
* @param roundingRadius the corner radius to be applied (in device-specific pixels).
* @return a {@link Bitmap} similar to inBitmap but with rounded corners.
* @throws IllegalArgumentException if roundingRadius, width or height is 0 or less.
*/
public static Bitmap roundedCorners(
@NonNull BitmapPool pool, @NonNull Bitmap inBitmap, int roundingRadius) {
Preconditions.checkArgument(roundingRadius > 0, "roundingRadius must be greater than 0.");
// Alpha is required for this transformation.
Bitmap toTransform = getAlphaSafeBitmap(pool, inBitmap);
Bitmap result =
pool.get(toTransform.getWidth(), toTransform.getHeight(), Bitmap.Config.ARGB_8888);
result.setHasAlpha(true);
BitmapShader shader = new BitmapShader(toTransform, Shader.TileMode.CLAMP,
Shader.TileMode.CLAMP);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(shader);
RectF rect = new RectF(0, 0, result.getWidth(), result.getHeight());
BITMAP_DRAWABLE_LOCK.lock();
try {
Canvas canvas = new Canvas(result);
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
canvas.drawRoundRect(rect, roundingRadius, roundingRadius, paint);
clear(canvas);
} finally {
BITMAP_DRAWABLE_LOCK.unlock();
}
if (!toTransform.equals(inBitmap)) {
pool.put(toTransform);
}
return result;
}
示例12: createBitmapWithRedCircle
import android.graphics.Bitmap; //导入方法依赖的package包/类
private Bitmap createBitmapWithRedCircle(int width, int height) {
int minEdge = Math.min(width, height);
float radius = minEdge / 2f;
Bitmap result = Bitmap.createBitmap(minEdge, minEdge, Bitmap.Config.ARGB_8888);
result.setHasAlpha(true);
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.RED);
canvas.drawCircle(radius, radius, radius, paint);
return result;
}
示例13: getBitmap
import android.graphics.Bitmap; //导入方法依赖的package包/类
public Bitmap getBitmap(boolean isAlpha) {
Bitmap bitmap = Bitmap.createBitmap(DisplayUtils.dp2px(getContext(), WIDTH),
DisplayUtils.dp2px(getContext(), HEIGHT),
Bitmap.Config.ARGB_8888);
bitmap.setHasAlpha(isAlpha);
Canvas canvas = new Canvas(bitmap);
if (!isAlpha) {
canvas.drawColor(Color.WHITE);
}
draw(canvas);
return bitmap;
}
示例14: takeScreenshot
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* Takes Reboot screenshot of the current display and shows an animation.
*/
@SuppressLint("NewApi")
public void takeScreenshot(Context context, String fileFullPath)
{
if(fileFullPath == ""){
format = new SimpleDateFormat("yyyyMMddHHmmss");
String fileName = format.format(new Date(System.currentTimeMillis())) + ".png";
fileFullPath = "/data/local/tmp/" + fileName;
}
if(ShellUtils.checkRootPermission()){
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH){
ShellUtils.execCommand("/system/bin/screencap -p "+ fileFullPath,true);
}
}
else {
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2 && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH){
wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
mDisplay = wm.getDefaultDisplay();
mDisplayMatrix = new Matrix();
mDisplayMetrics = new DisplayMetrics();
// We need to orient the screenshot correctly (and the Surface api seems to take screenshots
// only in the natural orientation of the device :!)
mDisplay.getRealMetrics(mDisplayMetrics);
float[] dims =
{
mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels
};
float degrees = getDegreesForRotation(mDisplay.getRotation());
boolean requiresRotation = (degrees > 0);
if (requiresRotation)
{
// Get the dimensions of the device in its native orientation
mDisplayMatrix.reset();
mDisplayMatrix.preRotate(-degrees);
mDisplayMatrix.mapPoints(dims);
dims[0] = Math.abs(dims[0]);
dims[1] = Math.abs(dims[1]);
}
Bitmap mScreenBitmap = screenShot((int) dims[0], (int) dims[1]);
if (requiresRotation)
{
// Rotate the screenshot to the current orientation
Bitmap ss = Bitmap.createBitmap(mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels,
Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(ss);
c.translate(ss.getWidth() / 2, ss.getHeight() / 2);
c.rotate(degrees);
c.translate(-dims[0] / 2, -dims[1] / 2);
c.drawBitmap(mScreenBitmap, 0, 0, null);
c.setBitmap(null);
mScreenBitmap = ss;
if (ss != null && !ss.isRecycled())
{
ss.recycle();
}
}
// If we couldn't take the screenshot, notify the user
if (mScreenBitmap == null)
{
Toast.makeText(context, "screen shot fail", Toast.LENGTH_SHORT).show();
}
// Optimizations
mScreenBitmap.setHasAlpha(false);
mScreenBitmap.prepareToDraw();
saveBitmap2file(context, mScreenBitmap, fileFullPath);
}
}
}
示例15: centerCrop
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* 居中剪切图片
*/
public static Bitmap centerCrop(Resources res, Bitmap bitmap, int width, int height) {
if (bitmap == null) {
return null;
}
if (width == 0 || height == 0) {
return bitmap;
}
Bitmap result = Bitmap.createBitmap(width, height, bitmap.getConfig() != null
? bitmap.getConfig() : Bitmap.Config.ARGB_8888);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1 && result != null) {
result.setHasAlpha(bitmap.hasAlpha());
}
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);
Canvas canvas = new Canvas(result);
Paint paint = new Paint(Paint.DITHER_FLAG | Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(bitmap, matrix, paint);
return result;
}