android.graphics.Bitmap.getNinePatchChunk()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(365)

本文整理了Java中android.graphics.Bitmap.getNinePatchChunk()方法的一些代码示例,展示了Bitmap.getNinePatchChunk()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bitmap.getNinePatchChunk()方法的具体详情如下:
包路径:android.graphics.Bitmap
类名称:Bitmap
方法名:getNinePatchChunk

Bitmap.getNinePatchChunk介绍

暂无

代码示例

代码示例来源:origin: vondear/RxTool

private void drawNinepath(Canvas canvas, int resId, Rect rect) {
  Bitmap bmp = BitmapFactory.decodeResource(getResources(), resId);
  NinePatch patch = new NinePatch(bmp, bmp.getNinePatchChunk(), null);
  patch.draw(canvas, rect);
}

代码示例来源:origin: robolectric/robolectric

@Implementation // todo: this sucks, it's all just so we can detect 9-patches
protected static Drawable createFromResourceStream(
  Resources res, TypedValue value, InputStream is, String srcName, BitmapFactory.Options opts) {
 if (is == null) {
  return null;
 }
 Rect pad = new Rect();
 if (opts == null) opts = new BitmapFactory.Options();
 opts.inScreenDensity = DisplayMetrics.DENSITY_DEFAULT;
 Bitmap  bm = BitmapFactory.decodeResourceStream(res, value, is, pad, opts);
 if (bm != null) {
  boolean isNinePatch = srcName != null && srcName.contains(".9.");
  if (isNinePatch) {
   ReflectionHelpers.callInstanceMethod(bm, "setNinePatchChunk", ClassParameter.from(byte[].class, new byte[0]));
  }
  byte[] np = bm.getNinePatchChunk();
  if (np == null || !NinePatch.isNinePatchChunk(np)) {
   np = null;
   pad = null;
  }
  if (np != null) {
   // todo: wrong
   return new NinePatchDrawable(res, bm, np, pad, srcName);
  }
  return new BitmapDrawable(res, bm);
 }
 return null;
}

代码示例来源:origin: stackoverflow.com

public static Bitmap get_ninepatch(int id,int x, int y, Context context){
   // id is a resource id for a valid ninepatch
   Bitmap bitmap = BitmapFactory.decodeResource(
       context.getResources(), id);
   byte[] chunk = bitmap.getNinePatchChunk();
   NinePatchDrawable np_drawable = new NinePatchDrawable(bitmap,
       chunk, new Rect(), null);
   np_drawable.setBounds(0, 0,x, y);
   Bitmap output_bitmap = Bitmap.createBitmap(x, y, Bitmap.Config.ARGB_8888);
   Canvas canvas = new Canvas(output_bitmap);
   np_drawable.draw(canvas);
   return output_bitmap;
 }

代码示例来源:origin: stackoverflow.com

NinePatchDrawable ninepatch;
Bitmap image = BitmapFactory.decodeResource(getResources(),R.drawable.ninepatch_background);
if (image.getNinePatchChunk()!=null){
  byte[] chunk = image.getNinePatchChunk();
  Rect paddingRectangle = new Rect(30, 0, 30, 50);
  ninepatch = new NinePatchDrawable(getResources(), image, chunk, paddingRectangle, null);
}
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
  linLayout.setBackgroundDrawable(ninepatch);
} else {
  linLayout.setBackground(ninepatch);
}

代码示例来源:origin: stackoverflow.com

InputStream in = MyClass.class.getResourceAsStream("/images/btn_default_normal.9.png");
Bitmap bitmap = BitmapFactory.decodeStream(in);
byte[] chunk = bitmap.getNinePatchChunk();
NinePatchDrawable drawable = new NinePatchDrawable(getResources(), bitmap, chunk, new Rect(), null);
button.setBackgroundDrawable(drawable);

代码示例来源:origin: zhujian1989/gank.io

public RecyclerViewItemDecoration(int recyclerviewMode, Context context, int drawableRid){
  this.recyclerviewMode = recyclerviewMode;
  this.drawableRid = drawableRid;
  this.bmp = BitmapFactory.decodeResource(context.getResources(), drawableRid);
  if(bmp.getNinePatchChunk()!=null){
    hasNinePatch = true;
    ninePatch = new NinePatch(bmp, bmp.getNinePatchChunk(), null);
  }
  initPaint();
}

