为什么我无法通过意图传递png?

时间:2015-03-23 10:48:05

标签: android android-intent android-fragments

我遇到了一些问题。我有一个jpg的有效bytearray和一个我将在下面证明的png,但由于某种原因,当我通过png意图时,我收到了一个奇怪的logcat(我还将在下面提供)并且我的屏幕是返回上一个活动。

好的,当两个片段的容器收到另一个片段列表中的项目被按下的消息时,调用下面的片段(下面的图片为ref)。当按下列表中的项目时,下面的这个片段将从容器中删除,并替换为新的片段并接收jsonInBytes& imageInBytes。

public class ImageAndSchematicPreviewFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_image_and_schematic_preview, container, false);

    Bundle extras = getArguments();

    // if there's passed arguments
    if (extras != null)
    {
       final byte[] jsonInBytes = extras.getByteArray("jsonInBytes");
       final byte[] imageInBytes = extras.getByteArray("imageInBytes");

        ByteArrayInputStream imageInputStream = new ByteArrayInputStream(imageInBytes);
        BufferedInputStream bufferedInputStream = new BufferedInputStream(imageInputStream);
        Bitmap imageForPreview = BitmapFactory.decodeStream(bufferedInputStream);

        ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
        imageView.setImageBitmap(imageForPreview);

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(jsonInBytes != null){
                    Intent intent = new Intent(v.getContext(), ImageAndSchematicSchematicOnlyView.class);
                    intent.putExtra("imageInBytes", imageInBytes);
                    intent.putExtra("jsonInBytes", jsonInBytes);
                    getActivity().startActivityForResult(intent, 0);
                } else {
                    Intent intent = new Intent(v.getContext(), ImageAndSchematicImageOnlyView.class);
                    intent.putExtra("imageInBytes", imageInBytes);
                    getActivity().startActivityForResult(intent, 0);
                }
            }
        });
    }
    return view;
    }
}

这是空白预览,当片段加载时没有包:

enter image description here

当我点击JPG时:

enter image description here

当我点击PNG时:

enter image description here

如您所见,在两种情况下都使用以下方式设置图像:

 ByteArrayInputStream imageInputStream = new ByteArrayInputStream(imageInBytes);
 BufferedInputStream bufferedInputStream = new    BufferedInputStream(imageInputStream);
 Bitmap imageForPreview = BitmapFactory.decodeStream(bufferedInputStream);

 ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
 imageView.setImageBitmap(imageForPreview);

这对我来说至少证明了字节数组是有效的。

是的,所以在onClick中我有' ImageAndSchematicSchematicOnlyView' &安培; ' ImageAndSchematicImageOnlyView'与他们的名字非常接近,有人可能认为这是信息的接收者,这是问题所在,我可以告诉你,这不是,并且为了证明这一点的意图,我将它们都设置为ImageAndSchematicImageOnlyView将它们带到可缩放,更大等图像视图。它有效,.jpg正在工作。但是,当我按下.png以放大它时,我会在log cat中得到它,并且我返回到之前的活动。

