2013-07-24 53 views
0

我的資源中有九個可修補的補丁。我必須在運行時更改一些顏色,將NinePatchDrawable保存爲位圖並更改像素,然後再次將此位圖保存爲NinePatchDrawable。NinePatchDrawable - >位圖 - > NinePatchDrawable

我的代碼:

Bitmap src = BitmapFactory.decodeResource(res, resId); 
Bitmap bitmap = src.copy(Bitmap.Config.ARGB_8888, true); 
//... pixels operation 

byte[] chunk = bitmap.getNinePatchChunk(); 
return new NinePatchDrawable(res, bitmap, chunk, new Rect(), null); 

應用崩潰的 '新NinePatchDrawable' 與以下內容:

"Signal Catcher" daemon prio=5 tid=4 RUNNABLE 
    | group="system" sCount=0 dsCount=0 obj=0x40517900 self=0xe89f0 
    | sysTid=21817 nice=0 sched=0/0 cgrp=[no-cpu-subsys] handle=473072 
    | schedstat=(1007082 4364014 23) 
    at dalvik.system.NativeStart.run(Native Method) 
[<c0294308>] save_stack_trace_tsk+0x0/0x90 
[<c03b5568>] proc_pid_stack+0xf8/0x144 
[<c03b68cc>] proc_single_show+0x48/0x84 
[<c038aef8>] seq_read+0x26c/0x4e4 
[<c0371ab8>] vfs_read+0xa8/0x150 
[<c0371c0c>] sys_read+0x3c/0x68 
[<c0290740>] ret_fast_syscall+0x0/0x30 
    [<ffffffff>] 0xffffffff 
    ------------------------------ 
"main" prio=5 tid=1 RUNNABLE 
    | group="main" sCount=1 dsCount=0 obj=0x400281f8  self=0xd190 
    | sysTid=21814 nice=0 sched=0/0 cgrp=[no-cpu-subsys]  handle=-1345002240 
    | schedstat=(1833007809 896209717 2404) 
    at  android.graphics.NinePatch.validateNinePatchChunk(Native Method) 
    at android.graphics.NinePatch.<init>(NinePatch.java:50) 
    at android.graphics.drawable.NinePatchDrawable.<init>(NinePatchDrawable.java:73) 

我到底做錯了什麼?

回答

1

當我使用從源位圖,而不是新的位圖,它的工作9個補丁塊:

所以不是:

byte[] chunk = bitmap.getNinePatchChunk(); 

應該是:

byte[] chunk = src.getNinePatchChunk(); 
相關問題