本文整理汇总了Java中android.graphics.Bitmap.hasAlpha方法的典型用法代码示例。如果您正苦于以下问题:Java Bitmap.hasAlpha方法的具体用法?Java Bitmap.hasAlpha怎么用?Java Bitmap.hasAlpha使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Bitmap
的用法示例。
在下文中一共展示了Bitmap.hasAlpha方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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]);
}
示例2: getFormat
import android.graphics.Bitmap; //导入方法依赖的package包/类
private Bitmap.CompressFormat getFormat(Bitmap bitmap, Options options) {
Bitmap.CompressFormat format = options.get(COMPRESSION_FORMAT);
if (format != null) {
return format;
} else if (bitmap.hasAlpha()) {
return Bitmap.CompressFormat.PNG;
} else {
return Bitmap.CompressFormat.JPEG;
}
}
示例3: compress
import android.graphics.Bitmap; //导入方法依赖的package包/类
private static boolean compress(Bitmap bitmap, String outfile, int quality) {
if (bitmap == null || bitmap.isRecycled())
return false;
if (bitmap.hasAlpha()) {
return CompatCompressor.compress(bitmap, outfile, quality, Bitmap.CompressFormat.PNG);
} else {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
return JpegTurboCompressor.compress(bitmap, outfile, quality);
} else {
return CompatCompressor.compress(bitmap, outfile, quality, Bitmap.CompressFormat.JPEG);
}
}
}
示例4: getOpacity
import android.graphics.Bitmap; //导入方法依赖的package包/类
public int getOpacity() {
if (this.mGravity != Opcodes.INVOKE_STATIC_RANGE || this.mIsCircular) {
return -3;
}
Bitmap bm = this.mBitmap;
if (bm == null || bm.hasAlpha() || this.mPaint.getAlpha() < 255 || isGreaterThanZero(this.mCornerRadius)) {
return -3;
}
return -1;
}
示例5: compress
import android.graphics.Bitmap; //导入方法依赖的package包/类
protected String compress(Bitmap bitmap, CompressSpec compressSpec) {
int quality = compressSpec.options.quality;
String outfile = null;
float size = compressSpec.options.maxSize;
if (quality < 0 || quality > 100)
quality = CompressSpec.DEFAULT_QUALITY;
if (bitmap.hasAlpha()) {
outfile = FileUtil.generateCompressOutfileFormatPNG(compressSpec.dir, null).getAbsolutePath();
} else {
outfile = FileUtil.generateCompressOutfileFormatJPEG(compressSpec.dir, null).getAbsolutePath();
}
boolean isSuccess = compress(bitmap, outfile, quality);
if (size > 0 && isSuccess) {
float outfileSize = (float) FileUtil.getSizeInBytes(outfile) / (float) 1024;
while (outfileSize > size) {
if (quality <= 25)
break;
quality -= 5;
isSuccess = compress(bitmap, outfile, quality);
if (!isSuccess)
break;
outfileSize = (float) FileUtil.getSizeInBytes(outfile) / (float) 1024;
}
}
Logger.i("final compress quality: " + quality);
if (bitmap != mT) {
bitmap.recycle();
bitmap = null;
System.gc();
System.runFinalization();
}
return outfile;
}
示例6: 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);
}
示例7: compress
import android.graphics.Bitmap; //导入方法依赖的package包/类
private static boolean compress(Bitmap bitmap, String outfile, int quality) throws FileNotFoundException {
if (bitmap == null || bitmap.isRecycled())
return false;
if (bitmap.hasAlpha()) {
return CompatCompressor.compress(bitmap, outfile, quality, Bitmap.CompressFormat.PNG);
} else {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
return JpegTurboCompressor.compress(bitmap, outfile, quality);
} else {
return CompatCompressor.compress(bitmap, outfile, quality, Bitmap.CompressFormat.JPEG);
}
}
}
示例8: draw
import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override
public void draw(Context context, Canvas canvas) {
ImageSticker imageSticker = (ImageSticker) sticker;
if (imageSticker.imageFile == null || imageSticker.imageFile.exists() == false) {
return;
}
BitmapFactory.Options options = new BitmapFactory.Options();
if (alpha < 1f) {
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
}
Bitmap bitmap = BitmapFactory.decodeFile(imageSticker.imageFile.getAbsolutePath(), options);
if (alpha < 1f && bitmap.hasAlpha() == false) {
Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas newCanvas = new Canvas(newBitmap);
newCanvas.drawBitmap(bitmap, 0, 0, null);
bitmap.recycle();
bitmap = newBitmap;
}
int canvasWidth = canvas.getWidth();
int canvasHeight = canvas.getHeight();
float bitmapWidth = bitmap.getWidth();
float bitmapHeight = bitmap.getHeight();
float scale = (canvasWidth * widthRatio) / bitmapWidth ;
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, (int) (bitmapWidth * scale), (int) (bitmapHeight * scale), true);
if (scaledBitmap != bitmap) {
bitmap.recycle();
}
bitmap = scaledBitmap;
bitmapWidth = bitmap.getWidth();
bitmapHeight = bitmap.getHeight();
Matrix matrix = new Matrix();
matrix.reset();
matrix.postTranslate((canvasWidth - bitmapWidth) / 2, (canvasHeight - bitmapHeight) / 2);
matrix.postRotate(angle, canvasWidth / 2, canvasHeight / 2);
matrix.postTranslate(canvasWidth / 2 * posX, canvasHeight / 2 * posY);
Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
paint.setAlpha((int) (alpha * 255));
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);
canvas.drawBitmap(bitmap, matrix, paint);
bitmap.recycle();
}