Android的媒体传递到另一个数据活动 [英] android pass media data to another activity
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/11519691/passing-image-from-one-activity-another-activity\">Passing从一个活动另一个活动图片
我的应用程序使用以下逻辑:点击一个按钮在活动A开始的手机摄像头,照片/视频拍摄后(用户$ P $摄像机窗口pssed拯救)活动B开始。该活动B包含拍摄的照片/视频,并通过HTTP请求上传的媒体数据的可能性的preVIEW。我不知道如何通过拍摄的图像/视频到活动B ..在活动A,我不能StartActivityForResult启动相机,因为结果必须被传递到活动B.任何浩这样做的想法?
my app uses following logic: a button click in Activity A starts the phone camera, after a picture/video is taken (the user pressed "save" in the camera window) Activity B starts. That Activity B contains a preview of taken picture/video and the possibility to upload the media data via a http request. I'm not sure how to pass the taken Image/Video to Activity B.. I can't launch the camera with StartActivityForResult in Activity A since the result must be delivered to Activity B. Any ideas ho to do that?
推荐答案
有3解决方案来解决这个问题。
There are 3 Solutions to solve this issue.
1)首先转换图像成字节数组,然后传递到意向,并在接下来的活动获得捆绑字节数组转换为图像(位图),并设置成ImageView的。
1) First Convert Image into Byte Array and then pass into Intent and in next activity get byte array from Bundle and Convert into Image(Bitmap) and set into ImageView.
位图转换为字节数组: -
Convert Bitmap to Byte Array:-
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
传递字节数组到意图: -
Pass byte array into intent:-
Intent intent = new Intent(this, NextActivity.class);
intent.putExtra("picture", byteArray);
startActivity(intent);
从包中获取字节数组转换成位图图像: -
Get Byte Array from Bundle and Convert into Bitmap Image:-
Bundle extras = getIntent().getExtras();
byte[] byteArray = extras.getByteArray("picture");
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap(bmp);
2)先保存图像到SD卡,并设置该图像为ImageView的。下一活动
2) First Save image into SDCard and in next activity set this image into ImageView.
3)通入位图和意图,从包下一个活动得到的位图,但问题是,如果你的位图/图像大小是当时的形象是不是在明年的活动装载大了。
3) Pass Bitmap into Intent and get bitmap in next activity from bundle, but the problem is if your Bitmap/Image size is big at that time the image is not load in next activity.
这篇关于Android的媒体传递到另一个数据活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!