예제 #1
0
		public static Bitmap RotateToCorrentOrientation(this Bitmap bitmap, SurfaceOrientation currentOrientation)
		{
			//Calculate rotation
			float degrees = 0;
			switch (currentOrientation)
			{
				case SurfaceOrientation.Rotation180:
					degrees = -180;
					break;
				case SurfaceOrientation.Rotation270:
					degrees = 90;
					break;
				case SurfaceOrientation.Rotation90:
					degrees = -90;
					break;
			}

			//Rotate if needed
			if (degrees != 0)
			{
				using (Matrix mtx = new Matrix())
				{
					mtx.PreRotate(degrees);
					bitmap = Bitmap.CreateBitmap(bitmap, 0, 0, bitmap.Width, bitmap.Height, mtx, false);
				}
			}
			return bitmap;
		}
예제 #2
0
 public IImage Rotate(int degrees) {
     using (var matrix = new Matrix()) {
         matrix.PreRotate(degrees);
         var bmp = Bitmap.CreateBitmap(this.bitmap, 0, 0, this.bitmap.Width, this.bitmap.Height, matrix, true);
         this.bitmap.Dispose();
         this.bitmap = bmp;
     }            
     return this;
 }
예제 #3
0
        public static Bitmap GetAndRotateBitmap(string fileName)
        {
            Bitmap bitmap = BitmapFactory.DecodeFile(fileName);

            // Images are being saved in landscape, so rotate them back to portrait if they were taken in portrait
            // See https://forums.xamarin.com/discussion/5409/photo-being-saved-in-landscape-not-portrait
            // See http://developer.android.com/reference/android/media/ExifInterface.html
            using (Matrix mtx = new Matrix())
            {
                if (Android.OS.Build.Product.Contains("Emulator"))
                {
                    mtx.PreRotate(90);
                }
                else
                {
                    ExifInterface exif = new ExifInterface(fileName);
                    var orientation = (Orientation)exif.GetAttributeInt(ExifInterface.TagOrientation, (int)Orientation.Normal);

                    //TODO : handle FlipHorizontal, FlipVertical, Transpose and Transverse
                    switch (orientation)
                    {
                        case Orientation.Rotate90:
                            mtx.PreRotate(90);
                            break;
                        case Orientation.Rotate180:
                            mtx.PreRotate(180);
                            break;
                        case Orientation.Rotate270:
                            mtx.PreRotate(270);
                            break;
                        case Orientation.Normal:
                            // Normal, do nothing
                            break;
                        default:
                            break;
                    }
                }

                if (mtx != null)
                    bitmap = Bitmap.CreateBitmap(bitmap, 0, 0, bitmap.Width, bitmap.Height, mtx, false);
            }

            return bitmap;
        }
예제 #4
0
		public static Bitmap LoadAndResizeBitmap (this string fileName, int width, int height)
		{

			ExifInterface exif = new ExifInterface (fileName);
			int exifOrientation = exif.GetAttributeInt (
				                      ExifInterface.TagOrientation,
				                      (int)Android.Media.Orientation.Normal);


			int rotate = 0;

			switch (exifOrientation) {
			case (int) Android.Media.Orientation.Rotate90:
				rotate = 90;
				break; 

			case (int) Android.Media.Orientation.Rotate180:
				rotate = 180;
				break;

			case (int) Android.Media.Orientation.Rotate270:
				rotate = 270;
				break;
			}

			Bitmap bitmap = BitmapFactory.DecodeFile (fileName);
			int w = bitmap.Width;
			int h = bitmap.Height;

			// Setting pre rotate
			Matrix mtx = new Matrix ();
			mtx.PreRotate (rotate);

			// Rotating Bitmap & convert to ARGB_8888, required by tess
			bitmap = Bitmap.CreateBitmap (bitmap, 0, 0, w, h, mtx, false);
			bitmap = bitmap.Copy (Bitmap.Config.Argb8888, true);

			return bitmap;
		}
