내가 (컴파일되지 않은) 나인 패치 NinePatch 비트 맵에서 NinePatchDrawable을 만들 수있는 도구를 개발 Create a NinePatch/NinePatchDrawable in runtime
에 대한 내 대답을 참조하십시오. https://gist.github.com/knight9999/86bec38071a9e0a781ee을 참조하십시오.
이 방법은 NinePatchDrawable createNinePatchDrawable(Resources res, Bitmap bitmap)
입니다. 예를 들어
,이 경우
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
는 자산 디렉토리 아래
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);
.
서버가 완전한 9patch 그래픽을 생성한다고 말하지 않았습니까? 경계 (검은 색 테두리 등)를 포함합니다. 그걸 정확히 그렇게 부르려고 했나요? 비트 맵에 검은 색 테두리가없는 경우 서버 소프트웨어를 개선해야합니다 (사용자의 경우) –
검은 색 테두리가있는 비트 맵을 안드로이드 자체에서 생성합니다. 서버에서 오는 이미지는 경계선이 없습니다. 문제는 비트 맵 개체에서 9patch 청크 정보를 추정 할 수 없다는 것입니다. –
@Pedro Lopes : 그런 다음 어떻게 컨트롤 프레임의 픽셀을 흰색과 검정색으로 결정해야합니까? – CommonsWare