Android附加2位图

时间:2014-07-15 23:11:45

标签: android layout bitmap

今天我有一个问题,我试图以低效的方式解决(弹出一个带有2个图像的对话框并创建位图)它仍然会爆炸......所以我现在绝望了。

我见过很多屏蔽线程,但没有附加屏蔽线程。

有位图A,现在有位图B,我想附加位图A和B来得到类似的东西 将灰色区域视为位图本身。

AAAA
AAAA
AAAA

+

BBBB
BBBB
BBBB

=

AAAA
AAAA
AAAA
BBBB
BBBB
BBBB

正如我之前解释的那样,我尝试了一个包含2个图像视图的布局,以及此代码...

public static Bitmap concatenarImagenes(Context oContexto, Bitmap A, Bitmap B)
    {
        if(A==null && B==null) return null;
        if(A==null && B!=null) return B;
        if(A!=null && B==null) return A;

        Dialog oDialogoTicket = new Dialog(oContexto, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
        oDialogoTicket.show();        
        oDialogoTicket.setContentView(R.layout.zutil_concatenate_pictures);

        ((ImageView) oDialogoTicket.findViewById(R.id.img01)).setImageBitmap(A);
        ((ImageView) oDialogoTicket.findViewById(R.id.img02)).setImageBitmap(B);

        ScrollView view = (ScrollView)oDialogoTicket.findViewById(R.id.content);

        view.setDrawingCacheEnabled(true);
        view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 
                MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
        view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); 
        view.buildDrawingCache(true);
        Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache(true));
        view.setDrawingCacheEnabled(false); // clear drawing cache
        oDialogoTicket.dismiss();
        return bitmap;
    }

我创建的照片具有与此类似的功能,但这会在此行爆炸

Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache(true));

出现此错误:

07-15 18:08:52.859: E/AndroidRuntime(8102): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1234, result=-1, data=Intent { (has extras) }} to activity {...VentaSingleActivity}: java.lang.NullPointerException
07-15 18:08:52.859: E/AndroidRuntime(8102):     at android.app.ActivityThread.deliverResults(ActivityThread.java:3154)
07-15 18:08:52.859: E/AndroidRuntime(8102):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:3197)
07-15 18:08:52.859: E/AndroidRuntime(8102):     at android.app.ActivityThread.access$1100(ActivityThread.java:135)
07-15 18:08:52.859: E/AndroidRuntime(8102):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
07-15 18:08:52.859: E/AndroidRuntime(8102):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-15 18:08:52.859: E/AndroidRuntime(8102):     at android.os.Looper.loop(Looper.java:154)
07-15 18:08:52.859: E/AndroidRuntime(8102):     at android.app.ActivityThread.main(ActivityThread.java:4643)
07-15 18:08:52.859: E/AndroidRuntime(8102):     at java.lang.reflect.Method.invokeNative(Native Method)
07-15 18:08:52.859: E/AndroidRuntime(8102):     at java.lang.reflect.Method.invoke(Method.java:511)
07-15 18:08:52.859: E/AndroidRuntime(8102):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
07-15 18:08:52.859: E/AndroidRuntime(8102):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
07-15 18:08:52.859: E/AndroidRuntime(8102):     at dalvik.system.NativeStart.main(Native Method)
07-15 18:08:52.859: E/AndroidRuntime(8102): Caused by: java.lang.NullPointerException
07-15 18:08:52.859: E/AndroidRuntime(8102):     at android.graphics.Bitmap.createBitmap(Bitmap.java:455)
07-15 18:08:52.859: E/AndroidRuntime(8102):     at ...helper.Ticket.concatenarImagenes(Ticket.java:47)
07-15 18:08:52.859: E/AndroidRuntime(8102):     at ...VentaSingleActivity.onActivityResult(VentaSingleActivity.java:114)
07-15 18:08:52.859: E/AndroidRuntime(8102):     at android.app.Activity.dispatchActivityResult(Activity.java:4663)
07-15 18:08:52.859: E/AndroidRuntime(8102):     at android.app.ActivityThread.deliverResults(ActivityThread.java:3150)
07-15 18:08:52.859: E/AndroidRuntime(8102):     ... 11 more

最后,我的代码出了什么问题,第二个问题是,这个问题的正确解决方案是什么?

提前谢谢你:)

0 个答案:

没有答案