I want to download a compiled Ninepatch file via network and set it into an ImageView. I already found the following solutions: Link, Link
My code is:
public class DownloadImageTask extends AsyncTask<URL, Void, Bitmap> {
private ImageView _imgView;
private Context _context;
public DownloadImageTask(Context context, ImageView imgView) {
_context = context;
_imgView = imgView;
}
@Override
protected Bitmap doInBackground(URL... params) {
Bitmap networkBitmap = null;
URL networkUrl = params[0];
try {
networkBitmap = BitmapFactory.decodeStream(networkUrl.openConnection().getInputStream());
}
catch (IOException e) {
e.printStackTrace();
}
return networkBitmap;
}
@Override
protected void onPostExecute(Bitmap result) {
byte[] chunk = result.getNinePatchChunk();
if (NinePatch.isNinePatchChunk(chunk)) {
NinePatchDrawable ninePatch = new NinePatchDrawable(_context.getResources(), result, chunk, new Rect(), null);
_imgView.setImageDrawable(ninePatch);
}
}
}
The Ninepatch that I load via network is compiled using aapt:
aapt.exe c -v -S in -C out
The Ninepatch is downloaded properly and onPostExecute() is getting called, I also get the chunck from the Bitmap and I'm able to create a NinePatchDrawable, but after setting it to the ImageView the Bitmap doesn't scale. What am I doing wrong?
Thanks in advance Dennis