android.graphics.Bitmap

Here are the examples of the java api class android.graphics.Bitmap taken from open source projects.

1. BearSceneView#init()

View license
private void init() {
    renderables = new Renderable[17];
    Bitmap threeB = BitmapFactory.decodeResource(getResources(), R.mipmap.tree);
    addThree(threeB, getMeasuredWidth() * 0.18f, getMeasuredHeight() * -0.65f, 0.28f, 0.46f);
    addThree(threeB, getMeasuredWidth() * 0.6f, getMeasuredHeight() * -0.65f, 0.33f, 0.46f);
    addThree(threeB, getMeasuredWidth() * 0.45f, getMeasuredHeight() * -0.45f, 0.5f, 0.8f);
    addThree(threeB, getMeasuredWidth() * 0.13f, getMeasuredHeight() * -0.65f, 0.3f, 0.46f);
    addThree(threeB, getMeasuredWidth() * 0.83f, getMeasuredHeight() * -0.2f, 0.5f, 1f);
    addThree(threeB, getMeasuredWidth() * 0.02f, getMeasuredHeight() * -0.1f, 0.8f, 1f);
    addThree(threeB, getMeasuredWidth() * 0.18f, getMeasuredHeight() * 0.15f, 0.8f, 1f);
    addThree(threeB, getMeasuredWidth() * 0.7f, getMeasuredHeight() * -0.1f, 0.8f, 1f);
    Bitmap bear1 = BitmapFactory.decodeResource(getResources(), R.mipmap.bear_1);
    Bitmap bear2 = BitmapFactory.decodeResource(getResources(), R.mipmap.bear_2);
    Bitmap bear3 = BitmapFactory.decodeResource(getResources(), R.mipmap.bear_white);
    Bitmap stones = BitmapFactory.decodeResource(getResources(), R.drawable.stones);
    Bitmap smoke = BitmapFactory.decodeResource(getResources(), R.drawable.smoke);
    Bitmap grunge = BitmapFactory.decodeResource(getResources(), R.drawable.grunge);
    addFire(smoke, stones, getMeasuredWidth() * 0.61f, getMeasuredHeight() * 0.8f);
    addBear(getMeasuredWidth() * 0.636f, getMeasuredHeight() * 0.59f, bear1, bear2);
    addWhiteBear(getMeasuredWidth() * 0.44f, getMeasuredHeight() * 0.66f, bear3);
    setLayerType(View.LAYER_TYPE_HARDWARE, null);
    addGrunge(grunge);
}

2. MediaStorage#cacheThumbnail()

Project: androidclient
Source File: MediaStorage.java
View license
private static void cacheThumbnail(Context context, Uri media, FileOutputStream fout, boolean forNetwork) throws IOException {
    ContentResolver cr = context.getContentResolver();
    InputStream in = cr.openInputStream(media);
    BitmapFactory.Options options = preloadBitmap(in, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
    in.close();
    // open again
    in = cr.openInputStream(media);
    Bitmap bitmap = BitmapFactory.decodeStream(in, null, options);
    in.close();
    Bitmap thumbnail = ThumbnailUtils.extractThumbnail(bitmap, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
    bitmap.recycle();
    thumbnail = bitmapOrientation(context, media, thumbnail);
    // write down to file
    thumbnail.compress(forNetwork ? Bitmap.CompressFormat.JPEG : Bitmap.CompressFormat.PNG, forNetwork ? THUMBNAIL_MIME_COMPRESSION : 0, fout);
    thumbnail.recycle();
}

3. WaterSceneView#init()

View license
private void init() {
    renderables = new Renderable[4];
    Bitmap waterBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.water);
    Bitmap foam = BitmapFactory.decodeResource(getResources(), R.drawable.foam);
    setLayerType(View.LAYER_TYPE_HARDWARE, null);
    water = new Water(waterBitmap, foam, getYCoordByPercent(0.65f), getYCoordByPercent(1f), getXCoordByPercent(1f), 6);
    renderables[0] = water;
    Bitmap aura = BitmapFactory.decodeResource(getResources(), R.drawable.sun_aura);
    renderables[1] = new Renderable(aura, getXCoordByPercent(0.5f), getYCoordByPercent(0.35f));
    Bitmap noiseScratch = BitmapFactory.decodeResource(getResources(), R.drawable.noise_scratch);
    Bitmap noiseReg = BitmapFactory.decodeResource(getResources(), R.drawable.noise);
    noiseScratchEffect = new NoiseEffect(noiseScratch, 100, 2f);
    renderables[2] = noiseScratchEffect;
    noise = new NoiseEffect(noiseReg, 30, 1.5f);
    renderables[3] = noise;
    setNoiseIntensity(0.5f);
    setWaveHeight(50);
}

4. BitmapPoolTest#testIsReusable()

Project: fresco
Source File: BitmapPoolTest.java
View license
// Test out bitmap reusability
@Test
public void testIsReusable() throws Exception {
    Bitmap b1 = mPool.alloc(12);
    assertTrue(mPool.isReusable(b1));
    Bitmap b2 = MockBitmapFactory.create(3, 4, Bitmap.Config.ARGB_8888);
    assertTrue(mPool.isReusable(b2));
    Bitmap b3 = MockBitmapFactory.create(3, 4, Config.ARGB_4444);
    assertTrue(mPool.isReusable(b3));
    Bitmap b4 = MockBitmapFactory.create(3, 4, Bitmap.Config.ARGB_8888);
    doReturn(true).when(b4).isRecycled();
    assertFalse(mPool.isReusable(b4));
    Bitmap b5 = MockBitmapFactory.create(3, 4, Bitmap.Config.ARGB_8888);
    doReturn(false).when(b5).isMutable();
    assertFalse(mPool.isReusable(b5));
}

5. TexCubeSmallGLUT#setTex()

Project: opengl
Source File: TexCubeSmallGLUT.java
View license
void setTex(GL10 gl, Context c, int textureID, int drawableID) {
    mCoordBuffer = getFloatBufferFromFloatArray(texCoords);
    mTextureID = textureID;
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);
    Bitmap bitmap = BitmapFactory.decodeResource(c.getResources(), drawableID);
    Bitmap bitmap256 = Bitmap.createScaledBitmap(bitmap, 256, 256, false);
    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap256, 0);
    bitmap.recycle();
    bitmap256.recycle();
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
    texEnabled = true;
}

6. TexCubeSmallGLUT#setTex()

Project: opengl
Source File: TexCubeSmallGLUT.java
View license
void setTex(GL10 gl, Context c, int textureID, int drawableID) {
    mCoordBuffer = getFloatBufferFromFloatArray(texCoords);
    mTextureID = textureID;
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);
    Bitmap bitmap = BitmapFactory.decodeResource(c.getResources(), drawableID);
    Bitmap bitmap256 = Bitmap.createScaledBitmap(bitmap, 256, 256, false);
    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap256, 0);
    bitmap.recycle();
    bitmap256.recycle();
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
    texEnabled = true;
}

7. TextViewUtils#convertViewToDrawable()

Project: AcFun-Area63
Source File: TextViewUtils.java
View license
public static Drawable convertViewToDrawable(View view) {
    int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    view.measure(spec, spec);
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
    Bitmap b = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);
    c.translate(-view.getScrollX(), -view.getScrollY());
    view.draw(c);
    view.setDrawingCacheEnabled(true);
    Bitmap cacheBmp = view.getDrawingCache();
    Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
    view.destroyDrawingCache();
    return new BitmapDrawable(view.getResources(), viewBmp);
}

8. RoundedImageView#onDraw()

View license
@Override
protected void onDraw(Canvas canvas) {
    Drawable drawable = getDrawable();
    if (drawable == null) {
        return;
    }
    if (getWidth() == 0 || getHeight() == 0) {
        return;
    }
    Bitmap b = ((BitmapDrawable) drawable).getBitmap();
    Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true);
    int w = getWidth(), h = getHeight();
    Bitmap roundBitmap = getRoundedCroppedBitmap(bitmap, w);
    canvas.drawBitmap(roundBitmap, 0, 0, null);
}

9. BitmapActivity#onCreate()

View license
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bitmap);
    mImageView1 = (ImageView) findViewById(R.id.imageView1);
    mImageView2 = (ImageView) findViewById(R.id.imageView2);
    mImageView3 = (ImageView) findViewById(R.id.imageView3);
    mImageView4 = (ImageView) findViewById(R.id.imageView4);
    Bitmap avatar1 = BitmapFactory.decodeResource(getResources(), R.drawable.headshow1);
    Bitmap avatar2 = BitmapFactory.decodeResource(getResources(), R.drawable.headshow2);
    Bitmap avatar3 = BitmapFactory.decodeResource(getResources(), R.drawable.headshow3);
    mBmps.add(avatar1);
    mBmps.add(avatar2);
    mBmps.add(avatar3);
}

10. BitmapsGenerator#getSatValBitmapFrom()

View license
/**Gets a Rectangular Bitmap representing the Gradient of Sat and Val copied from the given BitmapDrawable for the given Hue
     * @param bitmapDrawable A BitmapDrawable to use as a base for the gradient of Sat and Val
     * @param hue Value of Hue to use for the bitmap generation of SatVal Gradient bitmap
     * @param width Width of the SatValPicker
     * @param height Height of the SatValPicker
     * @param skipCount Number of pixels to skip when generating Bitmap (increasing this results in faster bitmap generation but reduces bitmap quality)
     * @return A Rectangular Bitmap representing the Gradient of Sat and Val copied from the given BitmapDrawable for the given Hue
     */
@Deprecated
public static Bitmap getSatValBitmapFrom(BitmapDrawable bitmapDrawable, float hue, int width, int height, int skipCount) {
    int[] pixels = new int[width * height];
    Bitmap bitmap = bitmapDrawable.getBitmap();
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    for (int i = 0; i < pixels.length; i++) {
        float[] hsv = new float[3];
        Color.colorToHSV(pixels[i], hsv);
        hsv[0] = hue;
        pixels[i] = Color.HSVToColor(hsv);
    }
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}

