Hi,
I have the need to transform a EmbeddedResourceImageSource of the FFImageLoading library into either a Bitmap (Android) or a byte array.
Before I used a StreamImageSource and was able to do it like this:
Bitmap bit = await new StreamImagesourceHandler().LoadImageAsync(person.Photo,MainActivity.Instance);
byte[] photoBytes;
using(var stream = new MemoryStream())
{
bit.Compress(Bitmap.CompressFormat.Png, 100, stream);
photoBytes = stream.ToArray();
List<IParcelable> data = new List<IParcelable>();
ContentValues row = new ContentValues();
row.Put(ContactsContract.Data.InterfaceConsts.Mimetype, ContactsContract.CommonDataKinds.Photo.ContentItemType);
row.Put(ContactsContract.CommonDataKinds.Photo.PhotoColumnId, photoBytes);
data.Add(row);
contactIntent.PutParcelableArrayListExtra(ContactsContract.Intents.Insert.Data, data);
}
But of course StreamImagesourceHandler is not working anymore for EmbeddedResourceImageSource.
Also I tried loading the BitmapDrawable by
BitmapDrawable dr = await ImageService.Instance.LoadEmbeddedResource((person.Photo as EmbeddedResourceImageSource).Uri.ToString()).AsBitmapDrawableAsync();
but then it crashes with System.ArgumentNullException with Message Value cannot be null.
Parameter name: Stream and Decoded
StackTrace:
at FFImageLoading.DataResolvers.WrappedDataResolver.Resolve (System.String identifier, FFImageLoading.Work.TaskParameter parameters, System.Threading.CancellationToken token) [0x000c1] in C:\projects\ffimageloading\source\FFImageLoading.Common\DataResolvers\WrappedDataResolver.cs:24 \n at FFImageLoading.Work.ImageLoaderTask`3[TDecoderContainer,TImageContainer,TImageView].RunAsync () [0x00300] in C:\projects\ffimageloading\source\FFImageLoading.Common\Work\ImageLoaderTask.cs:618 \n at F62App.Droid.DependencyServices.ContactHelper.AddContact (F62App.Models.PeopleFinder.Person person) [0x0012f] in /Users/ddz/Develop/XamarinWorkspace/F62App/F62App.Android/DependencyServices/ContactHelper.cs:43 \n at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__6_0 (System.Object state) [0x00000] in <3a61d48d66dd458fa0b64990b6c8f8cc>:0 \n at Android.App.SyncContext+<>c__DisplayClass2_0.b__0 () [0x00000] in :0 \n at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in :0 \n at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in :0 \n at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.56(intptr,intptr)"
Does anyone know how I can get the Bitmap and or the byte[], I guess I'm just missing something.
Thx!