Reputation:
I have activity when I make photo by button
Also I show this photo in Layout.
I need to display it in another activity
Here is code
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
Uri contentUri = Uri.FromFile(App._file);
mediaScanIntent.SetData(contentUri);
SendBroadcast(mediaScanIntent);
int height = Resources.DisplayMetrics.HeightPixels;
int width = _imageView.Height;
App.bitmap = App._file.Path.LoadAndResizeBitmap(width, height);
if (App.bitmap != null)
{
_imageView.SetImageBitmap(App.bitmap);
App.bitmap = null;
}
// Dispose of the Java side bitmap.
GC.Collect();
}
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
surname_from_activity = Intent.GetStringExtra("Surname");
inn_from_activity = Intent.GetStringExtra("INN");
System.Console.WriteLine(surname_from_activity);
SetContentView(Resource.Layout.qrandphotolayout);
ImageView qr = FindViewById<ImageView>(Resource.Id.qrimage);
if (IsThereAnAppToTakePictures())
{
CreateDirectoryForPictures();
Button button = FindViewById<Button>(Resource.Id.photobutton);
_imageView = FindViewById<ImageView>(Resource.Id.photo);
button.Click += TakeAPicture;
}
Button next = FindViewById<Button>(Resource.Id.sync);
next.Click += delegate {
var intent = new Intent(this, typeof(Badge));
intent.PutExtra("Surname", surname_from_activity);
intent.PutExtra("INN", inn_from_activity);
StartActivity(intent);
};
}
private void CreateDirectoryForPictures()
{
App._dir = new File(
Environment.GetExternalStoragePublicDirectory(
Environment.DirectoryPictures), "CameraAppDemo");
if (!App._dir.Exists())
{
App._dir.Mkdirs();
}
}
private bool IsThereAnAppToTakePictures()
{
Intent intent = new Intent(MediaStore.ActionImageCapture);
IList<ResolveInfo> availableActivities =
PackageManager.QueryIntentActivities(intent, PackageInfoFlags.MatchDefaultOnly);
return availableActivities != null && availableActivities.Count > 0;
}
private void TakeAPicture(object sender, EventArgs eventArgs)
{
Intent intent = new Intent(MediaStore.ActionImageCapture);
App._file = new File(App._dir, String.Format(surname_from_activity + inn_from_activity, Guid.NewGuid()));
intent.PutExtra(MediaStore.ExtraOutput, Uri.FromFile(App._file));
StartActivityForResult(intent,0);
}
}
I need to pass image to another activity and show it in ImageView
How I can do this?
Thank's so much
Upvotes: 1
Views: 542
Reputation: 17131
Sender Activity
Intent intent = new Intent(this, TwoActivity.class);
Bitmap bitmap;
ByteArrayOutputStream bs = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 50, bs);
i.putExtra("byte", bs.toByteArray());
startActivity(i);
Receiver Activity
if(getIntent().hasExtra("byte")) {
ImageView imv= new ImageView(this);
Bitmap bitmap = BitmapFactory.decodeByteArray(
getIntent().getByteArrayExtra("byte"),0,getIntent().getByteArrayExtra("byte").length);
imv.setImageBitmap(bitmap);
}
Upvotes: 1
Reputation: 419
Possibilities:
You can create static atribute in ActivityB, and before call ActivityB from ActivityA you should pass your imageView/URI to atribute created.
You can pass save image in folder temp (ActivityB), and get this image in ActivityB.
You pass images with intent/bundle is it's too heavy
Upvotes: 1