11. MultiSelectEditText#convertViewToDrawable()

View license
protected BitmapDrawable convertViewToDrawable(View textView) {
    int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    textView.measure(spec, spec);
    textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
    Bitmap b = Bitmap.createBitmap(textView.getMeasuredWidth(), textView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);
    c.translate(-textView.getScrollX(), -textView.getScrollY());
    textView.draw(c);
    textView.setDrawingCacheEnabled(true);
    Bitmap cacheBmp = textView.getDrawingCache();
    Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
    textView.destroyDrawingCache();
    BitmapDrawable bd = new BitmapDrawable(getContext().getResources(), viewBmp);
    bd.setBounds(0, 0, viewBmp.getWidth(), viewBmp.getHeight());
    return bd;
}

12. ACVComic#getScreenWithContents()

Project: droid-comic-viewer
Source File: ACVComic.java
View license
public Drawable getScreenWithContents(WebView w, int screenIndex) {
    final List<ACVContent> contents = this.getContents(screenIndex);
    final Drawable drawable = this.getScreen(screenIndex);
    if (contents.size() == 0) {
        return drawable;
    }
    // TODO: Cache modified bitmap
    final Bitmap original = ((BitmapDrawable) drawable).getBitmap();
    final Bitmap result = original.copy(Config.RGB_565, true);
    original.recycle();
    final int width = result.getWidth();
    final int height = result.getHeight();
    final Canvas canvas = new Canvas(result);
    for (ACVContent content : contents) {
        final Rect contentRect = content.createRect(width, height);
        final Bitmap contentBitmap = getBitmap(content, w, width, height);
        canvas.drawBitmap(contentBitmap, contentRect.left, contentRect.top, null);
        contentBitmap.recycle();
    }
    return new BitmapDrawable(result);
}

13. CircledImageView#onDraw()

View license
@Override
protected void onDraw(Canvas canvas) {
    Drawable drawable = getDrawable();
    if (drawable == null) {
        return;
    }
    if (getWidth() == 0 || getHeight() == 0) {
        return;
    }
    Bitmap b = ((BitmapDrawable) drawable).getBitmap();
    Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true);
    int w = getWidth(), h = getHeight();
    Bitmap roundBitmap = getCroppedBitmap(bitmap, w);
    canvas.drawBitmap(roundBitmap, 0, 0, null);
}

14. RepeatedPostprocessorProducerTest#runPostprocessAgainWhenDirty()

View license
@Test
public void runPostprocessAgainWhenDirty() {
    final RepeatedPostprocessorConsumer postprocessorConsumer = produceResults();
    final RepeatedPostprocessorRunner repeatedPostprocessorRunner = getRunner();
    performNewResult(postprocessorConsumer, false);
    Bitmap destBitmap0 = mDestinationBitmap;
    performUpdateDuringTheNextPostprocessing(repeatedPostprocessorRunner);
    mTestExecutorService.runNextPendingCommand();
    verifyNewResultProcessed(0, destBitmap0);
    Bitmap destBitmap1 = mDestinationBitmap;
    performUpdateDuringTheNextPostprocessing(repeatedPostprocessorRunner);
    mTestExecutorService.runNextPendingCommand();
    verifyNewResultProcessed(1, destBitmap1);
    Bitmap destBitmap2 = mDestinationBitmap;
    mTestExecutorService.runNextPendingCommand();
    verifyNewResultProcessed(2, destBitmap2);
}

15. BitmapUtilTest#testGetSizeInBytes()

Project: fresco
Source File: BitmapUtilTest.java
View license
@Test
public void testGetSizeInBytes() {
    // 0 for null
    assertEquals(0, BitmapUtil.getSizeInBytes(null));
    // 240 * 181 * 4 = 173760
    final Bitmap bitmap1 = BitmapFactory.decodeStream(BitmapUtilTest.class.getResourceAsStream("pngs/1.png"));
    assertEquals(173760, BitmapUtil.getSizeInBytes(bitmap1));
    // 240 * 246 * 4 = 236160
    final Bitmap bitmap2 = BitmapFactory.decodeStream(BitmapUtilTest.class.getResourceAsStream("pngs/2.png"));
    assertEquals(236160, BitmapUtil.getSizeInBytes(bitmap2));
    // 240 * 180 * 4 = 172800
    final Bitmap bitmap3 = BitmapFactory.decodeStream(BitmapUtilTest.class.getResourceAsStream("pngs/3.png"));
    assertEquals(172800, BitmapUtil.getSizeInBytes(bitmap3));
}

16. StackBlur#blurNativelyPixels()

Project: Genius-Android
Source File: StackBlur.java
View license
/**
     * StackBlur By Jni Pixels
     *
     * @param original         Original Image
     * @param radius           Blur radius
     * @param canReuseInBitmap Can reuse In original Bitmap
     * @return Image Bitmap
     */
public static Bitmap blurNativelyPixels(Bitmap original, int radius, boolean canReuseInBitmap) {
    if (radius < 1) {
        return null;
    }
    Bitmap bitmap = buildBitmap(original, canReuseInBitmap);
    // Return this none blur
    if (radius == 1) {
        return bitmap;
    }
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    int[] pix = new int[w * h];
    bitmap.getPixels(pix, 0, w, 0, 0, w, h);
    // Jni Pixels Blur
    blurPixels(pix, w, h, radius);
    bitmap.setPixels(pix, 0, w, 0, 0, w, h);
    return (bitmap);
}

17. StackBlur#blurNativelyPixels()

Project: ImageBlurring
Source File: StackBlur.java
View license
/**
     * StackBlur By Jni Pixels
     *
     * @param original         Original Image
     * @param radius           Blur radius
     * @param canReuseInBitmap Can reuse In original Bitmap
     * @return Image Bitmap
     */
public static Bitmap blurNativelyPixels(Bitmap original, int radius, boolean canReuseInBitmap) {
    if (radius < 1) {
        return null;
    }
    Bitmap bitmap = buildBitmap(original, canReuseInBitmap);
    // Return this none blur
    if (radius == 1) {
        return bitmap;
    }
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    int[] pix = new int[w * h];
    bitmap.getPixels(pix, 0, w, 0, 0, w, h);
    // Jni Pixels Blur
    blurPixels(pix, w, h, radius);
    bitmap.setPixels(pix, 0, w, 0, 0, w, h);
    return (bitmap);
}

18. JmeAndroidSystem#writeImageFile()

Project: jmonkeyengine
Source File: JmeAndroidSystem.java
View license
@Override
public void writeImageFile(OutputStream outStream, String format, ByteBuffer imageData, int width, int height) throws IOException {
    Bitmap bitmapImage = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    AndroidScreenshots.convertScreenShot(imageData, bitmapImage);
    Bitmap.CompressFormat compressFormat;
    if (format.equals("png")) {
        compressFormat = Bitmap.CompressFormat.PNG;
    } else if (format.equals("jpg")) {
        compressFormat = Bitmap.CompressFormat.JPEG;
    } else {
        throw new UnsupportedOperationException("Only 'png' and 'jpg' formats are supported on Android");
    }
    bitmapImage.compress(compressFormat, 95, outStream);
    bitmapImage.recycle();
}

19. Blur#blur()

Project: LiveBlurListView
Source File: Blur.java
View license
public Bitmap blur(Bitmap image, boolean fast) {
    float scale = BITMAP_SCALE_NOMAL;
    float radius = BLUR_RADIUS_NOMAL;
    if (fast) {
        scale = BITMAP_SCALE_FAST;
        radius = BLUR_RADIUS_FAST;
    }
    int width = Math.round(image.getWidth() * scale);
    int height = Math.round(image.getHeight() * scale);
    Bitmap bitmap = Bitmap.createScaledBitmap(image, width, height, true);
    Bitmap outputBitmap = getBitmapFromMemCache("" + width + height);
    if (outputBitmap == null) {
        outputBitmap = bitmap.copy(bitmap.getConfig(), true);
        addBitmapToMemoryCache("" + width + height, outputBitmap);
    }
    mRender.blur(radius, bitmap, outputBitmap);
    bitmap.recycle();
    return outputBitmap;
}

20. LoadingImageView#initMaskBitmap()

View license
private void initMaskBitmap(int maskColor) {
    Drawable drawable = getDrawable();
    if (drawable == null) {
        return;
    }
    Bitmap bgd = ((BitmapDrawable) drawable).getBitmap();
    imageWidth = drawable.getIntrinsicWidth();
    imageHeight = drawable.getIntrinsicHeight();
    Bitmap fg = Bitmap.createBitmap(imageWidth, imageHeight, Bitmap.Config.ARGB_8888);
    Canvas fgCanvas = new Canvas(fg);
    fgCanvas.drawColor(maskColor);
    Bitmap bitmap = combineImages(bgd, fg);
    maskDrawable = new BitmapDrawable(bitmap);
    clipDrawable = new ClipDrawable(maskDrawable, gravity, orientaion);
//shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
//paint.setShader(shader);
}

21. HeartView#createHeart()

Project: MousePaint
Source File: HeartView.java
View license
public Bitmap createHeart(int color) {
    if (sHeart == null) {
        sHeart = BitmapFactory.decodeResource(getResources(), mHeartResId);
    }
    if (sHeartBorder == null) {
        sHeartBorder = BitmapFactory.decodeResource(getResources(), mHeartBorderResId);
    }
    Bitmap heart = sHeart;
    Bitmap heartBorder = sHeartBorder;
    Bitmap bm = createBitmapSafely(heartBorder.getWidth(), heartBorder.getHeight());
    if (bm == null) {
        return null;
    }
    Canvas canvas = sCanvas;
    canvas.setBitmap(bm);
    Paint p = sPaint;
    canvas.drawBitmap(heartBorder, 0, 0, p);
    p.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
    float dx = (heartBorder.getWidth() - heart.getWidth()) / 2f;
    float dy = (heartBorder.getHeight() - heart.getHeight()) / 2f;
    canvas.drawBitmap(heart, dx, dy, p);
    p.setColorFilter(null);
    canvas.setBitmap(null);
    return bm;
}

