Java Code Examples for android.graphics.Bitmap.hasAlpha()

The following are Jave code examples for showing how to use hasAlpha() of the android.graphics.Bitmap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: react-native-webgl-view-shot   File: RNWebGLTextureView.java   View Source Code Vote up 6 votes
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]);
}
 
Example 2
Project: GitHub   File: BitmapEncoder.java   View Source Code Vote up 5 votes
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;
  }
}
 
Example 3
Project: GitHub   File: BitmapEncoder.java   View Source Code Vote up 5 votes
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;
  }
}
 
Example 4
Project: tiny   File: FileCompressor.java   View Source Code Vote up 5 votes
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);
        }
    }
}
 
Example 5
Project: boohee_v5.6   File: RoundedBitmapDrawable.java   View Source Code Vote up 5 votes
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;
}
 
Example 6
Project: Flora   File: CompressCallable.java   View Source Code Vote up 5 votes
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;
}
 
Example 7
Project: Flora   File: CompressCallable.java   View Source Code Vote up 5 votes
protected boolean compress(Bitmap bitmap, String outfile, int quality) {
    if (bitmap == null || bitmap.isRecycled())
        return false;

    if (bitmap.hasAlpha()) {
        return compress(bitmap, outfile, quality, Bitmap.CompressFormat.PNG);
    } else {
        return compress(bitmap, outfile, quality, Bitmap.CompressFormat.JPEG);
    }
}
 
Example 8
Project: starcor.xul   File: XulWorker.java   View Source Code Vote up 5 votes
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);
}
 
Example 9
Project: Tiny   File: FileCompressor.java   View Source Code Vote up 5 votes
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);
        }
    }
}
 
Example 10
Project: SmingZZick_App   File: ImageStickerAttachInfo.java   View Source Code Vote up 4 votes
@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();
}
 
Example 11
Project: tiny   File: FileCompressor.java   View Source Code Vote up 4 votes
public static CompressResult compress(Bitmap bitmap, Tiny.FileCompressOptions options, boolean withBitmap, boolean recycle) {
    if (bitmap == null || bitmap.isRecycled())
        return null;

    CompressResult result = new CompressResult();

    if (options == null)
        options = new Tiny.FileCompressOptions();

    int quality = options.quality;
    String outfile = options.outfile;
    float size = options.size;

    if (quality < 0 || quality > 100)
        quality = CompressKit.DEFAULT_QUALITY;

    if (Conditions.isDirectory(outfile))
        outfile = FileKit.generateCompressOutfileFormatJPEG().getAbsolutePath();

    if (!Conditions.isJpegFormat(outfile))
        outfile = FileKit.generateCompressOutfileFormatJPEG().getAbsolutePath();

    if (bitmap.hasAlpha())
        outfile = FileKit.generateCompressOutfileFormatPNG().getAbsolutePath();

    boolean isSuccess = compress(bitmap, outfile, quality);

    if (size > 0 && isSuccess) {
        float outfileSize = (float) FileKit.getSizeInBytes(outfile) / (float) 1024;
        while (outfileSize > size) {
            if (quality <= 25)
                break;
            quality -= 5;
            isSuccess = compress(bitmap, outfile, quality);
            if (!isSuccess)
                break;
            outfileSize = (float) FileKit.getSizeInBytes(outfile) / (float) 1024;
        }
    }

    Logger.e("compress quality: " + quality);

    result.outfile = outfile;
    result.success = isSuccess;

    if (withBitmap) {
        result.bitmap = bitmap;
    } else {
        if (recycle) {
            result.bitmap = null;
            bitmap.recycle();
            bitmap = null;
        }
    }
    return result;
}