Here are the examples of the java api class android.graphics.Bitmap taken from open source projects.
1. BearSceneView#init()
Project: Depth-LIB-Android-
File: BearSceneView.java
File: BearSceneView.java
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
File: MediaStorage.java
File: MediaStorage.java
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. BitmapPoolTest#testIsReusable()
Project: fresco
File: BitmapPoolTest.java
File: BitmapPoolTest.java
// 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)); }
4. WaterSceneView#init()
Project: Depth-LIB-Android-
File: WaterSceneView.java
File: WaterSceneView.java
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); }
5. TexCubeSmallGLUT#setTex()
Project: opengl
File: TexCubeSmallGLUT.java
File: TexCubeSmallGLUT.java
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
File: TexCubeSmallGLUT.java
File: TexCubeSmallGLUT.java
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. ImageBlurManager#doBlurJniArray()
Project: SimplifyReader
File: ImageBlurManager.java
File: ImageBlurManager.java
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); }
8. ScreenshotTaker#getBitmapOfView()
Project: robotium
File: ScreenshotTaker.java
File: ScreenshotTaker.java
/** * 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; }
9. RoundedImageView#onDraw()
Project: repay-android
File: RoundedImageView.java
File: RoundedImageView.java
@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); }
10. HeartView#createHeart()
Project: MousePaint
File: HeartView.java
File: HeartView.java
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; }
11. LoadingImageView#initMaskBitmap()
Project: LoadingImageView
File: LoadingImageView.java
File: LoadingImageView.java
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); }
12. Blur#blur()
Project: LiveBlurListView
File: Blur.java
File: Blur.java
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; }
13. CircleTransform#transform()
Project: TuentiTV
File: CircleTransform.java
File: CircleTransform.java
@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; }
14. TagsEditText#convertViewToDrawable()
Project: TagsEditText
File: TagsEditText.java
File: TagsEditText.java
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); }
15. LruCacheTest#overMaxSizeDoesNotClear()
Project: picasso
File: LruCacheTest.java
File: LruCacheTest.java
@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); }
16. ImageProcessor#doHighlightImage()
Project: photofilter
File: ImageProcessor.java
File: ImageProcessor.java
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; }
17. RoundedImageView#onDraw()
Project: openshop.io-android
File: RoundedImageView.java
File: RoundedImageView.java
@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); }
18. CircleTransformation#transform()
Project: Nox
File: CircleTransformation.java
File: CircleTransformation.java
@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; }
19. BitmapUtils#drawViewToBitmap()
Project: NBAPlus
File: BitmapUtils.java
File: BitmapUtils.java
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; }
20. JmeAndroidSystem#writeImageFile()
Project: jmonkeyengine
File: JmeAndroidSystem.java
File: JmeAndroidSystem.java
@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(); }
21. StackBlur#blurNativelyPixels()
Project: ImageBlurring
File: StackBlur.java
File: StackBlur.java
/** * 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); }
22. StackBlur#blurNativelyPixels()
Project: Genius-Android
File: StackBlur.java
File: StackBlur.java
/** * 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); }
23. BitmapUtilTest#testGetSizeInBytes()
Project: fresco
File: BitmapUtilTest.java
File: BitmapUtilTest.java
@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)); }
24. RepeatedPostprocessorProducerTest#runPostprocessAgainWhenDirty()
Project: fresco
File: RepeatedPostprocessorProducerTest.java
File: RepeatedPostprocessorProducerTest.java
@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); }
25. CircledImageView#onDraw()
Project: ExpandablePanel
File: CircledImageView.java
File: CircledImageView.java
@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); }
26. ACVComic#getScreenWithContents()
Project: droid-comic-viewer
File: ACVComic.java
File: ACVComic.java
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); }
27. BitmapsGenerator#getSatValBitmapFrom()
Project: AndroidPhotoshopColorPicker
File: BitmapsGenerator.java
File: BitmapsGenerator.java
/**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; }
28. MultiSelectEditText#convertViewToDrawable()
Project: AutoCompleteBubbleText
File: MultiSelectEditText.java
File: MultiSelectEditText.java
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; }
29. BitmapActivity#onCreate()
Project: android-combination-avatar
File: BitmapActivity.java
File: BitmapActivity.java
@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); }
30. RoundedImageView#onDraw()
Project: AmazeFileManager
File: RoundedImageView.java
File: RoundedImageView.java
@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); }
31. TextViewUtils#convertViewToDrawable()
Project: AcFun-Area63
File: TextViewUtils.java
File: TextViewUtils.java
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); }
32. BitmapUtil#convertGreyImg()
Project: AndroidStudyDemo
File: BitmapUtil.java
File: BitmapUtil.java
/** * ?????????? * * @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; }
33. DisplayUtil#snapShotWithoutStatusBar()
Project: AndroidStudyDemo
File: DisplayUtil.java
File: DisplayUtil.java
/** * ??????????????? * * @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; }
34. DisplayUtil#snapShotWithStatusBar()
Project: AndroidStudyDemo
File: DisplayUtil.java
File: DisplayUtil.java
/** * ?????????????? * * @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; }
35. ImageProcessor#applyCurves()
Project: AndroidPhotoFilters
File: ImageProcessor.java
File: ImageProcessor.java
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; }
36. ImageUtil#decodeScaleImage()
Project: AndroidLife
File: ImageUtil.java
File: ImageUtil.java
/** * ???? */ 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; } }
37. EncodingHandler#createQRCode()
Project: Android-ZBLibrary
File: EncodingHandler.java
File: EncodingHandler.java
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; }
38. PlanarYUVLuminanceSource#renderCroppedGreyscaleBitmap()
Project: Android-ZBLibrary
File: PlanarYUVLuminanceSource.java
File: PlanarYUVLuminanceSource.java
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. EncodingHandler#createQRCode()
Project: Android-ZBLibrary
File: EncodingHandler.java
File: EncodingHandler.java
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; }
40. PlanarYUVLuminanceSource#renderCroppedGreyscaleBitmap()
Project: Android-ZBLibrary
File: PlanarYUVLuminanceSource.java
File: PlanarYUVLuminanceSource.java
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. Utils#roundBitmap()
Project: android-utils
File: Utils.java
File: Utils.java
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; }
42. ImageUtils#scaleDownBitmapForUri()
Project: android-utils
File: ImageUtils.java
File: ImageUtils.java
/** * 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. MusicProviderTest#testUpdateMusicArt()
Project: android-UniversalMusicPlayer
File: MusicProviderTest.java
File: MusicProviderTest.java
@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)); }
44. PlanarYUVLuminanceSource#renderCroppedGreyscaleBitmap()
Project: android-quick-response-code
File: PlanarYUVLuminanceSource.java
File: PlanarYUVLuminanceSource.java
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. GlideCircleTransform#circleCrop()
Project: android-open-project-demo
File: GlideCircleTransform.java
File: GlideCircleTransform.java
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; }
46. PlanarYUVLuminanceSource#renderCroppedGreyscaleBitmap()
Project: android-ocr
File: PlanarYUVLuminanceSource.java
File: PlanarYUVLuminanceSource.java
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. ListPaymentMethodNonceTest#displaysCorrectActivePaymentMethod()
Project: braintree_android
File: ListPaymentMethodNonceTest.java
File: ListPaymentMethodNonceTest.java
@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)); }
48. ListPaymentMethodNonceTest#displaysACard()
Project: braintree_android
File: ListPaymentMethodNonceTest.java
File: ListPaymentMethodNonceTest.java
@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)); }
49. TestImplConvertBitmap#checkBitmapToMultiRGB()
Project: BoofCV
File: TestImplConvertBitmap.java
File: TestImplConvertBitmap.java
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); } }
50. TestImplConvertBitmap#checkBitmapToGrayRGB()
Project: BoofCV
File: TestImplConvertBitmap.java
File: TestImplConvertBitmap.java
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); } }
51. PlanarYUVLuminanceSource#renderCroppedGreyscaleBitmap()
Project: bitcoin-android
File: PlanarYUVLuminanceSource.java
File: PlanarYUVLuminanceSource.java
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; }
52. DecodeHandler#bundleThumbnail()
Project: BarcodeScanner
File: DecodeHandler.java
File: DecodeHandler.java
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()); }
53. AsyncImageView#getImageBitmap()
Project: astrid
File: AsyncImageView.java
File: AsyncImageView.java
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; }
54. FilterListFragment#superImposeListIcon()
Project: astrid
File: FilterListFragment.java
File: FilterListFragment.java
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; }
55. FastBlurTransformation#transform()
Project: AntennaPod
File: FastBlurTransformation.java
File: FastBlurTransformation.java
@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. MainActivity#showAnimDialog()
Project: AnimProgressBar
File: MainActivity.java
File: MainActivity.java
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; } }); }
57. BitmapUtil#convertToBlackWhite()
Project: AndroidStudyDemo
File: BitmapUtil.java
File: BitmapUtil.java
/** * ?????????? * * @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; }
58. WebpBitmapFactoryTest#testInBitmap()
Project: fresco
File: WebpBitmapFactoryTest.java
File: WebpBitmapFactoryTest.java
@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)); }
59. WebpBitmapFactoryTest#testWebpDecodeStream()
Project: fresco
File: WebpBitmapFactoryTest.java
File: WebpBitmapFactoryTest.java
@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")); }
60. ImageHelper#rotateImageFile()
Project: fanfouapp-opensource
File: ImageHelper.java
File: ImageHelper.java
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; }
61. MainActivity#initWidget()
Project: FaceRecognition
File: MainActivity.java
File: MainActivity.java
@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); }
62. DecodeHandler#bundleThumbnail()
Project: ExhibitionCenter
File: DecodeHandler.java
File: DecodeHandler.java
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()); }
63. SocialUtils#compressBitmap()
Project: ESSocialSDK
File: SocialUtils.java
File: SocialUtils.java
/** * ???? * * @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; }
64. ShadowDecorator#processBitmap()
Project: enroscar
File: ShadowDecorator.java
File: ShadowDecorator.java
@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; }
65. CardBgTest#doGenCardBg()
Project: EhViewer
File: CardBgTest.java
File: CardBgTest.java
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); }
66. GlideCircleTransform#transform()
Project: EasyGank
File: GlideCircleTransform.java
File: GlideCircleTransform.java
@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; }
67. ImageRequestTransformer#transform()
Project: CrossBow
File: ImageRequestTransformer.java
File: ImageRequestTransformer.java
@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(); }
68. MainActivity#onCreate()
Project: codeexamples-android
File: MainActivity.java
File: MainActivity.java
@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)); }
69. ChatFileStore#resizeAndImportImage()
Project: ChatSecureAndroid
File: ChatFileStore.java
File: ChatFileStore.java
/** * 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); }
70. PlanarYUVLuminanceSource#renderCroppedGreyscaleBitmap()
Project: android-app
File: PlanarYUVLuminanceSource.java
File: PlanarYUVLuminanceSource.java
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; }
71. BlurTransform#transform()
Project: Amphitheatre
File: BlurTransform.java
File: BlurTransform.java
@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; }
72. CropView#crop()
Project: AlbumSelector
File: CropView.java
File: CropView.java
/** * 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; }
73. WebViewMapFragment#getSnapshot()
Project: AirMapView
File: WebViewMapFragment.java
File: WebViewMapFragment.java
@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); }
74. Coloring#colorDrawable()
Project: actual-number-picker
File: Coloring.java
File: Coloring.java
/** * 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); }
75. AndroidMessenger#sendAnimation()
Project: actor-platform
File: AndroidMessenger.java
File: AndroidMessenger.java
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); }
76. ContactPictureLoader#calculateFallbackBitmap()
Project: k-9
File: ContactPictureLoader.java
File: ContactPictureLoader.java
/** * 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; }
77. MjpegFileWriter#writeImageToBytes()
Project: jmonkeyengine
File: MjpegFileWriter.java
File: MjpegFileWriter.java
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(); }
78. BitmapUtils#blackAndWhited()
Project: ImageLoader_Android
File: BitmapUtils.java
File: BitmapUtils.java
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; }
79. DrawingView#setCanvasBitmap()
Project: helpstack-android
File: DrawingView.java
File: DrawingView.java
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); }
80. RoundedCornersTransformation#transform()
Project: glide-transformations
File: RoundedCornersTransformation.java
File: RoundedCornersTransformation.java
@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); }
81. MaskTransformation#transform()
Project: glide-transformations
File: MaskTransformation.java
File: MaskTransformation.java
@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); }
82. GrayscaleTransformation#transform()
Project: glide-transformations
File: GrayscaleTransformation.java
File: GrayscaleTransformation.java
@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. CropSquareTransformation#transform()
Project: glide-transformations
File: CropSquareTransformation.java
File: CropSquareTransformation.java
@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); }
84. ColorFilterTransformation#transform()
Project: glide-transformations
File: ColorFilterTransformation.java
File: ColorFilterTransformation.java
@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); }
85. DebugImage#writeNv21Image()
Project: gast-lib
File: DebugImage.java
File: DebugImage.java
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); }
86. DebugImage#writeGrayImage()
Project: gast-lib
File: DebugImage.java
File: DebugImage.java
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); }
87. UiHelper#snapShotWithoutStatusBar()
Project: GanWuMei
File: UiHelper.java
File: UiHelper.java
/** * ??????????????? */ 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; }
88. UiHelper#snapShotWithStatusBar()
Project: GanWuMei
File: UiHelper.java
File: UiHelper.java
/** * ?????????????? */ 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; }
89. UpdateDisplayStateTest#assertSameNotification()
Project: mixpanel-android
File: UpdateDisplayStateTest.java
File: UpdateDisplayStateTest.java
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)); }
90. RoundedImageView#onDraw()
Project: material-design-library
File: RoundedImageView.java
File: RoundedImageView.java
@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); }
91. Texture#loadTexture()
Project: LiquidFunPaint
File: Texture.java
File: Texture.java
/** * 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(); }
92. LGraphics#copyArea()
Project: LGame
File: LGraphics.java
File: LGraphics.java
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
File: LGraphics.java
File: LGraphics.java
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. LGraphics#drawReverseBitmap()
Project: LGame
File: LGraphics.java
File: LGraphics.java
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; }
95. LGraphics#drawFlipBitmap()
Project: LGame
File: LGraphics.java
File: LGraphics.java
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; }
96. LGraphics#drawNotCacheMirrorBitmap()
Project: LGame
File: LGraphics.java
File: LGraphics.java
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; }
97. VisualFilters#applyFilter()
Project: Snapprefs
File: VisualFilters.java
File: VisualFilters.java
private static void applyFilter(Bitmap source, Bitmap result, FilterType type) { GPUImage gpuImage = new GPUImage(context); gpuImage.setImage(source); gpuImage.setFilter(type.getFilter()); Bitmap filtered = gpuImage.getBitmapWithFilterApplied(); int[] pixels = new int[filtered.getHeight() * filtered.getWidth()]; filtered.getPixels(pixels, 0, filtered.getWidth(), 0, 0, filtered.getWidth(), filtered.getHeight()); result.setPixels(pixels, 0, filtered.getWidth(), 0, 0, filtered.getWidth(), filtered.getHeight()); // Canvas canvas = new Canvas(result); // // Paint paint = new Paint(); // paint.setColor(Color.WHITE); // paint.setTextSize(50); // paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); // // canvas.drawBitmap(result, 0, 0, paint); // canvas.drawText(type.name(), 150, 150, paint); }
98. ImageUtils#adjustmentMethodScale()
Project: Snapprefs
File: ImageUtils.java
File: ImageUtils.java
/** * Creates a bitmap with the resolution of the device and puts the given bitmap using the scale, x- and y-transitions. * * @param bitmap The bitmap to be used as source * @param scale The scale the image has to be enlarged or reduced * @param xTrans The x-transition * @param yTrans The y-transition * @return The adjusted bitmap */ public Bitmap adjustmentMethodScale(Bitmap bitmap, float scale, float xTrans, float yTrans) { // we are going to scale the image down and place a black background behind it Bitmap background = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888); background.eraseColor(Color.BLACK); Canvas canvas = new Canvas(background); Matrix transform = new Matrix(); transform.preScale(scale, scale); transform.postTranslate(xTrans, yTrans); Paint paint = new Paint(); paint.setFilterBitmap(true); canvas.drawBitmap(bitmap, transform, paint); bitmap.recycle(); return background; }
99. RotateImageProcessor#process()
Project: Sketch
File: RotateImageProcessor.java
File: RotateImageProcessor.java
@Override public Bitmap process(Sketch sketch, Bitmap bitmap, Resize resize, boolean forceUseResize, boolean lowQualityImage) { Bitmap resizeBitmap = super.process(sketch, bitmap, resize, forceUseResize, lowQualityImage); if (degrees == 0) { return resizeBitmap; } Matrix matrix = new Matrix(); matrix.setRotate(degrees); Bitmap rotateBitmap = Bitmap.createBitmap(resizeBitmap, 0, 0, resizeBitmap.getWidth(), resizeBitmap.getHeight(), matrix, true); if (resizeBitmap != bitmap) { resizeBitmap.recycle(); } return rotateBitmap; }
100. GaussianBlurImageProcessor#process()
Project: Sketch
File: GaussianBlurImageProcessor.java
File: GaussianBlurImageProcessor.java
@Override public Bitmap process(Sketch sketch, Bitmap bitmap, Resize resize, boolean forceUseResize, boolean lowQualityImage) { // cut handle Bitmap resizeBitmap = super.process(sketch, bitmap, resize, forceUseResize, lowQualityImage); if (resizeBitmap == null) { return null; } // blur handle Bitmap blurBitmap = fastGaussianBlur(resizeBitmap, radius, false); if (resizeBitmap != bitmap) { resizeBitmap.recycle(); } // dark handle if (blurBitmap != null && isDarkHandle) { Canvas canvas = new Canvas(blurBitmap); canvas.drawColor(Color.parseColor("#55000000")); } return blurBitmap; }