22. BitmapUtils#drawViewToBitmap()

Project: NBAPlus
Source File: BitmapUtils.java
View license
public static Bitmap drawViewToBitmap(View view, int width, int height, float translateX, float translateY, int downSampling, String color) {
    float scale = 1f / downSampling;
    int bmpWidth = (int) (width * scale - translateX / downSampling);
    int bmpHeight = (int) (height * scale - translateY / downSampling);
    Bitmap dest = Bitmap.createBitmap(bmpWidth, bmpHeight, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(dest);
    canvas.translate(-translateX / downSampling, -translateY / downSampling);
    if (downSampling > 1) {
        canvas.scale(scale, scale);
    }
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
    PorterDuffColorFilter filter = new PorterDuffColorFilter(Color.parseColor(color), PorterDuff.Mode.SRC_ATOP);
    paint.setColorFilter(filter);
    view.buildDrawingCache();
    Bitmap cache = view.getDrawingCache();
    canvas.drawBitmap(cache, 0, 0, paint);
    cache.recycle();
    view.destroyDrawingCache();
    return dest;
}

23. CircleTransformation#transform()

Project: Nox
Source File: CircleTransformation.java
View license
@Override
public Bitmap transform(Bitmap source) {
    int size = Math.min(source.getWidth(), source.getHeight());
    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;
    Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
    if (squaredBitmap != source) {
        source.recycle();
    }
    Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
    paint.setShader(shader);
    paint.setAntiAlias(true);
    float r = size / 2f;
    canvas.drawCircle(r, r, r, paint);
    squaredBitmap.recycle();
    return bitmap;
}

24. RoundedImageView#onDraw()

View license
@Override
protected void onDraw(Canvas canvas) {
    Drawable drawable = getDrawable();
    if (drawable == null) {
        return;
    }
    if (getWidth() == 0 || getHeight() == 0) {
        return;
    }
    Bitmap b = ((BitmapDrawable) drawable).getBitmap();
    Bitmap bitmap = b.copy(Config.ARGB_8888, true);
    int w = getWidth(), h = getHeight();
    Bitmap roundBitmap = getRoundedCroppedBitmap(bitmap, w);
    canvas.drawBitmap(roundBitmap, 0, 0, null);
}

25. ImageProcessor#doHighlightImage()

Project: photofilter
Source File: ImageProcessor.java
View license
public Bitmap doHighlightImage(Bitmap originalImage, int radius, @ColorInt int highlightColor) {
    Bitmap resultingBitmap = Bitmap.createBitmap(originalImage.getWidth() + 96, originalImage.getHeight() + 96, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(resultingBitmap);
    canvas.drawColor(0, PorterDuff.Mode.CLEAR);
    Paint paintBlur = new Paint();
    paintBlur.setMaskFilter(new BlurMaskFilter(radius, BlurMaskFilter.Blur.NORMAL));
    int[] offsetXY = new int[2];
    Bitmap bitmapAlpha = originalImage.extractAlpha(paintBlur, offsetXY);
    Paint paintAlphaColor = new Paint();
    paintAlphaColor.setColor(highlightColor);
    canvas.drawBitmap(bitmapAlpha, offsetXY[0], offsetXY[1], paintAlphaColor);
    bitmapAlpha.recycle();
    canvas.drawBitmap(originalImage, 0, 0, null);
    return resultingBitmap;
}

26. LruCacheTest#overMaxSizeDoesNotClear()

Project: picasso
Source File: LruCacheTest.java
View license
@Test
public void overMaxSizeDoesNotClear() {
    LruCache cache = new LruCache(16);
    Bitmap size4 = Bitmap.createBitmap(2, 2, ALPHA_8);
    Bitmap size16 = Bitmap.createBitmap(4, 4, ALPHA_8);
    Bitmap size25 = Bitmap.createBitmap(5, 5, ALPHA_8);
    cache.set("4", size4);
    expectedPutCount++;
    assertHit(cache, "4", size4);
    cache.set("16", size16);
    expectedPutCount++;
    // size4 was evicted.
    expectedEvictionCount++;
    assertMiss(cache, "4");
    assertHit(cache, "16", size16);
    cache.set("25", size25);
    assertHit(cache, "16", size16);
    assertMiss(cache, "25");
    assertEquals(cache.size(), 16);
}

27. RoundedImageView#onDraw()

Project: repay-android
Source File: RoundedImageView.java
View license
@Override
protected void onDraw(Canvas canvas) {
    if (getDrawable() == null) {
        return;
    }
    if (getWidth() == 0 || getHeight() == 0) {
        return;
    }
    Bitmap b = ((BitmapDrawable) getDrawable()).getBitmap();
    Bitmap bitmap = b.copy(Config.ARGB_8888, true);
    double w = getWidth() * SCALE_FACTOR;
    double left = getWidth() - w;
    double top = getHeight() - (getHeight() * SCALE_FACTOR);
    Bitmap roundBitmap = getCroppedBitmap(bitmap, (int) w);
    canvas.drawCircle(getWidth() / 2, getHeight() / 2, getWidth() / 2, mBackgroundPaint);
    canvas.drawBitmap(roundBitmap, (int) left / 2, (int) top / 2, null);
}

28. ScreenshotTaker#getBitmapOfView()

Project: robotium
Source File: ScreenshotTaker.java
View license
/**
	 * Returns a bitmap of a given View.
	 * 
	 * @param view the view to save a bitmap from
	 * @return a bitmap of the given view
	 * 
	 */
private Bitmap getBitmapOfView(final View view) {
    view.destroyDrawingCache();
    view.buildDrawingCache(false);
    Bitmap orig = view.getDrawingCache();
    Bitmap.Config config = null;
    if (orig == null) {
        return null;
    }
    config = orig.getConfig();
    if (config == null) {
        config = Bitmap.Config.ARGB_8888;
    }
    Bitmap b = orig.copy(config, false);
    orig.recycle();
    view.destroyDrawingCache();
    return b;
}

29. ImageBlurManager#doBlurJniArray()

View license
public static Bitmap doBlurJniArray(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) {
    Bitmap bitmap;
    if (canReuseInBitmap) {
        bitmap = sentBitmap;
    } else {
        bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
    }
    if (radius < 1) {
        return (null);
    }
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    int[] pix = new int[w * h];
    bitmap.getPixels(pix, 0, w, 0, 0, w, h);
    // Jni array calculate
    ImageBlur.blurIntArray(pix, w, h, radius);
    bitmap.setPixels(pix, 0, w, 0, 0, w, h);
    return (bitmap);
}

30. TagsEditText#convertViewToDrawable()

Project: TagsEditText
Source File: TagsEditText.java
View license
private Drawable convertViewToDrawable(View view) {
    int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    view.measure(spec, spec);
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
    Bitmap b = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);
    c.translate(-view.getScrollX(), -view.getScrollY());
    view.draw(c);
    view.setDrawingCacheEnabled(true);
    Bitmap cacheBmp = view.getDrawingCache();
    Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
    view.destroyDrawingCache();
    return new BitmapDrawable(getResources(), viewBmp);
}

31. CircleTransform#transform()

Project: TuentiTV
Source File: CircleTransform.java
View license
@Override
public Bitmap transform(Bitmap source) {
    Bitmap squaredBitmap = Bitmap.createScaledBitmap(source, size, size, false);
    if (squaredBitmap != source) {
        source.recycle();
    }
    Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
    paint.setShader(shader);
    paint.setAntiAlias(true);
    float r = size / 2f;
    canvas.drawCircle(r, r, r, paint);
    squaredBitmap.recycle();
    return bitmap;
}

32. AndroidMessenger#sendAnimation()

View license
public void sendAnimation(Peer peer, String fullFilePath) {
    ImageHelper.BitmapSize size = ImageHelper.getImageSize(fullFilePath);
    if (size == null) {
        return;
    }
    Bitmap bmp = BitmapFactory.decodeFile(fullFilePath);
    if (bmp == null) {
        return;
    }
    Bitmap fastThumb = ImageHelper.scaleFit(bmp, 90, 90);
    byte[] fastThumbData = ImageHelper.save(fastThumb);
    sendAnimation(peer, fullFilePath, size.getWidth(), size.getHeight(), new FastThumb(fastThumb.getWidth(), fastThumb.getHeight(), fastThumbData), fullFilePath);
}

33. Coloring#colorDrawable()

Project: actual-number-picker
Source File: Coloring.java
View license
/**
     * Colors the given drawable to a specified color. Uses mode SRC_ATOP.
     *
     * @param context Which context to use
     * @param drawable Which drawable to color
     * @param color Which color to use
     * @return A colored drawable ready for use
     */
public Drawable colorDrawable(Context context, @Nullable Drawable drawable, int color) {
    if (!(drawable instanceof BitmapDrawable)) {
        Log.w(LOG_TAG, "Original drawable is not a bitmap! Trying with constant state cloning.");
        return colorUnknownDrawable(drawable, color);
    }
    Bitmap original = ((BitmapDrawable) drawable).getBitmap();
    Bitmap copy = Bitmap.createBitmap(original.getWidth(), original.getHeight(), original.getConfig());
    Paint paint = new Paint();
    Canvas c = new Canvas(copy);
    paint.setColorFilter(new PorterDuffColorFilter(color, SRC_ATOP));
    c.drawBitmap(original, 0, 0, paint);
    return new BitmapDrawable(context.getResources(), copy);
}

34. WebViewMapFragment#getSnapshot()

Project: AirMapView
Source File: WebViewMapFragment.java
View license
@Override
public void getSnapshot(OnSnapshotReadyListener listener) {
    boolean isDrawingCacheEnabled = webView.isDrawingCacheEnabled();
    webView.setDrawingCacheEnabled(true);
    // copy to a new bitmap, otherwise the bitmap will be
    // destroyed when the drawing cache is destroyed
    // webView.getDrawingCache can return null if drawing cache is disabled or if the size is 0
    Bitmap bitmap = webView.getDrawingCache();
    Bitmap newBitmap = null;
    if (bitmap != null) {
        newBitmap = bitmap.copy(Bitmap.Config.RGB_565, false);
    }
    webView.destroyDrawingCache();
    webView.setDrawingCacheEnabled(isDrawingCacheEnabled);
    listener.onSnapshotReady(newBitmap);
}

35. CropView#crop()

Project: AlbumSelector
Source File: CropView.java
View license
/**
     * Performs synchronous image cropping based on configuration.
     *
     * @return A {@link Bitmap} cropped based on viewport and user panning and zooming or <code>null</code> if no {@link Bitmap} has been
     * provided.
     */
@Nullable
public Bitmap crop() {
    if (bitmap == null) {
        return null;
    }
    final Bitmap src = bitmap;
    final Bitmap.Config srcConfig = src.getConfig();
    final Bitmap.Config config = srcConfig == null ? Bitmap.Config.ARGB_8888 : srcConfig;
    final int viewportHeight = touchManager.getViewportHeight();
    final int viewportWidth = touchManager.getViewportWidth();
    final Bitmap dst = Bitmap.createBitmap(viewportWidth, viewportHeight, config);
    Canvas canvas = new Canvas(dst);
    final int left = (getRight() - viewportWidth) / 2;
    final int top = (getBottom() - viewportHeight) / 2;
    canvas.translate(-left, -top);
    drawBitmap(canvas);
    return dst;
}

36. BlurTransform#transform()

Project: Amphitheatre
Source File: BlurTransform.java
View license
@Override
public Bitmap transform(Bitmap in) {
    Bitmap out = Bitmap.createBitmap(in.getWidth(), in.getHeight(), in.getConfig());
    out.setDensity(in.getDensity());
    RenderScript rs = RenderScript.create(context);
    Allocation input = Allocation.createFromBitmap(rs, in);
    Allocation output = Allocation.createFromBitmap(rs, out);
    ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, getElement(in, rs));
    script.setInput(input);
    script.setRadius(20);
    script.forEach(output);
    output.copyTo(out);
    in.recycle();
    rs.destroy();
    return out;
}