代码示例来源:origin: stackoverflow.com

private Drawable loadNinePatch(String path, Context context) {
    Bitmap bitmap = BitmapFactory.decodeFile(path);
    byte[] chunk = bitmap.getNinePatchChunk();
    if(NinePatch.isNinePatchChunk(chunk)) {
      return new NinePatchDrawable(context.getResources(), bitmap, chunk, new Rect(), null);
    } else return new BitmapDrawable(bitmap);
}

代码示例来源:origin: stackoverflow.com

private Drawable displayNinePatch(String path, Context context) {
  Bitmap bitmap = BitmapFactory.decodeFile(path);
  byte[] chunk = bitmap.getNinePatchChunk();
  if(NinePatch.isNinePatchChunk(chunk)) {
    return new NinePatchDrawable(context.getResources(), bitmap, chunk, new Rect(), null);
  } else return new BitmapDrawable(bitmap);
}

代码示例来源:origin: stackoverflow.com

private Drawable displayNinePatch(Bitmap bitmap, Context context) {
  byte[] chunk = bitmap.getNinePatchChunk();
  if(NinePatch.isNinePatchChunk(chunk)) {
    return new NinePatchDrawable(context.getResources(), bitmap, chunk, new Rect(), null);
  } else return new BitmapDrawable(bitmap);
}

代码示例来源:origin: arjinmc/RecyclerViewDecoration

private void initPaint(Context context) {
  this.mBmp = BitmapFactory.decodeResource(context.getResources(), mDrawableRid);
  if (mBmp != null) {
    if (mBmp.getNinePatchChunk() != null) {
      hasNinePatch = true;
      mNinePatch = new NinePatch(mBmp, mBmp.getNinePatchChunk(), null);
    }
    if (mMode == RVItemDecorationConst.MODE_HORIZONTAL)
      mCurrentThickness = mThickness == 0 ? mBmp.getHeight() : mThickness;
    if (mMode == RVItemDecorationConst.MODE_VERTICAL)
      mCurrentThickness = mThickness == 0 ? mBmp.getWidth() : mThickness;
  }
  mPaint = new Paint();
  mPaint.setColor(mColor);
  mPaint.setStyle(Paint.Style.STROKE);
  mPaint.setStrokeWidth(mThickness);
}

代码示例来源:origin: stackoverflow.com

public static Rect getNinePatchPadding(Context context, int drawableId) {
  Rect mPadding = new Rect();
  Bitmap bm = BitmapFactory.decodeResource(context.getResources(), drawableId);
  final byte[] chunk = bm.getNinePatchChunk();
  if (!NinePatch.isNinePatchChunk(chunk)) return null;
  ByteBuffer byteBuffer = ByteBuffer.wrap(chunk).order(ByteOrder.nativeOrder());

  // Skip to padding
  for (int i = 0; i < 12; i++) {
    byteBuffer.get();
  }

  mPadding.left = byteBuffer.getInt();
  mPadding.top = byteBuffer.getInt();
  mPadding.right = byteBuffer.getInt();
  mPadding.bottom = byteBuffer.getInt();

  return mPadding;
}

代码示例来源:origin: Tencent/RapidView

byte[] chunk = bitmap.getNinePatchChunk();

代码示例来源:origin: Tencent/RapidView

@Override
  public void finish(boolean succeed, String name, Bitmap bmp) {
    Drawable drawable = null;
    if( !succeed ){
      return;
    }
    byte[] chunk = bmp.getNinePatchChunk();
    if(chunk != null && NinePatch.isNinePatchChunk(chunk)){
      drawable = new NinePatchDrawable(fView.getContext().getResources(), bmp, chunk, new Rect(), null);
    }
    else{
      drawable = new BitmapDrawable(bmp);
    }
    fView.setBackgroundDrawable(drawable);
  }
});

代码示例来源:origin: Tencent/RapidView

@Override
  public void finish(boolean succeed, String name, Bitmap bmp) {
    byte[] chunk;
    if (!succeed || bmp == null || bmp.isRecycled()) {
      return;
    }
    chunk = bmp.getNinePatchChunk();
    if ( chunk != null && NinePatch.isNinePatchChunk(chunk) ) {
      Drawable drawable;
      drawable = new NinePatchDrawable(imageView.getContext().getResources(),
          bmp, chunk, new Rect(), null);
      imageView.setImageDrawable(drawable);
      return;
    }
    imageView.setImageBitmap(bmp);
  }
});

