当前位置: 首页>>代码示例>>Java>>正文


Java Bitmap.prepareToDraw方法代码示例

本文整理汇总了Java中android.graphics.Bitmap.prepareToDraw方法的典型用法代码示例。如果您正苦于以下问题:Java Bitmap.prepareToDraw方法的具体用法?Java Bitmap.prepareToDraw怎么用?Java Bitmap.prepareToDraw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.Bitmap的用法示例。


在下文中一共展示了Bitmap.prepareToDraw方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: internalPrepareBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
private void internalPrepareBitmap(CloseableReference<CloseableImage> newResult) {
  if (newResult == null || !newResult.isValid()) {
    return;
  }

  final CloseableImage closeableImage = newResult.get();
  if (closeableImage == null || closeableImage.isClosed()) {
    return;
  }

  if (closeableImage instanceof CloseableStaticBitmap) {
    final CloseableStaticBitmap staticBitmap = (CloseableStaticBitmap) closeableImage;
    final Bitmap bitmap = staticBitmap.getUnderlyingBitmap();
    if (bitmap == null) {
      return;
    }

    final int bitmapByteCount = bitmap.getRowBytes() * bitmap.getHeight();
    if (bitmapByteCount < mMinBitmapSizeBytes) {
      return;
    }
    if (bitmapByteCount > mMaxBitmapSizeBytes) {
      return;
    }

    bitmap.prepareToDraw();
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:BitmapPrepareProducer.java

示例2: colorBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * Colors the given bitmap to the specified color. Uses {@link PorterDuff.Mode#SRC_ATOP}.
 *
 * @param bitmap The original bitmap, must not be {@code null}
 * @param color  Which color to use for coloring
 * @return A new, colored Bitmap, never {@code null}
 */
@NonNull
public static Bitmap colorBitmap(@NonNull final Bitmap bitmap, @ColorInt final int color) {
    // use the original bitmap config
    final Bitmap result = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());

    // paint over the new canvas
    final Paint paint = new Paint();
    final Canvas c = new Canvas(result);
    paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
    c.drawBitmap(bitmap, 0, 0, paint);

    result.prepareToDraw();
    return result;
}
 
开发者ID:milosmns,项目名称:silly-android,代码行数:22,代码来源:Coloring.java

示例3: testColorBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * Tests the {@link Coloring#colorBitmap(Bitmap, int)} method.
 * <p>
 * Due to {@link org.robolectric.shadows.ShadowBitmap}'s empty implementation, this won't really work, so we can only test the transparency.
 */
@Test
public final void testColorBitmap() {
    final Bitmap.Config config = Bitmap.Config.ARGB_8888;
    final int width = 10, height = 10;
    final int[] allReds = new int[width * height];
    for (int i = 0; i < width * height; i++) {
        allReds[i] = Color.RED;
    }

    final Bitmap redSquare = Bitmap.createBitmap(allReds, width, height, config);
    assertNotNull("Created Bitmap is null", redSquare);

    // initialize red Bitmap's internal structures, otherwise it won't draw properly
    redSquare.prepareToDraw();
    final byte[] redPixels = new byte[redSquare.getWidth() * redSquare.getHeight() * 8];
    final ByteBuffer redBuffer = ByteBuffer.wrap(redPixels);
    redBuffer.order(ByteOrder.nativeOrder());
    redSquare.copyPixelsToBuffer(redBuffer);
    redSquare.copyPixelsFromBuffer(redBuffer);
    redSquare.prepareToDraw();

    final String redPixel = hex(redSquare.getPixel(width / 2, height / 2));
    final String errorRed = String.format("Error while creating red bitmap, middle pixel is %s", redPixel);
    assertEquals(errorRed, hex(Color.TRANSPARENT), redPixel);

    final Bitmap greenSquare = Coloring.colorBitmap(redSquare, Color.GREEN);
    assertNotNull("Created colored Bitmap is null", greenSquare);
    final String greenPixel = hex(greenSquare.getPixel(width / 2, height / 2));
    final String errorGreen = String.format("Error while coloring bitmap, middle pixel is %s", greenPixel);
    assertEquals(errorGreen, hex(Color.TRANSPARENT), greenPixel);
}
 
开发者ID:milosmns,项目名称:silly-android,代码行数:37,代码来源:ColoringTest.java

示例4: takeScreenshot

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * Takes Reboot screenshot of the current display and shows an animation.
 */
@SuppressLint("NewApi")
public void takeScreenshot(Context context, String fileFullPath)
{
    if(fileFullPath == ""){
        format = new SimpleDateFormat("yyyyMMddHHmmss");
        String fileName = format.format(new Date(System.currentTimeMillis())) + ".png";
        fileFullPath = "/data/local/tmp/" + fileName;
    }

    if(ShellUtils.checkRootPermission()){
        if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH){
            ShellUtils.execCommand("/system/bin/screencap -p "+ fileFullPath,true);
        }
    }
    else {
        if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2 && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH){
            wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            mDisplay = wm.getDefaultDisplay();
            mDisplayMatrix = new Matrix();
            mDisplayMetrics = new DisplayMetrics();
            // We need to orient the screenshot correctly (and the Surface api seems to take screenshots
            // only in the natural orientation of the device :!)
            mDisplay.getRealMetrics(mDisplayMetrics);
            float[] dims =
                    {
                            mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels
                    };
            float degrees = getDegreesForRotation(mDisplay.getRotation());
            boolean requiresRotation = (degrees > 0);
            if (requiresRotation)
            {
                // Get the dimensions of the device in its native orientation
                mDisplayMatrix.reset();
                mDisplayMatrix.preRotate(-degrees);
                mDisplayMatrix.mapPoints(dims);
                dims[0] = Math.abs(dims[0]);
                dims[1] = Math.abs(dims[1]);
            }

            Bitmap mScreenBitmap = screenShot((int) dims[0], (int) dims[1]);
            if (requiresRotation)
            {
                // Rotate the screenshot to the current orientation
                Bitmap ss = Bitmap.createBitmap(mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels,
                        Bitmap.Config.ARGB_8888);
                Canvas c = new Canvas(ss);
                c.translate(ss.getWidth() / 2, ss.getHeight() / 2);
                c.rotate(degrees);
                c.translate(-dims[0] / 2, -dims[1] / 2);
                c.drawBitmap(mScreenBitmap, 0, 0, null);
                c.setBitmap(null);
                mScreenBitmap = ss;
                if (ss != null && !ss.isRecycled())
                {
                    ss.recycle();
                }
            }

            // If we couldn't take the screenshot, notify the user
            if (mScreenBitmap == null)
            {
                Toast.makeText(context, "screen shot fail", Toast.LENGTH_SHORT).show();
            }

            // Optimizations
            mScreenBitmap.setHasAlpha(false);
            mScreenBitmap.prepareToDraw();

            saveBitmap2file(context, mScreenBitmap, fileFullPath);
        }
    }

}
 
开发者ID:kaixuanluo,项目名称:pc-android-controller-android,代码行数:77,代码来源:ScreentShotUtil.java


注:本文中的android.graphics.Bitmap.prepareToDraw方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。