37. PlanarYUVLuminanceSource#renderCroppedGreyscaleBitmap()

View license
public Bitmap renderCroppedGreyscaleBitmap() {
    int width = getWidth();
    int height = getHeight();
    int[] pixels = new int[width * height];
    byte[] yuv = yuvData;
    int inputOffset = top * dataWidth + left;
    for (int y = 0; y < height; y++) {
        int outputOffset = y * width;
        for (int x = 0; x < width; x++) {
            int grey = yuv[inputOffset + x] & 0xff;
            pixels[outputOffset + x] = 0xFF000000 | (grey * 0x00010101);
        }
        inputOffset += dataWidth;
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}

38. PlanarYUVLuminanceSource#renderCroppedGreyscaleBitmap()

View license
public Bitmap renderCroppedGreyscaleBitmap() {
    int width = getWidth();
    int height = getHeight();
    int[] pixels = new int[width * height];
    byte[] yuv = yuvData;
    int inputOffset = top * dataWidth + left;
    for (int y = 0; y < height; y++) {
        int outputOffset = y * width;
        for (int x = 0; x < width; x++) {
            int grey = yuv[inputOffset + x] & 0xff;
            pixels[outputOffset + x] = 0xFF000000 | (grey * 0x00010101);
        }
        inputOffset += dataWidth;
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}

39. GlideCircleTransform#circleCrop()

View license
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
    if (source == null)
        return null;
    int size = Math.min(source.getWidth(), source.getHeight());
    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;
    Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
    Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
    if (result == null) {
        result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    }
    Canvas canvas = new Canvas(result);
    Paint paint = new Paint();
    paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
    paint.setAntiAlias(true);
    float r = size / 2f;
    canvas.drawCircle(r, r, r, paint);
    return result;
}

40. PlanarYUVLuminanceSource#renderCroppedGreyscaleBitmap()

View license
public Bitmap renderCroppedGreyscaleBitmap() {
    int width = getWidth();
    int height = getHeight();
    int[] pixels = new int[width * height];
    byte[] yuv = yuvData;
    int inputOffset = top * dataWidth + left;
    for (int y = 0; y < height; y++) {
        int outputOffset = y * width;
        for (int x = 0; x < width; x++) {
            int grey = yuv[inputOffset + x] & 0xff;
            pixels[outputOffset + x] = 0xFF000000 | (grey * 0x00010101);
        }
        inputOffset += dataWidth;
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}

41. MusicProviderTest#testUpdateMusicArt()

View license
@Test
public void testUpdateMusicArt() throws Exception {
    Bitmap bIcon = Bitmap.createBitmap(2, 2, Bitmap.Config.ALPHA_8);
    Bitmap bArt = Bitmap.createBitmap(2, 2, Bitmap.Config.ALPHA_8);
    MediaMetadataCompat metadata = provider.getShuffledMusic().iterator().next();
    String musicId = metadata.getDescription().getMediaId();
    assertNotEquals(bArt, metadata.getBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART));
    assertNotEquals(bIcon, metadata.getBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON));
    provider.updateMusicArt(musicId, bArt, bIcon);
    MediaMetadataCompat newMetadata = provider.getMusic(musicId);
    assertEquals(bArt, newMetadata.getBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART));
    assertEquals(bIcon, newMetadata.getBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON));
}

42. ImageUtils#scaleDownBitmapForUri()

Project: android-utils
Source File: ImageUtils.java
View license
/**
	 * Scales the image independently of the screen density of the device. Maintains image aspect
	 * ratio.
	 * 
	 * @param uri
	 *            Uri of the source bitmap
	 **/
public static Uri scaleDownBitmapForUri(Context ctx, Uri uri, int newHeight) throws FileNotFoundException, IOException {
    if (uri == null)
        throw new NullPointerException(ERROR_URI_NULL);
    if (!MediaUtils.isMediaContentUri(uri))
        return null;
    Bitmap original = Media.getBitmap(ctx.getContentResolver(), uri);
    Bitmap bmp = scaleBitmap(ctx, original, newHeight);
    Uri destUri = null;
    String uriStr = Utils.writeImageToMedia(ctx, bmp, "", "");
    if (uriStr != null) {
        destUri = Uri.parse(uriStr);
    }
    return destUri;
}

43. Utils#roundBitmap()

Project: android-utils
Source File: Utils.java
View license
public static Bitmap roundBitmap(Bitmap bmp, int radius) {
    Bitmap sbmp;
    if (bmp.getWidth() != radius || bmp.getHeight() != radius)
        sbmp = Bitmap.createScaledBitmap(bmp, radius, radius, false);
    else
        sbmp = bmp;
    Bitmap output = Bitmap.createBitmap(sbmp.getWidth(), sbmp.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xffa19774;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, sbmp.getWidth(), sbmp.getHeight());
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawCircle(sbmp.getWidth() / 2 + 0.7f, sbmp.getHeight() / 2 + 0.7f, sbmp.getWidth() / 2 + 0.1f, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(sbmp, rect, rect, paint);
    return output;
}

44. PlanarYUVLuminanceSource#renderCroppedGreyscaleBitmap()

View license
public Bitmap renderCroppedGreyscaleBitmap() {
    int width = getWidth();
    int height = getHeight();
    int[] pixels = new int[width * height];
    byte[] yuv = yuvData;
    int inputOffset = top * dataWidth + left;
    for (int y = 0; y < height; y++) {
        int outputOffset = y * width;
        for (int x = 0; x < width; x++) {
            int grey = yuv[inputOffset + x] & 0xff;
            pixels[outputOffset + x] = 0xFF000000 | (grey * 0x00010101);
        }
        inputOffset += dataWidth;
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}

45. EncodingHandler#createQRCode()

View license
public static Bitmap createQRCode(String str, int widthAndHeight) throws WriterException {
    Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
    hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
    BitMatrix matrix = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight);
    int width = matrix.getWidth();
    int height = matrix.getHeight();
    int[] pixels = new int[width * height];
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            if (matrix.get(x, y)) {
                pixels[y * width + x] = BLACK;
            }
        }
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}

46. PlanarYUVLuminanceSource#renderCroppedGreyscaleBitmap()

View license
public Bitmap renderCroppedGreyscaleBitmap() {
    int width = getWidth();
    int height = getHeight();
    int[] pixels = new int[width * height];
    byte[] yuv = yuvData;
    int inputOffset = top * dataWidth + left;
    for (int y = 0; y < height; y++) {
        int outputOffset = y * width;
        for (int x = 0; x < width; x++) {
            int grey = yuv[inputOffset + x] & 0xff;
            pixels[outputOffset + x] = 0xFF000000 | (grey * 0x00010101);
        }
        inputOffset += dataWidth;
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}

47. EncodingHandler#createQRCode()

View license
public static Bitmap createQRCode(String str, int widthAndHeight) throws WriterException {
    Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
    hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
    BitMatrix matrix = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight);
    int width = matrix.getWidth();
    int height = matrix.getHeight();
    int[] pixels = new int[width * height];
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            if (matrix.get(x, y)) {
                pixels[y * width + x] = BLACK;
            }
        }
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}

48. ImageUtil#decodeScaleImage()

Project: AndroidLife
Source File: ImageUtil.java
View license
/**
     * ????
     */