예제 #5
0
        public static Bitmap LoadAndResizeBitmap(this string fileName, int width, int height)
        {
            // First we get the the dimensions of the file on disk
            BitmapFactory.Options options = new BitmapFactory.Options { InJustDecodeBounds = true };
            BitmapFactory.DecodeFile(fileName, options);

            // Next we calculate the ratio that we need to resize the image by
            // in order to fit the requested dimensions.
            int outHeight = options.OutHeight;
            int outWidth = options.OutWidth;
            int inSampleSize = 1;

            if (outHeight > height || outWidth > width)
            {
                inSampleSize = outWidth > outHeight
                    ? outHeight / height
                        : outWidth / width;
            }

            // Now we will load the image and have BitmapFactory resize it for us.
            options.InSampleSize = inSampleSize;
            options.InJustDecodeBounds = false;
            Bitmap resizedBitmap = BitmapFactory.DecodeFile(fileName, options);

            // Images are being saved in landscape, so rotate them back to portrait if they were taken in portrait
            Matrix mtx = new Matrix();
            ExifInterface exif = new ExifInterface(fileName);
            var orientation = (Orientation)exif.GetAttributeInt(ExifInterface.TagOrientation, (int)Orientation.Undefined);

            switch (orientation)
            {
                case Orientation.Undefined: // Nexus 7 landscape...
                    break;
                case Orientation.Normal: // landscape
                    break;
                case Orientation.FlipHorizontal:
                    break;
                case Orientation.Rotate180:
                    mtx.PreRotate(180);
                    resizedBitmap = Bitmap.CreateBitmap(resizedBitmap, 0, 0, resizedBitmap.Width, resizedBitmap.Height, mtx, false);
                    mtx.Dispose();
                    mtx = null;
                    break;
                case Orientation.FlipVertical:
                    break;
                case Orientation.Transpose:
                    break;
                case Orientation.Rotate90: // portrait
                    mtx.PreRotate(90);
                    resizedBitmap = Bitmap.CreateBitmap(resizedBitmap, 0, 0, resizedBitmap.Width, resizedBitmap.Height, mtx, false);
                    mtx.Dispose();
                    mtx = null;
                    break;
                case Orientation.Transverse:
                    break;
                case Orientation.Rotate270: // might need to flip horizontally too...
                    mtx.PreRotate(270);
                    resizedBitmap = Bitmap.CreateBitmap(resizedBitmap, 0, 0, resizedBitmap.Width, resizedBitmap.Height, mtx, false);
                    mtx.Dispose();
                    mtx = null;
                    break;
                default:
                    mtx.PreRotate(90);
                    resizedBitmap = Bitmap.CreateBitmap(resizedBitmap, 0, 0, resizedBitmap.Width, resizedBitmap.Height, mtx, false);
                    mtx.Dispose();
                    mtx = null;
                    break;
            }
            
            return resizedBitmap;
        }
        private Bitmap ExifRotateBitmap(ContentResolver contentResolver, Uri uri, Bitmap bitmap)
        {
            if (bitmap == null)
                return null;

            var exif = new Android.Media.ExifInterface(GetRealPathFromUri(contentResolver, uri));
            var rotation = exif.GetAttributeInt(Android.Media.ExifInterface.TagOrientation, (Int32)Android.Media.Orientation.Normal);
            var rotationInDegrees = ExifToDegrees(rotation);
            if (rotationInDegrees == 0)
                return bitmap;

            using (var matrix = new Matrix())
            {
                matrix.PreRotate(rotationInDegrees);
                return Bitmap.CreateBitmap(bitmap, 0, 0, bitmap.Width, bitmap.Height, matrix, true);
            }
        }
예제 #7
0
        //@Override
        protected override void OnSizeChanged(int width, int height, int oldw, int oldh)
        {

            int centerX = width / 2;
            int centerY = height / 2;

            innerPadding = (int)(paramInnerPadding * width / 100);
            outerPadding = (int)(paramOuterPadding * width / 100);
            arrowPointerSize = (int)(paramArrowPointerSize * width / 100);
            valueSliderWidth = (int)(paramValueSliderWidth * width / 100);

            outerWheelRadius = width / 2 - outerPadding - arrowPointerSize;
            innerWheelRadius = outerWheelRadius - valueSliderWidth;
            colorWheelRadius = innerWheelRadius - innerPadding;

            outerWheelRect.Set(centerX - outerWheelRadius, centerY - outerWheelRadius, centerX + outerWheelRadius, centerY + outerWheelRadius);
            innerWheelRect.Set(centerX - innerWheelRadius, centerY - innerWheelRadius, centerX + innerWheelRadius, centerY + innerWheelRadius);

            colorWheelBitmap = createColorWheelBitmap(colorWheelRadius * 2, colorWheelRadius * 2);

            gradientRotationMatrix = new Matrix();
            gradientRotationMatrix.PreRotate(270, width / 2, height / 2);

            colorViewPath.ArcTo(outerWheelRect, 270, -180);
            colorViewPath.ArcTo(innerWheelRect, 90, 180);

            valueSliderPath.ArcTo(outerWheelRect, 270, 180);
            valueSliderPath.ArcTo(innerWheelRect, 90, -180);

        }
예제 #8
0
        private Bitmap LoadAndResizeBitmap()
        {
            if (Path.StartsWith("http"))
            {
                //var webImage = GetImageBitmapFromUrl(Path);
                //return Bitmap.CreateScaledBitmap(webImage, _screenWidth, _screenHeight, false);
                return GetImageBitmapFromUrl(Path);
            }

            // First we get the the dimensions of the file on disk
            BitmapFactory.Options options = new BitmapFactory.Options { InJustDecodeBounds = true };
            BitmapFactory.DecodeFile(Path, options);

            // Next we calculate the ratio that we need to resize the image by
            // in order to fit the requested dimensions.
            int outHeight = options.OutHeight;
            int outWidth = options.OutWidth;
            int inSampleSize = 1;

            if (outHeight > _screenHeight || outWidth > _screenWidth)
            {
                inSampleSize = outWidth > outHeight
                               ? outHeight / _screenHeight
                               : outWidth / _screenWidth;
            }

            // Now we will load the image and have BitmapFactory resize it for us.
            options.InSampleSize = inSampleSize;
            options.InJustDecodeBounds = false;
            Bitmap resizedBitmap = BitmapFactory.DecodeFile(Path, options);

            // Images are being saved in landscape, so rotate them back to portrait if they were taken in portrait
            Matrix mtx = new Matrix();
            ExifInterface exif = new ExifInterface(Path);
            string orientation = exif.GetAttribute(ExifInterface.TagOrientation);
            switch (orientation)
            {
                case "6": // portrait
                    mtx.PreRotate(90);
                    resizedBitmap = Bitmap.CreateBitmap(resizedBitmap, 0, 0, resizedBitmap.Width, resizedBitmap.Height, mtx, false);
                    mtx.Dispose();
                    mtx = null;
                    break;
                case "1": // landscape
                    break;
                default:
                    mtx.PreRotate(90);
                    resizedBitmap = Bitmap.CreateBitmap(resizedBitmap, 0, 0, resizedBitmap.Width, resizedBitmap.Height, mtx, false);
                    mtx.Dispose();
                    mtx = null;
                    break;
            }

            return resizedBitmap;
        }