Exemple #1
0
        /// <summary>
        /// Sets the value of ImageView.ImageMatrix based on Stretch.
        /// </summary>
        /// <param name="frameSize">In logical pixels</param>
        private void UpdateMatrix(Windows.Foundation.Size frameSize)
        {
            SetScaleType(ScaleType.Matrix);

            if (SourceImageSize.Width == 0 || SourceImageSize.Height == 0 || frameSize.Width == 0 || frameSize.Height == 0)
            {
                return;
            }

            // Calculate the resulting space required on screen for the image
            var containerSize = this.MeasureSource(frameSize, SourceImageSize);

            // Calculate the position of the image to follow stretch and alignment requirements
            var sourceRect = this.ArrangeSource(frameSize, containerSize);

            var scaleX     = (sourceRect.Width / SourceImageSize.Width) * _sourceImageScale;
            var scaleY     = (sourceRect.Height / SourceImageSize.Height) * _sourceImageScale;
            var translateX = ViewHelper.LogicalToPhysicalPixels(sourceRect.X);
            var translateY = ViewHelper.LogicalToPhysicalPixels(sourceRect.Y);

            var matrix = new Android.Graphics.Matrix();

            matrix.PostScale((float)scaleX, (float)scaleY);
            matrix.PostTranslate(translateX, translateY);
            ImageMatrix = matrix;
        }
Exemple #2
0
        /// <summary>
        /// Sets the value of ImageView.ImageMatrix based on Stretch.
        /// </summary>
        /// <param name="frameSize">In logical pixels</param>
        private void UpdateMatrix(Windows.Foundation.Size frameSize)
        {
            SetScaleType(ScaleType.Matrix);

            if (SourceImageSize.Width == 0 || SourceImageSize.Height == 0 || frameSize.Width == 0 || frameSize.Height == 0)
            {
                return;
            }

            var sourceRect = new Windows.Foundation.Rect(Windows.Foundation.Point.Zero, SourceImageSize);
            var imageRect  = new Windows.Foundation.Rect(Windows.Foundation.Point.Zero, frameSize);

            MeasureSource(imageRect, ref sourceRect);
            ArrangeSource(imageRect, ref sourceRect);

            var scaleX     = (sourceRect.Width / SourceImageSize.Width) * _sourceImageScale;
            var scaleY     = (sourceRect.Height / SourceImageSize.Height) * _sourceImageScale;
            var translateX = ViewHelper.LogicalToPhysicalPixels(sourceRect.X);
            var translateY = ViewHelper.LogicalToPhysicalPixels(sourceRect.Y);

            var matrix = new Android.Graphics.Matrix();

            matrix.PostScale((float)scaleX, (float)scaleY);
            matrix.PostTranslate(translateX, translateY);
            ImageMatrix = matrix;
        }
        public static Bitmap CreateBitmap(Texture2D image, Vector2 scale, float rotation, Vector2 origin)
        {
            Matrix matrix = new Matrix();

            matrix.PostScale(scale.X, scale.Y);
            matrix.PostRotate(rotation, origin.X, origin.Y);

            Bitmap source    = Texture2D2Bitmap(image);
            Bitmap newBitmap = Bitmap.CreateBitmap(source, 0, 0, source.Width, source.Height, matrix, true);

            return(newBitmap);
        }