public static Bitmap decodeScaleImage(String path, int targetWidth, int targetHeight) {
    BitmapFactory.Options bitmapOptions = getBitmapOptions(path);
    bitmapOptions.inSampleSize = calculateInSampleSize(bitmapOptions, targetWidth, targetHeight);
    bitmapOptions.inJustDecodeBounds = false;
    Bitmap noRotatingBitmap = BitmapFactory.decodeFile(path, bitmapOptions);
    int degree = readPictureDegree(path);
    Bitmap rotatingBitmap;
    if (noRotatingBitmap != null && degree != 0) {
        rotatingBitmap = rotatingImageView(degree, noRotatingBitmap);
        noRotatingBitmap.recycle();
        return rotatingBitmap;
    } else {
        return noRotatingBitmap;
    }
}

49. ImageProcessor#applyCurves()

View license
public static Bitmap applyCurves(int[] rgb, int[] red, int[] green, int[] blue, Bitmap inputImage) {
    // create output bitmap
    Bitmap outputImage = inputImage;
    // get image size
    int width = inputImage.getWidth();
    int height = inputImage.getHeight();
    int[] pixels = new int[width * height];
    outputImage.getPixels(pixels, 0, width, 0, 0, width, height);
    if (rgb != null) {
        pixels = NativeImageProcessor.applyRGBCurve(pixels, rgb, width, height);
    }
    if (!(red == null && green == null && blue == null)) {
        pixels = NativeImageProcessor.applyChannelCurves(pixels, red, green, blue, width, height);
    }
    try {
        outputImage.setPixels(pixels, 0, width, 0, 0, width, height);
    } catch (IllegalStateException ise) {
    }
    return outputImage;
}

50. DisplayUtil#snapShotWithStatusBar()

Project: AndroidStudyDemo
Source File: DisplayUtil.java
View license
/**
     * ??????????????
     *
     * @param activity
     * @return
     */
public static Bitmap snapShotWithStatusBar(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap bmp = view.getDrawingCache();
    int width = getScreenW(activity);
    int height = getScreenH(activity);
    Bitmap bp = null;
    bp = Bitmap.createBitmap(bmp, 0, 0, width, height);
    view.destroyDrawingCache();
    return bp;
}

51. DisplayUtil#snapShotWithoutStatusBar()

Project: AndroidStudyDemo
Source File: DisplayUtil.java
View license
/**
     * ???????????????
     *
     * @param activity
     * @return
     */
public static Bitmap snapShotWithoutStatusBar(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap bmp = view.getDrawingCache();
    Rect frame = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    int statusBarHeight = frame.top;
    int width = getScreenW(activity);
    int height = getScreenH(activity);
    Bitmap bp = null;
    bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height - statusBarHeight);
    view.destroyDrawingCache();
    return bp;
}

52. BitmapUtil#convertGreyImg()

Project: AndroidStudyDemo
Source File: BitmapUtil.java
View license
/**
     * ??????????
     *
     * @param img ?Bitmap
     * @return ????????
     */
public static Bitmap convertGreyImg(Bitmap img) {
    // ??????
    int width = img.getWidth();
    // ??????
    int height = img.getHeight();
    // ??????????????
    int[] pixels = new int[width * height];
    img.getPixels(pixels, 0, width, 0, 0, width, height);
    int alpha = 0xFF << 24;
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            int grey = pixels[width * i + j];
            int red = ((grey & 0x00FF0000) >> 16);
            int green = ((grey & 0x0000FF00) >> 8);
            int blue = (grey & 0x000000FF);
            grey = (int) ((float) red * 0.3 + (float) green * 0.59 + (float) blue * 0.11);
            grey = alpha | (grey << 16) | (grey << 8) | grey;
            pixels[width * i + j] = grey;
        }
    }
    Bitmap result = Bitmap.createBitmap(width, height, Config.RGB_565);
    result.setPixels(pixels, 0, width, 0, 0, width, height);
    return result;
}

53. BitmapUtil#convertToBlackWhite()

Project: AndroidStudyDemo
Source File: BitmapUtil.java
View license
/**
     * ??????????
     *
     * @param bmp ??
     * @return ????????
     */
public static Bitmap convertToBlackWhite(Bitmap bmp) {
    int width = bmp.getWidth();
    int height = bmp.getHeight();
    int[] pixels = new int[width * height];
    bmp.getPixels(pixels, 0, width, 0, 0, width, height);
    // ???bitmap??24???
    int alpha = 0xFF << 24;
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            int grey = pixels[width * i + j];
            int red = ((grey & 0x00FF0000) >> 16);
            int green = ((grey & 0x0000FF00) >> 8);
            int blue = (grey & 0x000000FF);
            grey = (int) (red * 0.3 + green * 0.59 + blue * 0.11);
            grey = alpha | (grey << 16) | (grey << 8) | grey;
            pixels[width * i + j] = grey;
        }
    }
    Bitmap newBmp = Bitmap.createBitmap(width, height, Config.RGB_565);
    newBmp.setPixels(pixels, 0, width, 0, 0, width, height);
    return newBmp;
}

54. MainActivity#showAnimDialog()

Project: AnimProgressBar
Source File: MainActivity.java
View license
private void showAnimDialog() {
    final AlertDialog dialog = new AlertDialog.Builder(this).setCancelable(true).create();
    dialog.show();
    mStop = false;
    mProgress = 0;
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable());
    dialog.getWindow().setContentView(R.layout.anim_pb_dialog);
    mProgressBar = (AnimProgressBar) dialog.getWindow().findViewById(R.id.progressbar);
    mProgressBar.setMax(100);
    Bitmap bitmap1 = ((BitmapDrawable) getResources().getDrawable(com.mao.anim_pb.R.drawable.pb_anim_pic1)).getBitmap();
    Bitmap bitmap2 = ((BitmapDrawable) getResources().getDrawable(com.mao.anim_pb.R.drawable.pb_anim_pic2)).getBitmap();
    mProgressBar.setBitmapBuffer1(bitmap1);
    mProgressBar.setBitmapBuffer2(bitmap2);
    mTextView = (TextView) dialog.getWindow().findViewById(R.id.tv_progress);
    dialog.getWindow().findViewById(R.id.tv_download_cancle).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dialog.dismiss();
            mStop = true;
        }
    });
}

55. FastBlurTransformation#transform()

View license
@Override
protected Bitmap transform(BitmapPool pool, Bitmap source, int outWidth, int outHeight) {
    int targetWidth = BLUR_IMAGE_WIDTH;
    int targetHeight = (int) (1.0 * outHeight * targetWidth / outWidth);
    Bitmap resized = ThumbnailUtils.extractThumbnail(source, targetWidth, targetHeight);
    Bitmap result = fastBlur(resized, STACK_BLUR_RADIUS);
    if (result == null) {
        Log.w(TAG, "result was null");
        return source;
    }
    return result;
}

56. FilterListFragment#superImposeListIcon()

Project: astrid
Source File: FilterListFragment.java
View license
public static Bitmap superImposeListIcon(Activity activity, Bitmap listingIcon, String uuid) {
    Bitmap emblem = listingIcon;
    if (emblem == null)
        emblem = ((BitmapDrawable) activity.getResources().getDrawable(TagService.getDefaultImageIDForTag(uuid))).getBitmap();
    // create icon by superimposing astrid w/ icon
    DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    Bitmap bitmap = ((BitmapDrawable) activity.getResources().getDrawable(R.drawable.icon_blank)).getBitmap();
    bitmap = bitmap.copy(bitmap.getConfig(), true);
    Canvas canvas = new Canvas(bitmap);
    int dimension = 22;
    canvas.drawBitmap(emblem, new Rect(0, 0, emblem.getWidth(), emblem.getHeight()), new Rect(bitmap.getWidth() - dimension, bitmap.getHeight() - dimension, bitmap.getWidth(), bitmap.getHeight()), null);
    return bitmap;
}

57. AsyncImageView#getImageBitmap()

Project: astrid
Source File: AsyncImageView.java
View license
public Bitmap getImageBitmap() {
    setDrawingCacheEnabled(true);
    // this is the important code :)
    // Without it the view will have a dimension of 0,0 and the bitmap will be null
    measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    layout(0, 0, getMeasuredWidth(), getMeasuredHeight());
    buildDrawingCache(true);
    Bitmap drawingCache = getDrawingCache();
    if (drawingCache == null)
        return null;
    Bitmap b = Bitmap.createBitmap(getDrawingCache());
    // clear drawing cache
    setDrawingCacheEnabled(false);
    return b;
}

58. DecodeHandler#bundleThumbnail()

Project: BarcodeScanner
Source File: DecodeHandler.java
View license
private static void bundleThumbnail(PlanarYUVLuminanceSource source, Bundle bundle) {
    int[] pixels = source.renderThumbnail();
    int width = source.getThumbnailWidth();
    int height = source.getThumbnailHeight();
    Bitmap bitmap = Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.ARGB_8888);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out);
    bundle.putByteArray(DecodeThread.BARCODE_BITMAP, out.toByteArray());
    bundle.putFloat(DecodeThread.BARCODE_SCALED_FACTOR, (float) width / source.getWidth());
}

59. PlanarYUVLuminanceSource#renderCroppedGreyscaleBitmap()