代码示例来源:origin: Jay-Goo/RangeSeekBar

/**
 * draw 9Path
 *
 * @param canvas Canvas
 * @param bmp 9path bitmap
 * @param rect 9path rect
 */
public static void drawNinePath(Canvas canvas, Bitmap bmp, Rect rect) {
  NinePatch patch = new NinePatch(bmp, bmp.getNinePatchChunk(), null);
  patch.draw(canvas, rect);
}

代码示例来源:origin: Tophold/FinancialCustomerView

/**
 * draw 9Path
 *
 * @param canvas Canvas
 * @param bmp 9path bitmap
 * @param rect 9path rect
 */
public static void drawNinePath(Canvas canvas, Bitmap bmp, Rect rect) {
  NinePatch patch = new NinePatch(bmp, bmp.getNinePatchChunk(), null);
  patch.draw(canvas, rect);
}

代码示例来源:origin: Tencent/RapidView

@Override
  public void finish(boolean succeed, String name, Bitmap bmp) {
    Drawable drawable = null;
    if( !succeed ){
      return;
    }
    byte[] chunk = bmp.getNinePatchChunk();
    if(chunk != null && NinePatch.isNinePatchChunk(chunk)){
      drawable = new NinePatchDrawable(fBar.getContext().getResources(), bmp, chunk, new Rect(), null);
    }
    else{
      drawable = new BitmapDrawable(bmp);
    }
    fBar.setProgressDrawable(drawable);
  }
});

代码示例来源:origin: angeldevil/ChatImageView

private void init() {
  mMatrix = new Matrix();
  mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  if (mMaskResId <= 0) {
    return;
  }
  mMaskBmp = BitmapFactory.decodeResource(getResources(), mMaskResId);
  byte[] ninePatchChunk = mMaskBmp.getNinePatchChunk();
  if (ninePatchChunk != null && NinePatch.isNinePatchChunk(ninePatchChunk)) {
    mMaskDrawable = new NinePatchDrawable(getResources(), mMaskBmp, ninePatchChunk, new Rect(), null);
  }
  internalSetImage();
}

代码示例来源:origin: stackoverflow.com

private Drawable createBackground(int widthForRatio, int heightForRatio, int displayWidth, int displayHeight) {

  Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.img_border);

  NinePatchDrawable frame = new NinePatchDrawable(getResources(), b, b.getNinePatchChunk(), new Rect(), null);

  Drawable[] layers = { getTransparent(), getTransparent(), getTransparent(), getTransparent(), frame };
  LayerDrawable layerDrawable = new LayerDrawable(layers);

  final TypedArray styledAttributes = getTheme().obtainStyledAttributes(new int[] { android.R.attr.actionBarSize });
  int mActionBarSize = (int) styledAttributes.getDimension(0, 0);
  styledAttributes.recycle();

  layerDrawable.setLayerInset(0, 0, 0, 0, displayHeight - 100 - mActionBarSize);
  layerDrawable.setLayerInset(1, 0, displayHeight - 100 - mActionBarSize, 0, 0);
  layerDrawable.setLayerInset(2, displayWidth - 50, 100, 0, 100);
  layerDrawable.setLayerInset(3, 0, 100, displayWidth - 50, 100);
  layerDrawable.setLayerInset(4, 50, 100, 50, 100);

  return layerDrawable;
}

private ShapeDrawable getTransparent() {
  ShapeDrawable transparent = new ShapeDrawable();
  transparent.getPaint().setColor(Color.parseColor("#AA0A0A0A"));
  return transparent;
}

代码示例来源:origin: biezhihua/MySimpleDraweeView

/**
 * 设置数字标识,内部会判断是否大于1
 */
public MySimpleDraweeView setNumberChartIdentify(int number) {
  if (number > 1) {
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.identify_number);
    byte[] chunk = bitmap.getNinePatchChunk();
    if (NinePatch.isNinePatchChunk(chunk)) {
      mNumberChartOverlay = new MyNinePatchDrawable(getResources(), bitmap, chunk, NinePatchChunk.deserialize(chunk).mPaddings, null, number + "");
    } else {
      mNumberChartOverlay = null;
    }
  } else {
    mNumberChartOverlay = null;
  }
  return this;
}

相关文章