本文介绍了创建bitamp九宫 - 并获得新的调整位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我特林从网上下载图像,将其转换为ninepatch格式,我该如何选择拉伸像素超出范围为这个线程。

I'm tring to download an image from the net, and to convert it to ninepatch format, how I select the stretchable pixels is out of scope for this thread.

我试图使用但我无法得到它的工作。

I'm trying to use gist solution but I couldn't get it to work.

这是源$ C ​​$ C:

This is the source code:

NinePatchDrawable np = createNinePathWithCapInsets(res, bitmap, top,left, bitmap.getWidth() - right, bitmap.getHeight() - bottom, null);

和得到的结果位图:

Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(outputBitmap);
//np.setBounds(0, 0, width, height);
np.draw(canvas);
canvas.drawBitmap(outputBitmap, width, height, new Paint());

返回的位图不包含源位图,看起来就像4分割(SEG RECT')

The returned bitmap doesn't contain the source bitmap and looks just like 4 segmentations(rect seg').

我能找到的任何其他才达到这一目标,甚至没有使用OpenGL

I could find any other to achive that goal, even not using OpenGL

所得图像是:

推荐答案

试试这个:

public static byte[] getChunk(int xs, int xe, int ys, int ye) {
    ByteBuffer b = ByteBuffer.allocate(84).order(ByteOrder.nativeOrder());
    b.put((byte) 1); // wasDeserialized
    b.put((byte) 2); // numXDivs
    b.put((byte) 2); // numYDivs
    b.put((byte) 9); // numColors
    b.putInt(0);     // UNKNOWN
    b.putInt(0);     // UNKNOWN
    b.putInt(0);     // paddingLeft
    b.putInt(0);     // paddingRight
    b.putInt(0);     // paddingTop
    b.putInt(0);     // paddingBottom
    b.putInt(0);     // UNKNOWN
    b.putInt(xs);    // segX start
    b.putInt(xe);    // segX end
    b.putInt(ys);    // segY start
    b.putInt(ye);    // segY end
    for (int i = 0; i < 9; i++) {
        b.putInt(1);     // NO_COLOR
    }
    return b.array();
}

您可以在NinePatchDrawable构造函数中使用它(位图,字节[],矩形,字符串)

you can use it in NinePatchDrawable constructor (Bitmap, byte[], Rect, String)

这篇关于创建bitamp九宫 - 并获得新的调整位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 21:57