View license
public Bitmap renderCroppedGreyscaleBitmap() {
    int width = getWidth();
    int height = getHeight();
    int[] pixels = new int[width * height];
    byte[] yuv = yuvData;
    int inputOffset = top * dataWidth + left;
    for (int y = 0; y < height; y++) {
        int outputOffset = y * width;
        for (int x = 0; x < width; x++) {
            int grey = yuv[inputOffset + x] & 0xff;
            pixels[outputOffset + x] = 0xFF000000 | (grey * 0x00010101);
        }
        inputOffset += dataWidth;
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}

60. TestImplConvertBitmap#checkBitmapToGrayRGB()

Project: BoofCV
Source File: TestImplConvertBitmap.java
View license
public void checkBitmapToGrayRGB(Method m, Bitmap.Config config) {
    Bitmap orig = Bitmap.createBitmap(w, h, config);
    orig.setPixel(1, 2, 0xFF204010);
    Class[] params = m.getParameterTypes();
    String info = config + " " + params[1].getSimpleName();
    try {
        ImageGray found = (ImageGray) params[1].getConstructor(int.class, int.class).newInstance(w, h);
        m.invoke(null, orig, found);
        GImageGray g = FactoryGImageGray.wrap(found);
        // should be 37 for both 8888 and 565
        assertEquals(info, 37, g.get(1, 2).intValue());
        assertEquals(info, 0, g.get(0, 0).intValue());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

61. TestImplConvertBitmap#checkBitmapToMultiRGB()

Project: BoofCV
Source File: TestImplConvertBitmap.java
View license
public void checkBitmapToMultiRGB(Method m, Bitmap.Config config) {
    Bitmap orig = Bitmap.createBitmap(w, h, config);
    orig.setPixel(1, 2, 0xFF204010);
    Class[] params = m.getParameterTypes();
    String info = config + " " + m.getName();
    try {
        int numBands = Bitmap.Config.ARGB_8888 == config ? 4 : 3;
        Class msType = m.getName().contains("U8") ? GrayU8.class : GrayF32.class;
        Planar found = new Planar(msType, w, h, numBands);
        m.invoke(null, orig, found);
        assertEquals(0x20, (int) GeneralizedImageOps.get(found.getBand(0), 1, 2));
        assertEquals(0x40, (int) GeneralizedImageOps.get(found.getBand(1), 1, 2));
        assertEquals(0x10, (int) GeneralizedImageOps.get(found.getBand(2), 1, 2));
        if (numBands == 4)
            assertEquals(0xFF, (int) GeneralizedImageOps.get(found.getBand(3), 1, 2));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

62. ListPaymentMethodNonceTest#displaysACard()

View license
@Test(timeout = 30000)
public void displaysACard() {
    Activity activity = getActivity(getSinglePaymentMethodNonceIntent(new TestClientTokenBuilder().build()));
    waitForPaymentMethodNonceList();
    assertSelectedPaymentMethodIs(com.braintreepayments.api.dropin.R.string.bt_descriptor_visa);
    onView(withId(com.braintreepayments.api.dropin.R.id.bt_payment_method_description)).check(matches(withText("ends in 11")));
    ImageView iv = ((ImageView) activity.findViewById(com.braintreepayments.api.dropin.R.id.bt_payment_method_icon));
    Bitmap actual = ((BitmapDrawable) iv.getDrawable()).getBitmap();
    Bitmap expected = ((BitmapDrawable) activity.getResources().getDrawable(com.braintreepayments.api.dropin.R.drawable.bt_visa)).getBitmap();
    assertTrue(expected.sameAs(actual));
}

63. ListPaymentMethodNonceTest#displaysCorrectActivePaymentMethod()

View license
@Test(timeout = 30000)
public void displaysCorrectActivePaymentMethod() {
    Activity activity = getActivity(getSinglePaymentMethodNonceIntent(new TestClientTokenBuilder().build()));
    waitForPaymentMethodNonceList();
    assertSelectedPaymentMethodIs(com.braintreepayments.api.dropin.R.string.bt_descriptor_visa);
    onView(withId(com.braintreepayments.api.dropin.R.id.bt_payment_method_description)).check(matches(withText("ends in 11")));
    ImageView iv = ((ImageView) activity.findViewById(com.braintreepayments.api.dropin.R.id.bt_payment_method_icon));
    Bitmap actual = ((BitmapDrawable) iv.getDrawable()).getBitmap();
    Bitmap expected = ((BitmapDrawable) activity.getResources().getDrawable(com.braintreepayments.api.dropin.R.drawable.bt_visa)).getBitmap();
    assertTrue(expected.sameAs(actual));
}

64. ChatFileStore#resizeAndImportImage()

View license
/**
     * Resize an image to an efficient size for sending via OTRDATA, then copy
     * that resized version into vfs. All imported content is stored under
     * /SESSION_NAME/ The original full path is retained to facilitate browsing
     * The session content can be deleted when the session is over
     *
     * @param imagePath
     * @return vfs uri
     * @throws IOException
     */
public static Uri resizeAndImportImage(Context context, String sessionId, Uri uri, String mimeType) throws IOException {
    String imagePath = uri.getPath();
    String targetPath = "/" + sessionId + "/upload/" + imagePath;
    targetPath = createUniqueFilename(targetPath);
    int defaultImageWidth = 600;
    //load lower-res bitmap
    Bitmap bmp = getThumbnailFile(context, uri, defaultImageWidth);
    File file = new File(targetPath);
    FileOutputStream out = new FileOutputStream(file);
    if (//preserve alpha channel
    imagePath.endsWith(".png") || mimeType.contains("png"))
        bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
    else
        bmp.compress(Bitmap.CompressFormat.JPEG, 90, out);
    out.flush();
    out.close();
    bmp.recycle();
    return vfsUri(targetPath);
}

65. MainActivity#onCreate()

View license
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ImageView button = (ImageView) findViewById(R.id.image);
    InputStream resource = getResources().openRawResource(R.drawable.eye);
    Bitmap bitmap = BitmapFactory.decodeStream(resource);
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;
    Bitmap b = Bitmap.createScaledBitmap(bitmap, width, height, false);
    button.setBackground(new MyRoundCornerDrawable(b));
}

66. ImageRequestTransformer#transform()

View license
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
public byte[] transform(ParamsBundle requestArgs, byte[] data) throws ParseError {
    int width = requestArgs.getInt("width", 500);
    int height = requestArgs.getInt("height", 500);
    Bitmap.Config config = (Bitmap.Config) requestArgs.getSerializable("config");
    ImageView.ScaleType scaleType = (ImageView.ScaleType) requestArgs.getSerializable("scale_type");
    if (config == null) {
        config = Bitmap.Config.RGB_565;
    }
    if (scaleType == null) {
        scaleType = ImageView.ScaleType.CENTER_INSIDE;
    }
    Bitmap bitmap = ImageDecoder.parseImage(data, config, scaleType, width, height);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.WEBP, 100, stream);
    return stream.toByteArray();
}

67. GlideCircleTransform#transform()

Project: EasyGank
Source File: GlideCircleTransform.java
View license
@Override
protected Bitmap transform(BitmapPool pool, Bitmap inBitmap, int destWidth, int destHeight) {
    if (inBitmap == null)
        return null;
    int size = Math.min(inBitmap.getWidth(), inBitmap.getHeight());
    int x = (inBitmap.getWidth() - size) / 2;
    int y = (inBitmap.getHeight() - size) / 2;
    Bitmap squared = Bitmap.createBitmap(inBitmap, x, y, size, size);
    Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
    if (result == null) {
        result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    }
    Canvas canvas = new Canvas(result);
    Paint paint = new Paint();
    paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
    paint.setAntiAlias(true);
    float r = size / 2f;
    canvas.drawCircle(r, r, r, paint);
    return result;
}

68. CardBgTest#doGenCardBg()

Project: EhViewer
Source File: CardBgTest.java
View license
private void doGenCardBg(OutputStream os, int color, float radius, float base, float topAlpha, float topOffset, float topBlur, float bottomAlpha, float bottomOffset, float bottomBlur) throws FileNotFoundException {
    Path path = getPath(radius, base);
    path.offset(MAX_SIZE / 2, MAX_SIZE / 2);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    paint.setColor(color);
    Bitmap bitmap = Bitmap.createBitmap(MAX_SIZE, MAX_SIZE, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    // Draw bottom
    paint.setShadowLayer(bottomBlur, 0, bottomOffset, getColor(bottomAlpha));
    canvas.drawPath(path, paint);
    // Draw top
    paint.setShadowLayer(topBlur, 0, topOffset, getColor(topAlpha));
    canvas.drawPath(path, paint);
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, os);
}

69. ShadowDecorator#processBitmap()

Project: enroscar
Source File: ShadowDecorator.java
View license
@Override
protected Bitmap processBitmap(final Bitmap source, final Canvas sourceCanvas) {
    final Bitmap buffer = this.bitmap;
    final Canvas bufferCanvas = this.bitmapCanvas;
    final Paint shadowPaint = this.shadowPaint;
    buffer.eraseColor(0);
    final float size = this.size;
    shadowPaint.setShadowLayer(blur, size, size, Color.BLACK);
    bufferCanvas.drawRect(dst, shadowPaint);
    bufferCanvas.drawBitmap(source, src, dst, null);
    source.eraseColor(0);
    sourceCanvas.drawBitmap(buffer, 0, 0, null);
    return source;
}

70. SocialUtils#compressBitmap()

Project: ESSocialSDK
Source File: SocialUtils.java
View license
/**
     * ????
     *
     * @param data ??
     * @param size ???
     * @return ?????
     */
public static byte[] compressBitmap(byte[] data, float size) {
    Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
    if (bitmap == null || getSizeOfBitmap(bitmap) <= size) {
        return data;
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    int quality = 100;
    while ((baos.toByteArray().length / 1024f) > size) {
        quality -= 5;
        baos.reset();
        if (quality <= 0) {
            break;
        }
        bitmap.compress(Bitmap.CompressFormat.JPEG, quality, baos);
    }
    byte[] byteData = baos.toByteArray();
    return byteData;
}

71. DecodeHandler#bundleThumbnail()

Project: ExhibitionCenter
Source File: DecodeHandler.java
View license
private static void bundleThumbnail(PlanarYUVLuminanceSource source, Bundle bundle) {
    int[] pixels = source.renderThumbnail();
    int width = source.getThumbnailWidth();
    int height = source.getThumbnailHeight();
    Bitmap bitmap = Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.ARGB_8888);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out);
    bundle.putByteArray(DecodeThread.BARCODE_BITMAP, out.toByteArray());
    bundle.putFloat(DecodeThread.BARCODE_SCALED_FACTOR, (float) width / source.getWidth());
}

72. MainActivity#initWidget()

Project: FaceRecognition
Source File: MainActivity.java
View license
@Override
public void initWidget() {
    super.initWidget();
    Bitmap bitmap = BitmapCreate.bitmapFromResource(getResources(), R.drawable.image, 0, 0);
    imgOriginal.setImageBitmap(bitmap);
    FaceCropper faceCropper = new FaceCropper();
    faceCropper.setDebug(false);
    Bitmap cropBitmap = faceCropper.cropFace(bitmap);
    imgNew.setImageBitmap(cropBitmap);
}

73. ImageHelper#rotateImageFile()

View license
public static Bitmap rotateImageFile(final String filePath) {
    final int orientation = ImageHelper.getExifOrientation(filePath);
    final Bitmap source = BitmapFactory.decodeFile(filePath);
    final int sw = source.getWidth();
    final int sh = source.getHeight();
    final Matrix matrix = new Matrix();
    matrix.setRotate(orientation);
    final Bitmap bitmap = Bitmap.createBitmap(source, 0, 0, sw, sh, matrix, true);
    ImageHelper.releaseBitmap(source);
    return bitmap;
}

74. WebpBitmapFactoryTest#testWebpDecodeStream()

Project: fresco
Source File: WebpBitmapFactoryTest.java
View license
@Test
public void testWebpDecodeStream() throws Throwable {
    final Bitmap bitmap = WebpBitmapFactoryImpl.hookDecodeStream(getTestWebpInputStream(), null, null);
    assertNotNull("Bitmap should not be null", bitmap);
    assertEquals("Width should be decoded properly", 20, bitmap.getWidth());
    assertEquals("Height should be decoded properly", 20, bitmap.getHeight());
    assertEquals("Bitmap pixels should be red", 0xFFFF0100, bitmap.getPixel(5, 8));
    // Alternatively, load image manually adb pull /mnt/sdcard/resulthooked.jpg
    bitmap.compress(Bitmap.CompressFormat.JPEG, 90, new FileOutputStream(Environment.getExternalStorageDirectory() + "/resulthooked.jpg"));
}

75. WebpBitmapFactoryTest#testInBitmap()

Project: fresco
Source File: WebpBitmapFactoryTest.java
View license
@Test
public void testInBitmap() throws Throwable {
    if (!WebpBitmapFactoryImpl.IN_BITMAP_SUPPORTED) {
        return;
    }
    Bitmap inBitmap = Bitmap.createBitmap(20, 20, Bitmap.Config.ARGB_8888);
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inBitmap = inBitmap;
    final Bitmap outBitmap = WebpBitmapFactoryImpl.hookDecodeStream(getTestWebpInputStream(), null, options);
    assertNotNull("Bitmap should not be null", outBitmap);
    assertSame("Output bitmap shuold be the same as input bitmap", inBitmap, outBitmap);
    assertEquals("Bitmap pixels should be red", 0xFFFF0100, outBitmap.getPixel(5, 8));
}

76. UiHelper#snapShotWithStatusBar()

Project: GanWuMei
Source File: UiHelper.java
View license
/**
     * ??????????????
     */
public static Bitmap snapShotWithStatusBar(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap bmp = view.getDrawingCache();
    int width = getScreenWidth(activity);
    int height = getScreenHeight(activity);
    Bitmap bp = null;
    bp = Bitmap.createBitmap(bmp, 0, 0, width, height);
    view.destroyDrawingCache();
    return bp;
}

77. UiHelper#snapShotWithoutStatusBar()

Project: GanWuMei
Source File: UiHelper.java
View license
/**
     * ???????????????
     */
public static Bitmap snapShotWithoutStatusBar(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap bmp = view.getDrawingCache();
    Rect frame = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    int statusBarHeight = frame.top;
    int width = getScreenWidth(activity);
    int height = getScreenHeight(activity);
    Bitmap bp = null;
    bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height - statusBarHeight);
    view.destroyDrawingCache();
    return bp;
}

78. DebugImage#writeGrayImage()

Project: gast-lib
Source File: DebugImage.java
View license
public static boolean writeGrayImage(byte[] bImageData, int width, int height, String szFilename) {
    Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    int[] nImageData = new int[width * height];
    for (int i = 0; i < width * height; i++) {
        int nValue = 0xff & bImageData[i];
        nImageData[i] = Color.argb(0xff, nValue, nValue, nValue);
    }
    bmp.setPixels(nImageData, 0, width, 0, 0, width, height);
    return writeBitmap(szFilename, bmp);
}

79. DebugImage#writeNv21Image()

Project: gast-lib
Source File: DebugImage.java
View license
public static boolean writeNv21Image(byte[] bImageData, int width, int height, String szFilename) {
    Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    int[] nImageData = new int[width * height];
    int nVuOffset = width * height;
    for (int i = 0; i < height; i++) {
        // we produce two pixels for each VU pair in the color plane
        for (int j = 0; j < width; j += 2) {
            int nY = 0xff & bImageData[i * width + j];
            int nV = 0xff & bImageData[nVuOffset + (i / 2) * width + j];
            int nU = 0xff & bImageData[nVuOffset + (i / 2) * width + j + 1];
            nImageData[i * width + j] = AndroidColors.yuv2Color(nY, nU, nV);
            nY = 0xff & bImageData[i * width + j + 1];
            nImageData[i * width + j + 1] = AndroidColors.yuv2Color(nY, nU, nV);
        }
    }
    bmp.setPixels(nImageData, 0, width, 0, 0, width, height);
    return writeBitmap(szFilename, bmp);
}

80. ColorFilterTransformation#transform()

View license
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
    Bitmap source = resource.get();
    int width = source.getWidth();
    int height = source.getHeight();
    Bitmap.Config config = source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
    Bitmap bitmap = mBitmapPool.get(width, height, config);
    if (bitmap == null) {
        bitmap = Bitmap.createBitmap(width, height, config);
    }
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SRC_ATOP));
    canvas.drawBitmap(source, 0, 0, paint);
    return BitmapResource.obtain(bitmap, mBitmapPool);
}

