Tagged: drawing, image, protobuf-net, serialization
- This topic has 5 replies, 2 voices, and was last updated 11 years, 4 months ago by Anonymous.
-
AuthorPosts
-
August 2, 2013 at 19:04 #1009AnonymousInactive
I’m on Android Xamarin. Which version and dll type I need to add to xamarin references ?
I donwloaded protobuf-net from google repo, which I have to include ?
Thanks
MaxAugust 2, 2013 at 21:27 #1010AnonymousInactiveSOlved this one I got another problem.
I need to serialize pictures, videos, audio files.
I see the protobuf example. It use Systems.Drawing library which is ’empty’ in xamarin android.
How do I have to do in xamarin ? Which are libraries I need to import to serializa (like in your tutorial) images, audio and video ?
Thanks in advance.
MaxAugust 4, 2013 at 18:44 #1011AnonymousInactiveHeya Eudosia, I couldn’t give you any more specific advice other than what is already presented here.
August 5, 2013 at 22:17 #1013AnonymousInactiveI used to start your sample and I have modified the ImageWrapper class to suite the bitmap class:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Android.App; using Android.Content; using Android.OS; using Android.Runtime; using Android.Graphics; using NetworkCommsDotNet; using System.IO; using DPSBase; using ProtoBuf; namespace Discovery_Service { [ProtoContract] public class ImageWrapper { /// <summary> /// Private store of the image data as a byte[] /// This will be populated automatically when the object is serialised /// </summary> [ProtoMember(1)] private byte[] _imageData; /// <summary> /// The image name /// </summary> [ProtoMember(2)] public string ImageName { get; set; } /// <summary> /// The public accessor for the image. This will be populated /// automatically when the object is deserialised. /// </summary> public Bitmap Image { get; set; } /// <summary> /// Private parameterless constructor required for deserialisation /// </summary> private ImageWrapper() { } /// <summary> /// Create a new ImageWrapper /// </summary> /// <param name="imageName"></param> /// <param name="image"></param> public ImageWrapper(string imageName, Bitmap _image) { this.ImageName = imageName; this.Image = _image; } /// <summary> /// Before serialising this object convert the image into binary data /// </summary> [ProtoBeforeSerialization] private void Serialize() { if (Image != null) { //We need to decide how to convert our image to its raw binary form here byte[] bitmapData; using (var stream = new MemoryStream()) { Image.Compress (Bitmap.CompressFormat.Png, 0, stream); bitmapData = stream.ToArray(); } } } /// <summary> /// When deserialising the object convert the binary data back into an image object /// </summary> [ProtoAfterDeserialization] private void Deserialize() { //If we added custom data processes we have the perform the reverse operations here before //trying to recreate the image object //e.g. DPSManager.GetDataProcessor<LZMACompressor>() Image = BitmapFactory.DecodeByteArray(_imageData , 0, _imageData.Length); _imageData = null; } } }
But I got several errors from the class. Do you can see any evidence ?
Thanks
MaxAugust 6, 2013 at 09:35 #1014AnonymousInactiveWhat are the errors?
August 6, 2013 at 17:48 #1015AnonymousInactiveI receive this from the application output and object is not sent:
[mono] Stacktrace:
[mono]
[mono] at (wrapper delegate-invoke) <Module>.invoke_bool__this___intptr_intptr_intptr_JValue[] (intptr,intptr,intptr,Android.Runtime.JValue[]) <0xffffffff>
[mono] at Android.Runtime.JNIEnv.CallBooleanMethod (intptr,intptr,Android.Runtime.JValue[]) <0x00053>
[mono] at Android.Graphics.Bitmap.Compress (Android.Graphics.Bitmap/CompressFormat,int,System.IO.Stream) <0x001eb>
[mono] at Discovery_Service.ImageWrapper.Serialize () <0x0006b>
[mono] at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) <0xffffffff>
[mono] at System.Reflection.MonoMethod.Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <0x00183>
[mono] at System.Reflection.MethodBase.Invoke (object,object[]) <0x00047>
[mono] at ProtoBuf.Serializers.TypeSerializer.InvokeCallback (System.Reflection.MethodInfo,object,ProtoBuf.SerializationContext) <0x00157>
[mono] at ProtoBuf.Serializers.TypeSerializer.Callback (object,ProtoBuf.Meta.TypeModel/CallbackType,ProtoBuf.SerializationContext) <0x0004b>
[mono] at ProtoBuf.Serializers.TypeSerializer.Write (object,ProtoBuf.ProtoWriter) <0x0003b>
[mono] at ProtoBuf.Meta.RuntimeTypeModel.Serialize (int,object,ProtoBuf.ProtoWriter) <0x00087>
[mono] at ProtoBuf.Meta.TypeModel.SerializeCore (ProtoBuf.ProtoWriter,object) <0x00067>
[mono] at ProtoBuf.Meta.TypeModel.Serialize (System.IO.Stream,object,ProtoBuf.SerializationContext) <0x00073>
[mono] at ProtoBuf.Meta.TypeModel.Serialize (System.IO.Stream,object) <0x00027>
[mono] at ProtoBuf.Serializer/NonGeneric.Serialize (System.IO.Stream,object) <0x00033>
[mono] at DPSBase.ProtobufSerializer.SerialiseDataObjectInt (System.IO.Stream,object,System.Collections.Generic.Dictionary`2<string, string>) <0x00027>
[mono] at DPSBase.DataSerializer.SerialiseGeneralObject<T> (T,System.Collections.Generic.List1<DPSBase.DataProcessor>,System.Collections.Generic.Dictionary
2<string, string>) <0x0006f>
[mono] at DPSBase.DataSerializer.SerialiseDataObject<T> (T,System.Collections.Generic.List1<DPSBase.DataProcessor>,System.Collections.Generic.Dictionary
2<string, string>) <0x000ff>
[mono] at NetworkCommsDotNet.Packet.Constructor (string,string,object,NetworkCommsDotNet.SendReceiveOptions) <0x0015b>
[mono] at NetworkCommsDotNet.Packet..ctor (string,object,NetworkCommsDotNet.SendReceiveOptions) <0x00037>
[mono] at NetworkCommsDotNet.Connection.SendObject (string,object,NetworkCommsDotNet.SendReceiveOptions) <0x0004b>
[mono] at NetworkCommsDotNet.Connection.SendObject (string,object) <0x00027>
[mono] at NetworkCommsDotNet.NetworkComms.SendObject (string,string,int,object) <0x00057>
[mono] at Discovery_Service.MainActivity.OnActivityResult (int,Android.App.Result,Android.Content.Intent) <0x001b3>
[mono] at Android.App.Activity.n_OnActivityResult_IILandroid_content_Intent_ (intptr,intptr,int,int,intptr) <0x00077>
[mono] at (wrapper dynamic-method) object.289cae26-1434-4d67-9bd5-8ab6ccb6ee0a (intptr,intptr,int,int,intptr) <0x0005b>
[mono] at (wrapper native-to-managed) object.289cae26-1434-4d67-9bd5-8ab6ccb6ee0a (intptr,intptr,int,int,intptr) <0xffffffff>
Exception has been thrown by the target of an invocation.
[ActivityNative] send ACTIVITY_IDLE_TRANSACTION -
AuthorPosts
- You must be logged in to reply to this topic.