Image image = new Image (); Bitmap bitmap = Bitmap.CreateBitmap (200, 100, Bitmap.Config.Argb8888); Canvas canvas = new Canvas(bitmap); var paint = new Paint(); paint.Color = Android.Graphics.Color.Red; paint.SetStyle(Paint.Style.Fill); Rect rect = new Rect(0, 0, 200, 100); canvas.DrawRect(rect, paint);
Android.Widget.ImageView contains method SetImageBitmap.
What the best way to set Xamarin.Forms.Image from my bitmap?
The actual code that deals with the bitmap has to be in platform-specific code. You can write a DependencyService that gives you a Stream, and you can use that stream in the PCL. What you can't do in the PCL is actually draw the bitmap. That requires platform-specific APIs.
Answers
http://stackoverflow.com/questions/32092476/set-image-from-bitmap
Is this the best way?
That code is obviously platform-specific. This kind of thing can't be done in a PCL in a cross-platform way. You will have to use a DependencyService to implement this feature so that you can do the platform-specific code in the platform-specific project.
OK, but how I can set data in my image from the bitmap in cross-platform situation? I can't find this information
The actual code that deals with the bitmap has to be in platform-specific code. You can write a DependencyService that gives you a Stream, and you can use that stream in the PCL. What you can't do in the PCL is actually draw the bitmap. That requires platform-specific APIs.
OK. Thanks for the help!
Is there some code or example available as a working solution to this?? I have been search for a way to convert an Android Bitmap image to Xamarin.Forms ImageSource
This is coming late but can be useful to anyone who needs it now:
I created a Github gist that implements what @adamkemp described above