81. CropSquareTransformation#transform()

View license
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
    Bitmap source = resource.get();
    int size = Math.min(source.getWidth(), source.getHeight());
    mWidth = (source.getWidth() - size) / 2;
    mHeight = (source.getHeight() - size) / 2;
    Bitmap.Config config = source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
    Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
    if (bitmap == null) {
        bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
    }
    return BitmapResource.obtain(bitmap, mBitmapPool);
}

82. GrayscaleTransformation#transform()

View license
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
    Bitmap source = resource.get();
    int width = source.getWidth();
    int height = source.getHeight();
    Bitmap.Config config = source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
    Bitmap bitmap = mBitmapPool.get(width, height, config);
    if (bitmap == null) {
        bitmap = Bitmap.createBitmap(width, height, config);
    }
    Canvas canvas = new Canvas(bitmap);
    ColorMatrix saturation = new ColorMatrix();
    saturation.setSaturation(0f);
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(saturation));
    canvas.drawBitmap(source, 0, 0, paint);
    return BitmapResource.obtain(bitmap, mBitmapPool);
}

83. MaskTransformation#transform()

View license
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
    Bitmap source = resource.get();
    int width = source.getWidth();
    int height = source.getHeight();
    Bitmap result = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
    if (result == null) {
        result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    }
    Drawable mask = Utils.getMaskDrawable(mContext, mMaskId);
    Canvas canvas = new Canvas(result);
    mask.setBounds(0, 0, width, height);
    mask.draw(canvas);
    canvas.drawBitmap(source, 0, 0, sMaskingPaint);
    return BitmapResource.obtain(result, mBitmapPool);
}

84. RoundedCornersTransformation#transform()

View license
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
    Bitmap source = resource.get();
    int width = source.getWidth();
    int height = source.getHeight();
    Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
    if (bitmap == null) {
        bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    }
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
    drawRoundRect(canvas, paint, width, height);
    return BitmapResource.obtain(bitmap, mBitmapPool);
}

85. DrawingView#setCanvasBitmap()

Project: helpstack-android
Source File: DrawingView.java
View license
public void setCanvasBitmap(Bitmap bitmap) {
    cachedBitmap = bitmap;
    mCanvas.drawColor(Color.BLACK);
    Bitmap mutableBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
    calculateResizeRatio(bitmap, mCanvas);
    Bitmap resizedBitmap = Bitmap.createScaledBitmap(mutableBitmap, resizedWidth, resizedHeight, false);
    int leftStart = getLeftStart(resizedWidth);
    int topStart = getTopStart(resizedHeight);
    mCanvas.drawBitmap(resizedBitmap, leftStart, topStart, mPaint);
}

86. BitmapUtils#blackAndWhited()

View license
public static final Bitmap blackAndWhited(Bitmap in) {
    int width = in.getWidth();
    int height = in.getHeight();
    int[] pixels = new int[width * height];
    in.getPixels(pixels, 0, width, 0, 0, width, height);
    int alpha = 0xFF << 24;
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            int grey = pixels[width * i + j];
            int red = ((grey & 0x00FF0000) >> 16);
            int green = ((grey & 0x0000FF00) >> 8);
            int blue = (grey & 0x000000FF);
            grey = (int) (red * 0.3 + green * 0.59 + blue * 0.11);
            grey = alpha | (grey << 16) | (grey << 8) | grey;
            pixels[width * i + j] = grey;
        }
    }
    Bitmap newBmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
    newBmp.setPixels(pixels, 0, width, 0, 0, width, height);
    return newBmp;
}

87. MjpegFileWriter#writeImageToBytes()

