は、私は(コンパイルされていない)NinePatchビットマップからNinePatchDrawableを作成するためのツールを開発Create a NinePatch/NinePatchDrawable in runtime
のための私の答えを参照してください。 https://gist.github.com/knight9999/86bec38071a9e0a781eeを参照してください。
メソッド NinePatchDrawable createNinePatchDrawable(Resources res, Bitmap bitmap)
が役に立ちます。この場合
例えば、
ImageView imageView = (ImageView) findViewById(R.id.imageview);
Bitmap bitmap = loadBitmapAsset("my_nine_patch_image.9.png", this);
NinePatchDrawable drawable = NinePatchBitmapFactory.createNinePatchDrawable(getResources(), bitmap);
imageView.setBackground(drawable);
ここ
public static final Bitmap loadBitmapAsset(String fileName,Context context) {
final AssetManager assetManager = context.getAssets();
BufferedInputStream bis = null;
try {
bis = new BufferedInputStream(assetManager.open(fileName));
return BitmapFactory.decodeStream(bis);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
bis.close();
} catch (Exception e) {
}
}
return null;
}
、my_nine_patch_image.9.png
資産ディレクトリの下にあります。
サーバーが完全な9patchグラフィックを生成しているとは言いませんか?境界線を含む(黒い枠線など)。あなたはそれをちょうどそう呼んでみましたか?ビットマップに黒い罫線がない場合は、サーバーソフトウェアを改善する必要があります(ケースの場合) –
黒い枠線でビットマップを生成しています。サーバーからの画像には境界線がありません。 問題は、Bitmapオブジェクトから9patchチャンク情報を外挿することができないことです。 –
@ Pedro Lopes:次に、コントロールフレーム内のどのピクセルを白と白のどちらにするかを決定しますか? – CommonsWare