Exemple #4
0
        public static Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight)
        {
            int width  = bm.Width;
            int height = bm.Height;

            newHeight = CalculateProportionalHeight(bm.Width, bm.Height, newWidth);

            float scaleWidth  = ((float)newWidth) / width;
            float scaleHeight = ((float)newHeight) / height;
            var   matrix      = new Matrix1();

            matrix.PostScale(scaleWidth, scaleHeight);

            Bitmap resizedBitmap = Bitmap.CreateBitmap(
                bm, 0, 0, width, height, matrix, false);

            bm.Recycle();
            return(resizedBitmap);
        }
    protected Bitmap resizeImage(int w, int h)
    {
        // load the origial Bitmap
        Android.Graphics.Bitmap BitmapOrg = null;

        BitmapOrg = ((BitmapDrawable)this.Drawable).Bitmap.Copy(Bitmap.Config.Argb8888, true);

        int width     = BitmapOrg.Width;
        int height    = BitmapOrg.Height;
        int newWidth  = w;
        int newHeight = h;

        float scaleWidth  = ((float)newWidth) / width;
        float scaleHeight = ((float)newHeight) / height;

        Android.Graphics.Matrix matrix = new Android.Graphics.Matrix();
        matrix.PostScale(scaleWidth, scaleHeight);
        Bitmap resizedBitmap = Android.Graphics.Bitmap.CreateBitmap(BitmapOrg, 0, 0, width, height, matrix, true);

        return(resizedBitmap);
    }
        /// <summary>
        /// Rotates the image to the correct orientation
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="orientation"></param>
        /// <returns></returns>
        public static Bitmap RotateBitmap( Bitmap bitmap, int orientation )
        {
            Matrix matrix = new Matrix();

            switch( orientation )
            {
                case 1:
                    return bitmap;

                case 2:
                    matrix.SetScale( -1, 1 );
                    break;

                case 3:
                    matrix.SetRotate( 180 );
                    break;

                case 4:
                    matrix.SetRotate( 180 );
                    matrix.PostScale( -1, 1 );
                    break;

                case 5:
                    matrix.SetRotate( 90 );
                    matrix.PostScale( -1, 1 );
                    break;

                case 6:
                    matrix.SetRotate( 90 );
                    break;

                case 7:
                    matrix.SetRotate( -90 );
                    matrix.PostScale( -1, 1 );
                    break;

                case 8:
                    matrix.SetRotate( -90 );
                    break;

                default:
                    return bitmap;
            }


            Bitmap bmRotated = Bitmap.CreateBitmap(bitmap, 0, 0, bitmap.Width, bitmap.Height, matrix, true);
            bitmap.Recycle();
            return bmRotated;

        }
		public async void OnGlobalLayout ()
		{
			productImage.ViewTreeObserver.RemoveGlobalOnLayoutListener (this);

			const int DeltaX = 100;

			var img1 = Images.FromUrl (Product.ImageForSize (images [0], Images.ScreenWidth));
			var img2 = Images.FromUrl (Product.ImageForSize (images [1], Images.ScreenWidth));

			productDrawable = new KenBurnsDrawable (Color.DarkBlue);
			productDrawable.FirstBitmap = await img1;
			productDrawable.SecondBitmap = await img2;
			productImage.SetImageDrawable (productDrawable);
			currentIndex++;

			var evaluator = new MatrixEvaluator ();
			var finalMatrix = new Matrix ();
			finalMatrix.SetTranslate (-DeltaX, -(float)productDrawable.FirstBitmap.Height / 1.3f + (float)productImage.Height);
			finalMatrix.PostScale (1.27f, 1.27f);
			kenBurnsMovement = ValueAnimator.OfObject (evaluator, new Matrix (), finalMatrix);
			kenBurnsMovement.Update += (sender, e) => productDrawable.SetMatrix ((Matrix)e.Animation.AnimatedValue);
			kenBurnsMovement.SetDuration (14000);
			kenBurnsMovement.RepeatMode = ValueAnimatorRepeatMode.Reverse;
			kenBurnsMovement.RepeatCount = ValueAnimator.Infinite;
			kenBurnsMovement.Start ();

			kenBurnsAlpha = ObjectAnimator.OfInt (productDrawable, "alpha", 0, 0, 0, 255, 255, 255);
			kenBurnsAlpha.SetDuration (kenBurnsMovement.Duration);
			kenBurnsAlpha.RepeatMode = ValueAnimatorRepeatMode.Reverse;
			kenBurnsAlpha.RepeatCount = ValueAnimator.Infinite;
			kenBurnsAlpha.AnimationRepeat += (sender, e) => NextImage ();
			kenBurnsAlpha.Start ();
		}
Exemple #8
0
        public void DrawShowcase(Canvas canvas, float x, float y, float scaleMultiplier, float radius)
        {
            Matrix mm = new Matrix();
            mm.PostScale(scaleMultiplier, scaleMultiplier, x, y);
            canvas.Matrix = mm;

            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Honeycomb)
            {
                canvas.DrawCircle(x, y, radius, mEraser);
            }

            mShowcaseDrawable.SetBounds(mShowcaseRect.Left, mShowcaseRect.Top, mShowcaseRect.Right, mShowcaseRect.Bottom);
            mShowcaseDrawable.Draw(canvas);

            canvas.Matrix = new Matrix();
        }