03-23 10:40:17.267    8380-8416/com.xxxx.xxxx E/Qmage﹕ onDecode : QmageDecodeFrame 20140421 Rev.6376
03-23 10:40:17.267    8380-8416/com.xxxx.xxxx E/Qmage﹕ This is decoding
03-23 10:40:17.267    8380-8416/com.xxxx.xxxx E/Qmage﹕ decoding stream->hasLength()
03-23 10:40:17.267    8380-8416/com.xxxx.xxxx E/Qmage﹕ onDecode : QmageDecParseHeader call : QM
03-23 10:40:17.267    8380-8416/com.xxxx.xxxx E/Qmage﹕ Qmage parsing for decoding ok
03-23 10:40:17.267    8380-8416/com.xxxx.xxxx E/Qmage﹕ onDecode :  QmageHeader.NinePatched 0
03-23 10:40:17.267    8380-8416/com.xxxx.xxxx E/Qmage﹕ onDecode : QmageHeader Height() 12 Width() : 522 sampleSize : 1
03-23 10:40:17.267    8380-8416/com.xxxx.xxxx E/Qmage﹕ Qmage Make Color table
03-23 10:40:17.267    8380-8416/com.xxxx.xxxx E/Qmage﹕ SkBitmap::kIndex8_Config == config && 1 == sampleSize
03-23 10:40:17.267    8380-8416/com.xxxx.xxxx E/Qmage﹕ onDecode : return true QM
03-23 10:40:17.267    8380-8416/com.xxxx.xxxx E/Qmage﹕ onDecode : QmageDecodeFrame 20140421 Rev.6376
03-23 10:40:17.267    8380-8416/com.xxxx.xxxx E/Qmage﹕ This is decoding
03-23 10:40:17.267    8380-8416/com.xxxx.xxxx E/Qmage﹕ decoding stream->hasLength()
03-23 10:40:17.267    8380-8416/com.xxxx.xxxx E/Qmage﹕ onDecode : QmageDecParseHeader call : QM
03-23 10:40:17.267    8380-8416/com.xxxx.xxxx E/Qmage﹕ Qmage parsing for decoding ok
03-23 10:40:17.267    8380-8416/com.xxxx.xxxx E/Qmage﹕ onDecode :  QmageHeader.NinePatched 0
03-23 10:40:17.267    8380-8416/com.xxxx.xxxx E/Qmage﹕ onDecode : QmageHeader Height() 135 Width() : 522 sampleSize : 1
03-23 10:40:17.267    8380-8416/com.xxxx.xxxx E/Qmage﹕ normal image decoding
03-23 10:40:17.267    8380-8416/com.xxxx.xxxx E/Qmage﹕ onDecode : QmageDecodeFrame call : QM
03-23 10:40:17.277    8398-8417/com.xxxx.xxxx E/Qmage﹕ onDecode : QmageDecodeFrame 20140421 Rev.6376
03-23 10:40:17.277    8398-8417/com.xxxx.xxxx E/Qmage﹕ This is decoding
03-23 10:40:17.277    8398-8417/com.xxxx.xxxx E/Qmage﹕ decoding stream->hasLength()
03-23 10:40:17.277    8398-8417/com.xxxx.xxxx E/Qmage﹕ onDecode : QmageDecParseHeader call : QM
03-23 10:40:17.277    8398-8417/com.xxxx.xxxx E/Qmage﹕ Qmage parsing for decoding ok
03-23 10:40:17.277    8398-8417/com.xxxx.xxxx E/Qmage﹕ onDecode :  QmageHeader.NinePatched 0
03-23 10:40:17.277    8398-8417/com.xxxx.xxxx E/Qmage﹕ onDecode : QmageHeader Height() 135 Width() : 522 sampleSize : 1
03-23 10:40:17.277    8398-8417/com.xxxx.xxxx E/Qmage﹕ normal image decoding
03-23 10:40:17.277    8398-8417/com.xxxx.xxxx E/Qmage﹕ onDecode : QmageDecodeFrame call : QM
03-23 10:40:17.287    8398-8420/com.xxxx.xxxx E/Qmage﹕ onDecode : QmageDecodeFrame 20140421 Rev.6376
03-23 10:40:17.287    8398-8420/com.xxxx.xxxx E/Qmage﹕ This is decoding
03-23 10:40:17.297    8398-8420/com.xxxx.xxxx E/Qmage﹕ decoding stream->hasLength()
03-23 10:40:17.297    8398-8420/com.xxxx.xxxx E/Qmage﹕ onDecode : QmageDecParseHeader call : QM
03-23 10:40:17.297    8398-8420/com.xxxx.xxxx E/Qmage﹕ Qmage parsing for decoding ok
03-23 10:40:17.297    8398-8420/com.xxxx.xxxx E/Qmage﹕ onDecode :  QmageHeader.NinePatched 0
03-23 10:40:17.297    8398-8420/com.xxxx.xxxx E/Qmage﹕ onDecode : QmageHeader Height() 12 Width() : 522 sampleSize : 1
03-23 10:40:17.297    8398-8420/com.xxxx.xxxx E/Qmage﹕ Qmage Make Color table
03-23 10:40:17.297    8398-8420/com.xxxx.xxxx E/Qmage﹕ SkBitmap::kIndex8_Config == config && 1 == sampleSize
03-23 10:40:17.297    8398-8420/com.xxxx.xxxx E/Qmage﹕ onDecode : return true QM
03-23 10:40:17.307    8398-8417/com.xxxx.xxxx E/Qmage﹕ onDecode : return true QM
03-23 10:40:17.337    8398-8398/com.xxxx.xxxx I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
03-23 10:40:17.337    8398-8398/com.xxxx.xxxx W/dalvikvm﹕ VFY: unable to resolve virtual method 11634: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
03-23 10:40:17.337    8398-8398/com.xxxx.xxxx D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
03-23 10:40:17.337    8398-8398/com.xxxx.xxxx I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
03-23 10:40:17.337    8398-8398/com.xxxx.xxxx W/dalvikvm﹕ VFY: unable to resolve virtual method 11640: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
03-23 10:40:17.337    8398-8398/com.xxxx.xxxx D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
03-23 10:40:17.337    8398-8398/com.xxxx.xxxx I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
03-23 10:40:17.337    8398-8398/com.xxxx.xxxx W/dalvikvm﹕ VFY: unable to resolve virtual method 9308: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
03-23 10:40:17.337    8398-8398/com.xxxx.xxxx D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
03-23 10:40:17.347    8398-8398/com.xxxx.xxxx I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
03-23 10:40:17.347    8398-8398/com.xxxx.xxxx W/dalvikvm﹕ VFY: unable to resolve virtual method 495: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
03-23 10:40:17.347    8398-8398/com.xxxx.xxxx D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
03-23 10:40:17.347    8398-8398/com.xxxx.xxxx I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
03-23 10:40:17.347    8398-8398/com.xxxx.xxxx W/dalvikvm﹕ VFY: unable to resolve virtual method 517: Landroid/content/res/TypedArray;.getType (I)I
03-23 10:40:17.347    8398-8398/com.xxxx.xxxx D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
03-23 10:40:17.377    8380-8416/com.xxxx.xxxx E/Qmage﹕ onDecode : return true QM
03-23 10:40:17.407    8398-8398/com.xxxx.xxxx I/System.out﹕ show called
03-23 10:40:17.407    8398-8398/com.xxxx.xxxx E/Qmage﹕ onDecode : QmageDecodeFrame 20140421 Rev.6376
03-23 10:40:17.407    8398-8398/com.xxxx.xxxx E/Qmage﹕ This is decoding
03-23 10:40:17.407    8398-8398/com.xxxx.xxxx E/Qmage﹕ decoding stream->hasLength()
03-23 10:40:17.407    8398-8398/com.xxxx.xxxx E/Qmage﹕ onDecode : QmageDecParseHeader call : QM
03-23 10:40:17.417    8398-8398/com.xxxx.xxxx E/Qmage﹕ Qmage parsing for decoding ok
03-23 10:40:17.417    8398-8398/com.xxxx.xxxx E/Qmage﹕ onDecode :  QmageHeader.NinePatched 0
03-23 10:40:17.417    8398-8398/com.xxxx.xxxx E/Qmage﹕ onDecode : QmageHeader Height() 48 Width() : 48 sampleSize : 1
03-23 10:40:17.417    8398-8398/com.xxxx.xxxx E/Qmage﹕ Qmage Make Color table
03-23 10:40:17.417    8398-8398/com.xxxx.xxxx E/Qmage﹕ SkBitmap::kIndex8_Config == config && 1 == sampleSize
03-23 10:40:17.417    8398-8398/com.xxxx.xxxx E/Qmage﹕ onDecode : return true QM
03-23 10:40:17.417    8398-8398/com.xxxx.xxxx E/Qmage﹕ onDecode : QmageDecodeFrame 20140421 Rev.6376
03-23 10:40:17.417    8398-8398/com.xxxx.xxxx E/Qmage﹕ This is decoding
03-23 10:40:17.417    8398-8398/com.xxxx.xxxx E/Qmage﹕ decoding stream->hasLength()
03-23 10:40:17.417    8398-8398/com.xxxx.xxxx E/Qmage﹕ onDecode : QmageDecParseHeader call : QM
03-23 10:40:17.417    8398-8398/com.xxxx.xxxx E/Qmage﹕ Qmage parsing for decoding ok
03-23 10:40:17.417    8398-8398/com.xxxx.xxxx E/Qmage﹕ onDecode :  QmageHeader.NinePatched 0
03-23 10:40:17.417    8398-8398/com.xxxx.xxxx E/Qmage﹕ onDecode : QmageHeader Height() 48 Width() : 48 sampleSize : 1
03-23 10:40:17.417    8398-8398/com.xxxx.xxxx E/Qmage﹕ normal image decoding
03-23 10:40:17.417    8398-8398/com.xxxx.xxxx E/Qmage﹕ onDecode : QmageDecodeFrame call : QM
03-23 10:40:17.417    8398-8398/com.xxxx.xxxx E/Qmage﹕ onDecode : return true QM
03-23 10:40:17.507    8398-8398/com.xxxx.xxxx D/GC﹕ <tid=8398> OES20 ===> GC Version   : GC Ver rls_pxa988_KK44_GC13.20
03-23 10:40:17.527    8398-8398/com.xxxx.xxxx D/OpenGLRenderer﹕ Enabling debug mode 0

FYI。成功转换到.jpeg放大视图时不会发生这种情况。

这并不是什么大不了的事,因为我们制作的软件输出到这个软件所以理论上可以有一个png转换器,但我不觉得它应该是必要的。任何帮助将不胜感激,欢迎任何问题。感谢

0 个答案:

没有答案