Project: jmonkeyengine
Source File: MjpegFileWriter.java
View license
public byte[] writeImageToBytes(Bitmap image, float quality) throws Exception {
    Bitmap bi;
    if (image.getConfig() == Bitmap.Config.RGB_565) {
        bi = image;
    } else {
        bi = image.copy(Bitmap.Config.RGB_565, false);
        if (bi == null) {
            throw new IllegalStateException("Could not convert Bitmap to RGB_565");
        }
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bi.compress(Bitmap.CompressFormat.JPEG, (int) (quality * 100), baos);
    baos.close();
    return baos.toByteArray();
}

88. ContactPictureLoader#calculateFallbackBitmap()

Project: k-9
Source File: ContactPictureLoader.java
View license
/**
     * Calculates a bitmap with a color and a capital letter for contacts without picture.
     */
private Bitmap calculateFallbackBitmap(Address address) {
    Bitmap result = Bitmap.createBitmap(mPictureSizeInPx, mPictureSizeInPx, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    int rgb = calcUnknownContactColor(address);
    result.eraseColor(rgb);
    String letter = calcUnknownContactLetter(address);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL);
    paint.setARGB(255, 255, 255, 255);
    // just scale this down a bit
    paint.setTextSize(mPictureSizeInPx * 3 / 4);
    Rect rect = new Rect();
    paint.getTextBounds(letter, 0, 1, rect);
    float width = paint.measureText(letter);
    canvas.drawText(letter, (mPictureSizeInPx / 2f) - (width / 2f), (mPictureSizeInPx / 2f) + (rect.height() / 2f), paint);
    return result;
}

89. LGraphics#drawNotCacheMirrorBitmap()

Project: LGame
Source File: LGraphics.java
View license
public void drawNotCacheMirrorBitmap(Bitmap bit, int x, int y, boolean filter) {
    if (isClose) {
        return;
    }
    if (bit == null) {
        return;
    }
    tmp_matrix.reset();
    tmp_matrix.setValues(mirror);
    int width = bit.getWidth();
    int height = bit.getHeight();
    Bitmap dst = Bitmap.createBitmap(bit, 0, 0, width, height, tmp_matrix, filter);
    canvas.drawBitmap(dst, x, y, paint);
    dst.recycle();
    dst = null;
}

90. LGraphics#drawFlipBitmap()

Project: LGame
Source File: LGraphics.java
View license
public void drawFlipBitmap(Bitmap bit, int x, int y, boolean filter) {
    if (isClose) {
        return;
    }
    if (bit == null) {
        return;
    }
    tmp_matrix.reset();
    tmp_matrix.postRotate(180);
    Bitmap dst = Bitmap.createBitmap(bit, 0, 0, bit.getWidth(), bit.getHeight(), tmp_matrix, filter);
    canvas.drawBitmap(dst, x, y, paint);
    dst.recycle();
    dst = null;
}

91. LGraphics#drawReverseBitmap()

Project: LGame
Source File: LGraphics.java
View license
public void drawReverseBitmap(Bitmap bit, int x, int y, boolean filter) {
    if (isClose) {
        return;
    }
    if (bit == null) {
        return;
    }
    tmp_matrix.reset();
    tmp_matrix.postRotate(270);
    Bitmap dst = Bitmap.createBitmap(bit, 0, 0, bit.getWidth(), bit.getHeight(), tmp_matrix, filter);
    canvas.drawBitmap(dst, x, y, paint);
    dst.recycle();
    dst = null;
}

92. LGraphics#copyArea()

Project: LGame
Source File: LGraphics.java
View license
public void copyArea(int x, int y, int width, int height, int dx, int dy) {
    if (isClose) {
        return;
    }
    if (x < 0) {
        width += x;
        x = 0;
    }
    if (y < 0) {
        height += y;
        y = 0;
    }
    if (x + width > grapBitmap.getWidth()) {
        width = grapBitmap.getWidth() - x;
    }
    if (y + height > grapBitmap.getHeight()) {
        height = grapBitmap.getHeight() - y;
    }
    Bitmap copy = Bitmap.createBitmap(grapBitmap, x, y, width, height);
    canvas.drawBitmap(copy, x + dx, y + dy, null);
    copy.recycle();
    copy = null;
}

93. LGraphics#copyArea()

Project: LGame
Source File: LGraphics.java
View license
public void copyArea(int x, int y, int width, int height, int dx, int dy) {
    if (isClose) {
        return;
    }
    if (x < 0) {
        width += x;
        x = 0;
    }
    if (y < 0) {
        height += y;
        y = 0;
    }
    if (x + width > grapBitmap.getWidth()) {
        width = grapBitmap.getWidth() - x;
    }
    if (y + height > grapBitmap.getHeight()) {
        height = grapBitmap.getHeight() - y;
    }
    Bitmap copy = Bitmap.createBitmap(grapBitmap, x, y, width, height);
    canvas.drawBitmap(copy, x + dx, y + dy, null);
    copy.recycle();
    copy = null;
}

94. Texture#loadTexture()

Project: LiquidFunPaint
Source File: Texture.java
View license
/**
     * Load the drawable into a texture.
     *
     * @param context Context
     */
private void loadTexture(Context context, int resourceId, boolean scale, WrapParam wrapS, WrapParam wrapT) {
    BitmapFactory.Options opt = new BitmapFactory.Options();
    opt.inScaled = scale;
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, opt);
    bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), Y_FLIP_MATRIX, false);
    // Load texture
    loadTexture(bitmap, scale, wrapS, wrapT);
    bitmap.recycle();
}

95. RoundedImageView#onDraw()

View license
@Override
protected void onDraw(Canvas canvas) {
    Drawable drawable = getDrawable();
    if (drawable == null || getWidth() == 0 || getHeight() == 0)
        return;
    Bitmap bitmap = drawableToBitmap(drawable);
    Bitmap roundedBitmap = getCroppedBitmap(bitmap.copy(Bitmap.Config.ARGB_8888, true), getWidth());
    canvas.drawBitmap(roundedBitmap, 0, 0, null);
}

96. UpdateDisplayStateTest#assertSameNotification()

View license
private void assertSameNotification(UpdateDisplayState.DisplayState.InAppNotificationState original, UpdateDisplayState.DisplayState.InAppNotificationState reconstructed) {
    assertEquals(original.getHighlightColor(), reconstructed.getHighlightColor());
    final InAppNotification originalInApp = original.getInAppNotification();
    final InAppNotification reconstructedInApp = reconstructed.getInAppNotification();
    assertEquals(originalInApp.getId(), reconstructedInApp.getId());
    assertEquals(originalInApp.getMessageId(), reconstructedInApp.getMessageId());
    assertEquals(originalInApp.getBody(), reconstructedInApp.getBody());
    assertEquals(originalInApp.getCallToAction(), reconstructedInApp.getCallToAction());
    assertEquals(originalInApp.getCallToActionUrl(), reconstructedInApp.getCallToActionUrl());
    assertEquals(originalInApp.getImageUrl(), reconstructedInApp.getImageUrl());
    assertEquals(originalInApp.getTitle(), reconstructedInApp.getTitle());
    assertEquals(originalInApp.getType(), reconstructedInApp.getType());
    final Bitmap originalImage = originalInApp.getImage();
    final Bitmap reconstructedImage = reconstructedInApp.getImage();
    assertEquals(originalImage.getWidth(), reconstructedImage.getWidth());
    assertEquals(originalImage.getPixel(0, 0), originalImage.getPixel(0, 0));
}

97. ScreenUtil#snapShotWithStatusBar()

Project: MousePaint
Source File: ScreenUtil.java
View license
/**
     * ??????????????
     * @param activity
     * @return
     */
public static Bitmap snapShotWithStatusBar(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap bmp = view.getDrawingCache();
    int width = getScreenWidth();
    int height = getScreenHeight();
    Bitmap bp = null;
    bp = Bitmap.createBitmap(bmp, 0, 0, width, height);
    view.destroyDrawingCache();
    return bp;
}

98. ScreenUtil#snapShotWithoutStatusBar()

Project: MousePaint
Source File: ScreenUtil.java
View license
/**
     * ???????????????
     * @param activity
     * @return
     */
public static Bitmap snapShotWithoutStatusBar(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap bmp = view.getDrawingCache();
    Rect frame = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    int statusBarHeight = frame.top;
    int width = getScreenWidth();
    int height = getScreenHeight();
    Bitmap bp = null;
    bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height - statusBarHeight);
    view.destroyDrawingCache();
    return bp;
}

99. RoundedImageView#getRoundedCroppedBitmap()

View license
private static Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) {
    Bitmap finalBitmap;
    if (bitmap.getWidth() != radius || bitmap.getHeight() != radius)
        finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius, false);
    else
        finalBitmap = bitmap;
    Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(), finalBitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, finalBitmap.getWidth(), finalBitmap.getHeight());
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawCircle(finalBitmap.getWidth() / 2 + 0.7f, finalBitmap.getHeight() / 2 + 0.7f, finalBitmap.getWidth() / 2 + 0.1f, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(finalBitmap, rect, rect, paint);
    return output;
}

100. TheFullscreenBarcodeActivity#testWithBarcodeFormat()

View license
private void testWithBarcodeFormat(final PassBarCodeFormat format) {
    final PassImpl pass = new PassImpl(UUID.randomUUID().toString());
    pass.setBarCode(new BarCode(format, BARCODE_MESSAGE));
    passStore.setCurrentPass(pass);
    getActivity();
    onView(withId(R.id.fullscreen_barcode)).check(matches(isDisplayed()));
    final ImageView viewById = ButterKnife.findById(getActivity(), R.id.fullscreen_barcode);
    BitmapDrawable bitmapDrawable = (BitmapDrawable) viewById.getDrawable();
    final Bitmap bitmap = bitmapDrawable.getBitmap();
    final Bitmap bitmapToTest;
    if (format == PassBarCodeFormat.AZTEC) {
        // not sure why - but for the decoder to pick up AZTEC it must have moar pixelz - smells like a zxing bug
        bitmapToTest = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth() * 2, bitmap.getHeight() * 2, false);
    } else {
        bitmapToTest = bitmap;
    }
    assertThat(BarcodeDecoder.decodeBitmap(bitmapToTest)).isEqualTo(BARCODE_MESSAGE);
}