Exemple #9
0
		private static Matrix parseTransformScale(String pString) {
			var start = SVGConstants.ATTRIBUTE_TRANSFORM_VALUE_SCALE.Length + 1;
			var svgNumberParserFloatResult = pString.Substring (start, pString.IndexOf (')') - start).ParseFloats ();
			SVGTransformParser.assertNumberParserResultNumberCountMinimum(svgNumberParserFloatResult, 1);
			float sx = svgNumberParserFloatResult[0];
			float sy = 0;
			if (svgNumberParserFloatResult.Length > 1) {
				sy = svgNumberParserFloatResult[1];
			}
			Matrix matrix = new Matrix();
			matrix.PostScale(sx, sy);
			return matrix;
		}
	protected Bitmap resizeImage(int w, int h)
	{
		// load the origial Bitmap
		Android.Graphics.Bitmap BitmapOrg = null;

		BitmapOrg = ((BitmapDrawable)this.Drawable).Bitmap.Copy (Bitmap.Config.Argb8888, true);

		int width = BitmapOrg.Width;
		int height = BitmapOrg.Height;
		int newWidth = w;
		int newHeight = h;
		
		float scaleWidth = ((float) newWidth) / width;
		float scaleHeight = ((float) newHeight) / height;

		Android.Graphics.Matrix matrix = new Android.Graphics.Matrix();
		matrix.PostScale(scaleWidth, scaleHeight);
		Bitmap resizedBitmap = Android.Graphics.Bitmap.CreateBitmap(BitmapOrg, 0, 0, width, height, matrix, true);
		return resizedBitmap;
	}
		Bitmap changeOrientation (string filePath, Bitmap bitmap, int orientation)
		{
			var matrix = new Matrix ();
			switch (orientation) {
			case 2:
				matrix.SetScale (-1, 1);
				break;
			case 3:
				matrix.SetRotate (180);
				break;
			case 4:
				matrix.SetRotate (180);
				matrix.PostScale (-1, 1);
				break;
			case 5:
				matrix.SetRotate (90);
				matrix.PostScale (-1, 1);
				break;
			case 6:
				matrix.SetRotate (90);
				break;
			case 7:
				matrix.SetRotate (-90);
				matrix.PostScale (-1, 1);
				break;
			case 8:
				matrix.SetRotate (-90);
				break;
			default:
				return bitmap;
			}

			try {
				Bitmap oriented = Bitmap.CreateBitmap (bitmap, 0, 0, bitmap.Width, bitmap.Height, matrix, true);
				bitmap.Recycle ();
				return oriented;
			} catch (Exception e) {
				return bitmap;
			}
		}
        //protected override void OnSizeChanged(int w, int h, int oldw, int oldh)
        //{
        //    base.OnSizeChanged(w, h, oldw, oldh);
        //    mX = w * 0.5f; // remember the center of the screen
        //}

        public Drawable ResizeBitmap(Bitmap bitmapOrg, int desiredWidth, int desiredHeight)
        {
            try
            {
                int width = bitmapOrg.Width;
                int height = bitmapOrg.Height;
                int newWidth = desiredWidth;
                int newHeight = desiredHeight;

                // calculate the scale - in this case = 0.4f
                float scaleWidth = ((float)newWidth) / width;
                float scaleHeight = ((float)newHeight) / height;

                // createa matrix for the manipulation
                Matrix matrix = new Matrix();
                // resize the bit map
                matrix.PostScale(scaleWidth, scaleHeight);
                // rotate the Bitmap
                //matrix.PostRotate(45);

                // re*create the new Bitmap
                Bitmap resizedBitmap = Bitmap.CreateBitmap(bitmapOrg, 0, 0, width, height, matrix, true);

                // make a Drawable from Bitmap to allow to set the BitMap 
                // to the ImageView, ImageButton or what ever

                Drawable bmpDraw = new Android.Graphics.Drawables.BitmapDrawable(resizedBitmap);
                return bmpDraw;
            }
            catch (Exception ex)
            {
                //FirstLog.Error(FirstApplication.ApplicationName + "Log", "ResizeBitmap: " + ex.Message);
                return new Android.Graphics.Drawables.BitmapDrawable(bitmapOrg);
            }
        }
        /// <summary>
        /// Helper method to provide the corresponding Icon for a station
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public BitmapDescriptor CreateStationIcon(Station station)
        {
            Bitmap bitmap = null;
            var value = _settingsService.Settings.IsBikeMode ? station.AvailableBikes : station.AvailableBikeStands;
            var printedValue = value.HasValue ? value.Value.ToString() : string.Empty;
            if (!station.Loaded)
            {
                printedValue = string.Empty;
                bitmap = _iconGreyLowAlpha;
                bitmap = bitmap.Copy(bitmap.GetConfig(), true);
            }
            else if (station.Status == false)
            {
                printedValue = "!";
                bitmap = _iconGrey;
                bitmap = bitmap.Copy(bitmap.GetConfig(), true);
            }
            else if (station.ImageAvailable != null || station.ImageDocks != null)
            {
                if (_metrics == null)
                {
                    _metrics = new DisplayMetrics();
                    (CrossCurrentActivity.Current.Activity as MainActivity).WindowManager.DefaultDisplay.GetMetrics(_metrics);
                }

                bitmap = _iconGrey;
                bitmap = bitmap.Copy(bitmap.GetConfig(), true);
                try
                {
                    var data = (byte[])(_settingsService.Settings.IsBikeMode ? station.ImageAvailable : station.ImageDocks);
                    var gifDecoder = new GifDecoder();
                    gifDecoder.read(data);
                    if (gifDecoder.getFrameCount() != 0)
                    {
                        gifDecoder.advance();
                        var bmp = gifDecoder.getNextFrame();
                        var canvas = new Canvas(bitmap);

                        int width = bmp.Width;
                        int height = bmp.Height;
                        float scaleWidth = _metrics.ScaledDensity;
                        float scaleHeight = _metrics.ScaledDensity;
                        // create a matrix for the scaling manipulation
                        Matrix matrix = new Matrix();
                        // resize the bitmap
                        matrix.PostScale(scaleWidth, scaleHeight);

                        // recreate the new Bitmap
                        var resizedBitmap = Bitmap.CreateBitmap(bmp, 0, 0, width, height, matrix, true);

                        int xPos = canvas.Width / 2 - resizedBitmap.Width / 2;
                        int yPos = canvas.Height / 2 - resizedBitmap.Height;
                        canvas.DrawBitmap(resizedBitmap, xPos, yPos, null);
                    }

                }
                catch (System.Exception e)
                {
                }

            }
            else {
                if (value == 0)
                {
                    bitmap = _iconRed;
                }
                else if (value < 5)
                {
                    bitmap = _iconOrange;
                }
                else if (value >= 5)
                {
                    bitmap = _iconGreen;
                }
                else
                {
                    printedValue = "?";
                    bitmap = _iconGrey;
                }
            }

            if (printedValue != string.Empty)
            {
                bitmap = bitmap.Copy(bitmap.GetConfig(), true);
                Canvas canvas = new Canvas(bitmap);
                int xPos = (canvas.Width / 2);
                int yPos = (int)((canvas.Height / 2) - ((_textPaint.Descent() + _textPaint.Ascent()) / 2));
                canvas.DrawText(printedValue, xPos + 1, yPos - LayoutHelper.ConvertDpToPixel(6), _textPaint);
            }

            var icon = BitmapDescriptorFactory.FromBitmap(bitmap);
            bitmap.Recycle();
            return icon;
        }
        /// <summary>
        /// Setup the base matrix so that the image is centered and scaled properly.
        /// </summary>
        private void getProperBaseMatrix(RotateBitmap bitmap, Matrix matrix)
        {
            float viewWidth = _width; //Width;
            float viewHeight = _height; //Height;

            float w = bitmap.Width;
            float h = bitmap.Height;
            int rotation = bitmap.Rotation;
            matrix.Reset();

            // We limit up-scaling to 2x otherwise the result may look bad if it's
            // a small icon.
            float widthScale = viewWidth / w; //Math.Min(viewWidth / w, 2.0f);
            float heightScale = viewHeight / h; //Math.Min(viewHeight / h, 2.0f);
            float scale = Math.Min(widthScale, heightScale);

            matrix.PostConcat(bitmap.GetRotateMatrix());
            matrix.PostScale(scale, scale);

            matrix.PostTranslate(
                (viewWidth - w * scale) / 2F,
                (viewHeight - h * scale) / 2F);
        }
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if ((resultCode == Result.Ok) && (data != null))
            {
                if (requestCode == PickImageId)
                {
                    Uri uri = data.Data;
                    Bitmap tempBitmap = BitmapFactory.DecodeFile(GetPathToImage(uri));

                    //resize
                    int newHeight = ConvertDptoPx(60);
                    int newWidth = (int) (((float) tempBitmap.Width) / ((float) tempBitmap.Height) * newHeight);

                    //scale
                    float scaleWidth = ((float) newWidth) / tempBitmap.Width;
                    float scaleHeight = ((float) newHeight) / tempBitmap.Height;

                    Matrix matrix = new Matrix();
                    matrix.PostScale(scaleWidth, scaleHeight);

                    //rotate
                    ExifInterface exif = new ExifInterface(GetPathToImage(uri));
                    int orientation = exif.GetAttributeInt(ExifInterface.TagOrientation, 1);
                    switch (orientation)
                    {
                        case 3:
                            matrix.PostRotate(180);
                            break;
                        case 6:
                            matrix.PostRotate(90);
                            break;
                        case 8:
                            matrix.PostRotate(270);
                            break;
                    }

                    _bitmap = Bitmap.CreateBitmap(tempBitmap, 0, 0, tempBitmap.Width, tempBitmap.Height, matrix, false);
                    tempBitmap.Recycle();
                    _imageView.SetImageBitmap(_bitmap);
                }

                else if (requestCode == PickContactsId)
                {
                    _participantsAdapter.Items.Clear();

                    string intentString = data.GetStringExtra("New participants");
                    if (intentString != string.Empty)
                    {
                        string[] contactStrings = intentString.Split('|');

                        for (int i = 0; i < contactStrings.Length; i++)
                        {
                            string[] contactAttr = contactStrings[i].Split(',');

                            _participantsAdapter.Items.Add(new ListItem(contactAttr[0], int.Parse(contactAttr[1]))); // 0 = naam, 1 = image
                        }
                    }

                    _participantsAdapter.NotifyDataSetChanged();
                    _participantsRecyclerView.LayoutParameters.Height = ConvertDptoPx(listItemHeight * _participantsAdapter.Items.Count);
                    _participantsRecyclerView.Invalidate ();
                    _scrollView.Invalidate();
                    _scrollView.RequestLayout();
                }
            }
        }
		/// <summary>
		/// Configures the necessary transformation to mTextureView.
		/// This method should be called after the camera preciew size is determined in openCamera, and also the size of mTextureView is fixed
		/// </summary>
		/// <param name="viewWidth">The width of mTextureView</param>
		/// <param name="viewHeight">VThe height of mTextureView</param>
		private void ConfigureTransform(int viewWidth, int viewHeight)
		{
			Activity activity = Activity;
			if (mTextureView == null || mPreviewSize == null || activity == null) {
				return;
			}

			SurfaceOrientation rotation = activity.WindowManager.DefaultDisplay.Rotation;
			Matrix matrix = new Matrix ();
			RectF viewRect = new RectF (0, 0, viewWidth, viewHeight);
			RectF bufferRect = new RectF (0, 0, mPreviewSize.Width, mPreviewSize.Height);
			float centerX = viewRect.CenterX();
			float centerY = viewRect.CenterY();
			if (rotation == SurfaceOrientation.Rotation90 || rotation == SurfaceOrientation.Rotation270) {
				bufferRect.Offset (centerX - bufferRect.CenterX(), centerY - bufferRect.CenterY());
				matrix.SetRectToRect (viewRect, bufferRect, Matrix.ScaleToFit.Fill);
				float scale = Math.Max ((float)viewHeight / mPreviewSize.Height, (float)viewWidth / mPreviewSize.Width);
				matrix.PostScale (scale, scale, centerX, centerY);
				matrix.PostRotate (90 * ((int)rotation - 2), centerX, centerY);
			}
			mTextureView.SetTransform (matrix);
		}
		//Configures the neccesary matrix transformation to apply to the textureView
		public void configureTransform(int viewWidth, int viewHeight) 
		{
			if (null == Activity || null == previewSize || null == textureView) 
				return;

			int rotation = (int)Activity.WindowManager.DefaultDisplay.Rotation;
			var matrix = new Matrix ();
			var viewRect = new RectF (0, 0, viewWidth, viewHeight);
			var bufferRect = new RectF (0, 0, previewSize.Height, previewSize.Width);
			float centerX = viewRect.CenterX();
			float centerY = viewRect.CenterY();
			if ((int)SurfaceOrientation.Rotation90 == rotation || (int)SurfaceOrientation.Rotation270 == rotation) { 
				bufferRect.Offset ((centerX - bufferRect.CenterX()), (centerY - bufferRect.CenterY()));
				matrix.SetRectToRect (viewRect, bufferRect, Matrix.ScaleToFit.Fill);
				float scale = System.Math.Max (
					(float)viewHeight / previewSize.Height,
					(float)viewHeight / previewSize.Width);
				matrix.PostScale (scale, scale, centerX, centerY);
				matrix.PostRotate (90 * (rotation - 2), centerX, centerY);
			}
			textureView.SetTransform (matrix);
		}
        protected void ZoomOut(float rate)
        {
            if (bitmapDisplayed.Bitmap == null)
            {
                return;
            }

            float cx = Width / 2F;
            float cy = Height / 2F;

            // Zoom out to at most 1x.
            Matrix tmp = new Matrix(suppMatrix);
            tmp.PostScale(1F / rate, 1F / rate, cx, cy);

            if (GetScale(tmp) < 1F)
            {
                suppMatrix.SetScale(1F, 1F, cx, cy);
            }
            else
            {
                suppMatrix.PostScale(1F / rate, 1F / rate, cx, cy);
            }

            ImageMatrix = GetImageViewMatrix();
            Center(true, true);
        }