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


Java NinePatch.isNinePatchChunk方法代码示例

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


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

示例1: createImageBasedDrawable

import android.graphics.NinePatch; //导入方法依赖的package包/类
public static Drawable createImageBasedDrawable(byte[] byteArray, int bitmapDensityReference, boolean expectedNinePatch, Resources res)
{
    if (expectedNinePatch)
        return createNinePatchDrawable(byteArray,bitmapDensityReference,res);

    Bitmap bitmap = BitmapUtil.createBitmap(byteArray,bitmapDensityReference,res);

    byte[] chunk = bitmap.getNinePatchChunk();
    boolean result = NinePatch.isNinePatchChunk(chunk);
    if (result)
    {
        // Raro pero resulta que es un NinePatch (raro porque lo normal es que se especifique la extensión .9.png)
        return createNinePatchDrawable(bitmap,res);
    }
    else
    {
        return new BitmapDrawable(res, bitmap);
    }
}
 
开发者ID:jmarranz,项目名称:itsnat_droid,代码行数:20,代码来源:BitmapDrawableUtil.java

示例2: a

import android.graphics.NinePatch; //导入方法依赖的package包/类
private Drawable a(String str, Context context) {
    Drawable createFromStream;
    IOException e;
    try {
        InputStream open = context.getApplicationContext().getAssets().open(str);
        if (open == null) {
            return null;
        }
        if (str.endsWith(".9.png")) {
            Bitmap decodeStream = BitmapFactory.decodeStream(open);
            if (decodeStream == null) {
                return null;
            }
            byte[] ninePatchChunk = decodeStream.getNinePatchChunk();
            NinePatch.isNinePatchChunk(ninePatchChunk);
            return new NinePatchDrawable(decodeStream, ninePatchChunk, new Rect(), null);
        }
        createFromStream = Drawable.createFromStream(open, str);
        try {
            open.close();
            return createFromStream;
        } catch (IOException e2) {
            e = e2;
            e.printStackTrace();
            return createFromStream;
        }
    } catch (IOException e3) {
        IOException iOException = e3;
        createFromStream = null;
        e = iOException;
        e.printStackTrace();
        return createFromStream;
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:35,代码来源:AuthAgent.java

示例3: a

import android.graphics.NinePatch; //导入方法依赖的package包/类
private Drawable a(String str, Context context) {
    IOException e;
    Drawable createFromStream;
    try {
        InputStream open = context.getApplicationContext().getAssets().open(str);
        if (open == null) {
            return null;
        }
        if (str.endsWith(".9.png")) {
            Bitmap decodeStream = BitmapFactory.decodeStream(open);
            if (decodeStream == null) {
                return null;
            }
            byte[] ninePatchChunk = decodeStream.getNinePatchChunk();
            NinePatch.isNinePatchChunk(ninePatchChunk);
            return new NinePatchDrawable(decodeStream, ninePatchChunk, new Rect(), null);
        }
        createFromStream = Drawable.createFromStream(open, str);
        try {
            open.close();
            return createFromStream;
        } catch (IOException e2) {
            e = e2;
            e.printStackTrace();
            return createFromStream;
        }
    } catch (IOException e3) {
        IOException iOException = e3;
        createFromStream = null;
        e = iOException;
        e.printStackTrace();
        return createFromStream;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:35,代码来源:AuthAgent.java

示例4: createNinePatchDrawable

import android.graphics.NinePatch; //导入方法依赖的package包/类
public static NinePatchDrawable createNinePatchDrawable(Bitmap bitmap,Resources res)
{
    byte[] chunk = bitmap.getNinePatchChunk();
    boolean result = NinePatch.isNinePatchChunk(chunk);
    if (!result) throw new ItsNatDroidException("Expected a 9 patch png, put a valid 9 patch in /res/drawable folder, generate the .apk (/build/outputs/apk in Android Studio), decompress as a zip and copy the png file");

    return new NinePatchDrawable(res, bitmap, chunk, new Rect(), "XML 9 patch");
}
 
开发者ID:jmarranz,项目名称:itsnat_droid,代码行数:9,代码来源:BitmapDrawableUtil.java

示例5: createDrawablesByImages

import android.graphics.NinePatch; //导入方法依赖的package包/类
public static Drawable[] createDrawablesByImages(Resources res, Bitmap[] bitmaps) {
    Drawable[] drawables = new Drawable[bitmaps.length];
    for (int i = 0; i < bitmaps.length; i++) {
        byte[] chunk = bitmaps[i].getNinePatchChunk();
        boolean result = NinePatch.isNinePatchChunk(chunk);
        if (result) {
            drawables[i] = new NinePatchDrawable(res, bitmaps[i], chunk, new Rect(), null);
        } else {
            drawables[i] = new BitmapDrawable(res, bitmaps[i]);
        }
    }
    return drawables;
}
 
开发者ID:cdkd321,项目名称:pure,代码行数:14,代码来源:MaterialUtils.java

示例6: createFromResourceStream

import android.graphics.NinePatch; //导入方法依赖的package包/类
@Implementation // todo: this sucks, it's all just so we can detect 9-patches
public 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) {
      method("setNinePatchChunk").withParameterTypes(byte[].class).in(bm).invoke(new byte[0]);
    }

    byte[] np = bm.getNinePatchChunk();
    if (np == null || !NinePatch.isNinePatchChunk(np)) {
      np = null;
      pad = null;
    }
    int[] layoutBounds = method("getLayoutBounds").withReturnType(int[].class).in(bm).invoke();
    Rect layoutBoundsRect = null;
    if (layoutBounds != null) {
      layoutBoundsRect = new Rect(layoutBounds[0], layoutBounds[1],
          layoutBounds[2], layoutBounds[3]);
    }
    if (np != null) {
      // todo: wrong
      return new NinePatchDrawable(res, bm, np, pad, /*layoutBoundsRect,*/ srcName);
    }

    return new BitmapDrawable(res, bm);
  }
  return null;
}
 
开发者ID:qx,项目名称:FullRobolectricTestSample,代码行数:38,代码来源:ShadowDrawable.java

示例7: create

import android.graphics.NinePatch; //导入方法依赖的package包/类
/**
 * Attempts to decode 9-patch data from a {@link Bitmap}.
 * @param bitmap The {@link Bitmap} to check.
 * @return       An instance of {@link NinePatchData} representing the 9-patch information
 *               encoded in {@code bitmap} or {@code null} if the {@link Bitmap} wasn't a
 *               9-patch.
 */
public static NinePatchData create(Bitmap bitmap) {
    if (bitmap == null) return null;

    try {
        byte[] chunk = bitmap.getNinePatchChunk();
        if (chunk == null || !NinePatch.isNinePatchChunk(chunk)) return null;

        ByteBuffer buffer = ByteBuffer.wrap(chunk).order(ByteOrder.nativeOrder());

        // int8_t wasDeserialized
        if (buffer.get() == 0) return null;

        // int8_t numXDivs
        int numDivX = buffer.get();
        if (numDivX == 0 || (numDivX & 0x01) != 0) return null;

        // int8_t numYDivs
        int numDivY = buffer.get();
        if (numDivY == 0 || (numDivY & 0x01) != 0) return null;

        // int8_t numColors
        buffer.get();

        // uint32_t xDivsOffset
        buffer.getInt();

        // uint32_t yDivsOffset
        buffer.getInt();

        Rect padding = new Rect();

        // uint32_t paddingLeft
        padding.left = buffer.getInt();

        // uint32_t paddingRight
        padding.right = buffer.getInt();

        // uint32_t paddingTop
        padding.top = buffer.getInt();

        // uint32_t paddingBottom
        padding.bottom = buffer.getInt();

        // uint32_t colorsOffset
        buffer.getInt();

        // uint32_t uint32_t uint32_t ...
        int[] divX = new int[numDivX];
        for (int i = 0; i < numDivX; i++) divX[i] = buffer.getInt();

        // uint32_t uint32_t uint32_t ...
        int[] divY = new int[numDivY];
        for (int i = 0; i < numDivY; i++) divY[i] = buffer.getInt();

        return new NinePatchData(bitmap.getWidth(), bitmap.getHeight(), padding, divX, divY);
    } catch (BufferUnderflowException ex) {
        return null;
    }
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:67,代码来源:NinePatchData.java


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