示例#1
0
        public AndroidBitmapDescriptor ToNative(BitmapDescriptor descriptor)
        {
            switch (descriptor.Type)
            {
            case BitmapDescriptorType.Default:
                return(AndroidBitmapDescriptorFactory.DefaultMarker((float)((descriptor.Color.Hue * 360f) % 360f)));

            case BitmapDescriptorType.Bundle:
                return(AndroidBitmapDescriptorFactory.FromAsset(descriptor.BundleName));

            case BitmapDescriptorType.Resource:
                var d = Xamarin.Forms.Platform.Android.ResourceManager.GetDrawableByName(descriptor.BundleName);
                if (d > 0)
                {
                    return(AndroidBitmapDescriptorFactory.FromResource(d));
                }
                else
                {
                    return(AndroidBitmapDescriptorFactory.DefaultMarker());
                }

            case BitmapDescriptorType.Stream:
                if (descriptor.Stream.CanSeek && descriptor.Stream.Position > 0)
                {
                    descriptor.Stream.Position = 0;
                }
                return(AndroidBitmapDescriptorFactory.FromBitmap(BitmapFactory.DecodeStream(descriptor.Stream)));

            case BitmapDescriptorType.AbsolutePath:
                return(AndroidBitmapDescriptorFactory.FromPath(descriptor.AbsolutePath));

            default:
                return(AndroidBitmapDescriptorFactory.DefaultMarker());
            }
        }
        AndroidBitmapDescriptor GetRaw(BitmapDescriptor descriptor, Context context)
        {
            switch (descriptor.Type)
            {
            case BitmapDescriptorType.Default:
                return(AndroidBitmapDescriptorFactory.DefaultMarker((float)((descriptor.Color.Hue * 360f) % 360f)));

            case BitmapDescriptorType.Bundle:
                var bundleName = descriptor.BundleName;
                if (!bundleName.Contains('.'))
                {
                    bundleName += ".png";
                }
                if (UseGoogleMapsFactory || descriptor.IconScale == 1 || descriptor.IconScale == 0)
                {
                    return(AndroidBitmapDescriptorFactory.FromAsset(bundleName));
                }
                return(AndroidBitmapDescriptorFactory.FromBitmap(GetBitmapFromAsset(descriptor, context)));

            case BitmapDescriptorType.Stream:
                if (descriptor.Stream.CanSeek && descriptor.Stream.Position > 0)
                {
                    descriptor.Stream.Position = 0;
                }
                return(AndroidBitmapDescriptorFactory.FromBitmap(BitmapFactory.DecodeStream(descriptor.Stream)));

            case BitmapDescriptorType.AbsolutePath:
                return(AndroidBitmapDescriptorFactory.FromPath(descriptor.AbsolutePath));

            default:
                return(AndroidBitmapDescriptorFactory.DefaultMarker());
            }
        }
示例#3
0
        public static NativeBitmapDescriptor ToBitmapDescriptor(this BitmapDescriptor self)
        {
            switch (self.Type)
            {
            case BitmapDescriptorType.Default:
                return(NativeBitmapDescriptorFactory.DefaultMarker((float)self.Color.Hue * 360f));

            case BitmapDescriptorType.Bundle:
                return(NativeBitmapDescriptorFactory.FromAsset(self.BundleName));

            case BitmapDescriptorType.Stream:
                return(NativeBitmapDescriptorFactory.FromBitmap(BitmapFactory.DecodeStream(self.Stream)));

            case BitmapDescriptorType.AbsolutePath:
                return(NativeBitmapDescriptorFactory.FromPath(self.AbsolutePath));

            default:
                return(NativeBitmapDescriptorFactory.DefaultMarker());
            }
        }
        public AndroidBitmapDescriptor ToNative(BitmapDescriptor descriptor)
        {
            switch (descriptor.Type)
            {
            case BitmapDescriptorType.Default:
                return(AndroidBitmapDescriptorFactory.DefaultMarker((float)((descriptor.Color.Hue * 360f) % 360f)));

            case BitmapDescriptorType.Bundle:
                return(AndroidBitmapDescriptorFactory.FromAsset(descriptor.BundleName));

            case BitmapDescriptorType.Stream:
                if (descriptor.Stream.CanSeek && descriptor.Stream.Position > 0)
                {
                    descriptor.Stream.Position = 0;
                }
                return(AndroidBitmapDescriptorFactory.FromBitmap(BitmapFactory.DecodeStream(descriptor.Stream)));

            case BitmapDescriptorType.AbsolutePath:
                return(AndroidBitmapDescriptorFactory.FromPath(descriptor.AbsolutePath));

            default:
                return(AndroidBitmapDescriptorFactory.DefaultMarker());
            }
        }