public void ThenResultingImageSizeShouldBeLikeCropLayer(float left, float top, float right, float bottom, CropMode mode) { // When crop mode is percentage. The right and bottom values should represent // the percentage amount to remove from those sides. const int SizeX = 200; const int SizeY = 200; int expectedWidth = 160; int expectedHeight = 144; CropLayer cl = new CropLayer(left, top, right, bottom, mode); // Arrange using (Bitmap bitmap = new Bitmap(SizeX, SizeY)) using (MemoryStream memoryStream = new MemoryStream()) { bitmap.Save(memoryStream, ImageFormat.Bmp); memoryStream.Position = 0; using (ImageFactory imageFactory = new ImageFactory()) using (ImageFactory resultImage = imageFactory.Load(memoryStream).Crop(cl)) { // Act // Assert Assert.AreEqual(expectedWidth, resultImage.Image.Width); Assert.AreEqual(expectedHeight, resultImage.Image.Height); } } }
/// <summary> /// Initializes a new instance of the <see cref="CropLayer"/> class. /// </summary> /// <param name="left">The left coordinate of the crop layer.</param> /// <param name="top">The top coordinate of the crop layer.</param> /// <param name="right">The right coordinate of the crop layer.</param> /// <param name="bottom">The bottom coordinate of the crop layer.</param> /// <param name="cropMode">The <see cref="CropMode"/>.</param> /// <remarks> /// If the <see cref="CropMode"/> is set to <value>CropMode.Percentage</value> then the four coordinates /// become percentages to reduce from each edge. /// </remarks> public CropLayer(float left, float top, float right, float bottom, CropMode cropMode = CropMode.Percentage) { if (left < 0) { throw new ArgumentOutOfRangeException(nameof(left)); } if (top < 0) { throw new ArgumentOutOfRangeException(nameof(top)); } if (right < 0) { throw new ArgumentOutOfRangeException(nameof(right)); } if (bottom < 0) { throw new ArgumentOutOfRangeException(nameof(bottom)); } this.Left = left; this.Top = top; this.Right = right; this.Bottom = bottom; this.CropMode = cropMode; }
/// <summary> /// Initializes a new instance of the <see cref="CropFilter"/> class. /// </summary> /// <param name="shrinkFactor">The shrink factor.</param> /// <param name="anchor">The anchor.</param> public CropFilter(double shrinkFactor, AnchorLocation anchor) { if (0 > shrinkFactor || shrinkFactor > 1) throw new ArgumentException("Shrink factor must be between 0 and 1"); this.ShrinkFactor = shrinkFactor; this.Anchor = anchor; this._cropMode = CropMode.ShrinkFactor; }
public void ConstructorSavesData(float left, float top, float right, float bottom, CropMode mode) { CropLayer cl = new CropLayer(left, top, right, bottom, mode); cl.Left.Should().Be(left); cl.Top.Should().Be(top); cl.Right.Should().Be(right); cl.Bottom.Should().Be(bottom); cl.CropMode.Should().Be(mode); }
/// <summary> /// Initializes a new instance of the <see cref="CropFilter"/> class. /// </summary> /// <param name="shrinkFactor">The shrink factor.</param> /// <param name="anchor">The anchor.</param> public CropFilter(double shrinkFactor, AnchorLocation anchor) { if (0 > shrinkFactor || shrinkFactor > 1) { throw new ArgumentException("Shrink factor must be between 0 and 1"); } this.ShrinkFactor = shrinkFactor; this.Anchor = anchor; this._cropMode = CropMode.ShrinkFactor; }
/// <summary> /// Initializes a new instance of the <see cref="CropLayer"/> class. /// </summary> /// <param name="left"> /// The left coordinate of the crop layer. /// </param> /// <param name="top"> /// The top coordinate of the crop layer. /// </param> /// <param name="right"> /// The right coordinate of the crop layer. /// </param> /// <param name="bottom"> /// The bottom coordinate of the crop layer. /// </param> /// <param name="cropMode"> /// The <see cref="CropMode"/>. /// </param> /// <remarks> /// If the <see cref="CropMode"/> is set to <value>CropMode.Percentage</value> then the four coordinates /// become percentages to reduce from each edge. /// </remarks> public CropLayer(float left, float top, float right, float bottom, CropMode cropMode = CropMode.Percentage) { if (left < 0 || top < 0 || right < 0 || bottom < 0) { throw new ArgumentOutOfRangeException(); } this.Left = left; this.Top = top; this.Right = right; this.Bottom = bottom; this.CropMode = cropMode; }
/// <summary> /// Initializes a new instance of the <see cref="CropLayer"/> class. /// </summary> /// <param name="left">The left coordinate of the crop layer.</param> /// <param name="top">The top coordinate of the crop layer.</param> /// <param name="right">The right coordinate of the crop layer.</param> /// <param name="bottom">The bottom coordinate of the crop layer.</param> /// <param name="cropMode">The <see cref="CropMode"/>.</param> /// <remarks> /// If the <see cref="CropMode"/> is set to <value>CropMode.Percentage</value> then the four coordinates /// become percentages to reduce from each edge. /// </remarks> public CropLayer(float left, float top, float right, float bottom, CropMode cropMode = CropMode.Percentage) { if (left < 0 || top < 0 || right < 0 || bottom < 0) { throw new ArgumentOutOfRangeException(); } Left = left; Top = top; Right = right; Bottom = bottom; CropMode = cropMode; }
private void btnMode_Click(object sender, EventArgs e) { if (sender == btnModeSelection) { grpCropSide.Enabled = false; grpCropAspect.Enabled = true; cropMode = CropMode.Selection; } else if (sender == btnModeTrans || sender == btnModeTopLeft || sender == btnModeBottomRight) { grpCropSide.Enabled = true; grpCropAspect.Enabled = false; if ((sender as RadioButton).Checked) { if (sender == btnModeTrans) { opaqueMode = ContentMaskMode.Alpha; cropMode = CropMode.Transparency; } else if (sender == btnModeTopLeft) { opaqueMode = ContentMaskMode.TopLeft; cropMode = CropMode.TopLeft; } else if (sender == btnModeBottomRight) { opaqueMode = ContentMaskMode.BottomRight; cropMode = CropMode.BottomRight; } selectionSrc = AddinUtils.AdjustRegion(AddinUtils.GetContentBound(addin.ImageData, opaqueMode), addin.ImageData, cropSide); imgPreview.SelectionRegion = AddinUtils.RemapRegion(selectionSrc, addin.ImageData, thumb); } } else if (sender == btnModeAspect) { grpCropSide.Enabled = false; grpCropAspect.Enabled = true; cropMode = CropMode.AspectRatio; selection = MakeAspectRegion(thumb.Size, selection, cropAspectFactor); imgPreview.SelectionRegion = selection; } }
/// <summary> /// The position in the original string where the first character of the captured substring was found. /// </summary> /// <param name="queryString"> /// The query string to search. /// </param> /// <returns> /// The zero-based starting position in the original string where the captured substring was found. /// </returns> public int MatchRegexIndex(string queryString) { this.SortOrder = int.MaxValue; Match match = this.RegexPattern.Match(queryString); if (match.Success) { this.SortOrder = match.Index; NameValueCollection queryCollection = HttpUtility.ParseQueryString(queryString); float[] coordinates = QueryParamParser.Instance.ParseValue <float[]>(queryCollection["cropper"]); // Default CropMode.Pixels will be returned. CropMode cropMode = QueryParamParser.Instance.ParseValue <CropMode>(queryCollection["cropmode"]); CropLayer cropLayer = new CropLayer(coordinates[0], coordinates[1], coordinates[2], coordinates[3], cropMode); this.Processor.DynamicParameter = cropLayer; } return(this.SortOrder); }
/// <summary> /// Generates a new thumbnail which replaces the old thumbnail /// </summary> /// <param name="mode">Crop mode</param> /// <param name="fileStream">File stream</param> /// <param name="thumbnailPath">Path to thumbnail</param> /// <param name="value">Size value</param> private static void GenerateThumbnail(CropMode mode, Stream fileStream, string thumbnailPath, int value) { ResizeMode resizeMode = ResizeMode.Crop; switch (mode) { case CropMode.FillSquare: resizeMode = ResizeMode.Crop; break; case CropMode.Uniform: resizeMode = ResizeMode.Max; break; } SaveImage(fileStream, thumbnailPath, c => c.Resize(new ResizeOptions { Mode = resizeMode, Size = new Size(value) })); }
/// <summary> /// The position in the original string where the first character of the captured substring was found. /// </summary> /// <param name="queryString">The query string to search.</param> /// <returns> /// The zero-based starting position in the original string where the captured substring was found. /// </returns> public int MatchRegexIndex(string queryString) { int index = 0; // Set the sort order to max to allow filtering. this.SortOrder = int.MaxValue; // First merge the matches so we can parse . StringBuilder stringBuilder = new StringBuilder(); foreach (Match match in this.RegexPattern.Matches(queryString)) { // Match but ignore entropy if (match.Success && !queryString.ToUpperInvariant().Contains("ENTROPYCROP=")) { if (index == 0) { // Set the index on the first instance only. this.SortOrder = match.Index; } stringBuilder.Append(match.Value); index += 1; } } if (this.SortOrder < int.MaxValue) { // Match syntax string toParse = stringBuilder.ToString(); float[] coordinates = this.ParseCoordinates(toParse); CropMode cropMode = this.ParseMode(toParse); CropLayer cropLayer = new CropLayer(coordinates[0], coordinates[1], coordinates[2], coordinates[3], cropMode); this.Processor.DynamicParameter = cropLayer; } return(this.SortOrder); }
public static string writeCrop(CropMode mode, double[] coords) { if (mode == CropMode.Auto) { return("auto"); } if (mode == CropMode.None) { return("none"); } if (mode == CropMode.Custom) { string c = "("; foreach (double d in coords) { c += d.ToString(NumberFormatInfo.InvariantInfo) + ","; } return(c.TrimEnd(',') + ")"); } throw new NotImplementedException("Unrecognized CropMode value: " + mode.ToString()); }
private void tglCrop_Toggle(object sender, EventArgs e) { if (tglCrop.IsChecked) { cropMode = CropMode.CropToContent; this.MinimumSize = CropModeMinimumSize; player.SetLogoInt((uint)LibVlc.libvlc_video_logo_option_t.libvlc_logo_enable, 0); } else { cropMode = CropMode.NoCropping; this.MinimumSize = DefaultClientSize; if (this.Height < MinimumSize.Height) { this.ClientSize = MinimumSize; } else { this.Width = (int)(WhRatio * ucVLC.Height) + margin; } player.UnSetCropGeometry(); } }
void SetMode( CropMode mode ) { if( mode == Mode ) { throw new Exception( string.Format( "Crop Mode {0} requested, but already in that mode.", mode ) ); } switch( mode ) { case CropMode.Editing: { // If we're entering edit mode for the first time if ( Mode == CropMode.None ) { // Animate in the mask SimpleAnimator_Float floatAnimator = new SimpleAnimator_Float( MaskLayer.Opacity, MaskFadeAmount, MaskFadeTime, delegate( float percent, object value ) { Rock.Mobile.Threading.Util.PerformOnUIThread( delegate { MaskLayer.Opacity = (float)value; } ); }, null ); floatAnimator.Start( ); // turn on our cropper CropView.Visibility = ViewStates.Visible; // and set the source image to the scaled source. ImageView.SetImageBitmap( ScaledSourceImage ); } // else we're coming FROM Preview Mode, so we need to animate else { Animating = true; // setup the dimension changes System.Drawing.SizeF startSize = new System.Drawing.SizeF( ImageView.Width, ImageView.Height ); System.Drawing.SizeF endSize = new System.Drawing.SizeF( CropView.Width, CropView.Height ); PointF startPos = new PointF( ImageView.GetX( ), ImageView.GetY( ) ); PointF endPos = new PointF( CropView.GetX( ), CropView.GetY( ) ); // now animate the cropped image up to its full size AnimateImageView( ImageView, startPos, endPos, startSize, endSize, ImageAnimationTime, delegate { ImageView.SetImageBitmap( null ); // release any cropped image we had. if ( CroppedImage != null ) { CroppedImage.Dispose( ); CroppedImage = null; } // release the scaled version if we had it if ( ScaledCroppedImage != null ) { ScaledCroppedImage.Dispose( ); ScaledCroppedImage = null; } ImageView.SetImageBitmap( ScaledSourceImage ); ImageView.LayoutParameters.Width = ScaledSourceImage.Width; ImageView.LayoutParameters.Height = ScaledSourceImage.Height; // center the image ImageView.SetX( (ScreenSize.Width - ImageView.LayoutParameters.Width ) / 2 ); ImageView.SetY( (ScreenSize.Height - ImageView.LayoutParameters.Height ) / 2 ); MaskLayer.Visibility = ViewStates.Visible; CropView.Visibility = ViewStates.Visible; SimpleAnimator_Float floatAnimator = new SimpleAnimator_Float( MaskLayer.Opacity, MaskFadeAmount, MaskFadeTime, delegate( float percent, object value ) { Rock.Mobile.Threading.Util.PerformOnUIThread( delegate { MaskLayer.Opacity = (float)value; CropView.Alpha = percent; } ); }, // FINISHED MASK FADE-OUT delegate { Rock.Mobile.Threading.Util.PerformOnUIThread( delegate { Animating = false; }); }); floatAnimator.Start( ); } ); } break; } case CropMode.Previewing: { // don't allow a state change while we're animating Animating = true; SimpleAnimator_Float floatAnimator = new SimpleAnimator_Float( MaskLayer.Opacity, 1.00f, MaskFadeTime, delegate( float percent, object value ) { Rock.Mobile.Threading.Util.PerformOnUIThread( delegate { MaskLayer.Opacity = (float)value; CropView.Alpha = 1.0f - percent; } ); }, // FINISHED MASK FADE-IN delegate { Rock.Mobile.Threading.Util.PerformOnUIThread( delegate { // hide the mask and cropper MaskLayer.Visibility = ViewStates.Gone; CropView.Visibility = ViewStates.Gone; // create the cropped image CroppedImage = CropImage( SourceImage, new System.Drawing.RectangleF( CropView.GetX( ) - CropViewMinPos.X, CropView.GetY( ) - CropViewMinPos.Y, CropView.LayoutParameters.Width, CropView.LayoutParameters.Height ) ); // create a scaled version of the cropped image float scaledWidth = (float)CroppedImage.Width * (1.0f / ScreenToImageScalar); float scaledHeight = (float)CroppedImage.Height * (1.0f / ScreenToImageScalar); ScaledCroppedImage = Bitmap.CreateScaledBitmap( CroppedImage, (int)scaledWidth, (int)scaledHeight, false ); // set the scaled cropped image ImageView.SetImageBitmap( null ); ImageView.SetImageBitmap( ScaledCroppedImage ); // start the scaled cropped image scaled down further to match its size within the full image. ImageView.SetX( CropView.GetX( ) ); ImageView.SetY( CropView.GetY( ) ); ImageView.LayoutParameters.Width = CropView.Width; ImageView.LayoutParameters.Height = CropView.Height; // setup the dimension changes System.Drawing.SizeF startSize = new System.Drawing.SizeF( ScaledCroppedImage.Width, ScaledCroppedImage.Height ); System.Drawing.SizeF endSize; if( ScreenSize.Width < ScreenSize.Height ) { endSize = new System.Drawing.SizeF( ScreenSize.Width, (float)System.Math.Ceiling( ScreenSize.Width * ( startSize.Width / startSize.Height ) ) ); } else { endSize = new System.Drawing.SizeF( (float)System.Math.Ceiling( ScreenSize.Height * ( startSize.Height / startSize.Width ) ), ScreenSize.Height ); } PointF startPos = new PointF( CropView.GetX( ), CropView.GetY( ) ); PointF endPos = new PointF( (ScreenSize.Width - endSize.Width) / 2, (ScreenSize.Height - endSize.Height) / 2 ); // now animate the cropped image up to its full size AnimateImageView( ImageView, startPos, endPos, startSize, endSize, ImageAnimationTime, delegate { Animating = false; } ); } ); } ); floatAnimator.Start( ); break; } } Mode = mode; }
public void ResampleAndCrop(ResamplingFilters filter, CropMode mode, int newWidth, int newHeight) { if (Disposed) { return; } // fit int w = newWidth; int h = newHeight; if (mode == CropMode.Fit) { float factor1 = ((float)w / (float)h); float factor2 = ((float)Width / (float)Height); if (factor1 > factor2) { h = newHeight; w = (int)((((float)h) / ((float)Height)) * Width); } else { w = newWidth; h = (int)((((float)w) / ((float)Width)) * Height); } } else if (mode == CropMode.Cover) { float factor1 = ((float)w / (float)h); float factor2 = ((float)Width / (float)Height); if (factor1 > factor2) { w = newWidth; h = (int)((((float)w) / ((float)Width)) * Height); } else { h = newHeight; w = (int)((((float)h) / ((float)Height)) * Width); } } this.Resample(filter, w, h); Color *myPointer = (Color *)Bytes.ToPointer(); var copy = Marshal.AllocHGlobal(w * h * PixelSize); Color *copyPointer = (Color *)copy.ToPointer(); Buffer.MemoryCopy(myPointer, copyPointer, w * h * PixelSize, w * h * PixelSize); this.InternalResize(newWidth, newHeight); myPointer = (Color *)Bytes.ToPointer(); int ox = (newWidth - w) / 2; int oy = (newHeight - h) / 2; for (int y = 0; y < newHeight; y++) { for (int x = 0; x < newWidth; x++) { if (x >= ox && x < ox + w && y >= oy && y < oy + h) { *(myPointer + x + y * newWidth) = *(copyPointer + (x - ox) + (y - oy) * w); } else { *(myPointer + x + y * newWidth) = new Color(0, 0, 0, 0); } } } }
private static string GetFileName(string size, CropMode mode) => string.IsNullOrEmpty(size) ? "originalImage" : $"{size}({mode})";
/// <summary> /// Initializes a new instance of the <see cref="CropFilter"/> class. /// </summary> /// <param name="cropArea">The crop area.</param> public CropFilter(Rectangle cropArea) { this.CropArea = cropArea; this._cropMode = CropMode.Area; }
void SetMode(CropMode mode) { if (mode == Mode) { throw new Exception(string.Format("Crop Mode {0} requested, but already in that mode.", mode)); } switch (mode) { case CropMode.Editing: { // if we're entering Editing for the first time, setup is simple. if (Mode == CropMode.None) { // fade in the blocker, which will help the user // see what they're supposed to be doing AnimateBlocker(true); } // If we're coming BACK from previewing if (Mode == CropMode.Previewing) { // Then we need to reverse the animation we played to crop the image. UIView.Animate(.5f, 0, UIViewAnimationOptions.CurveEaseInOut, // ANIMATING new Action(delegate { // animate the cropped image down to its original size. ImageView.Frame = CropView.Frame; }) // DONE ANIMATING , new Action(delegate { // done, so now set the original image (which will // seamlessly replace the cropped image) ImageView.Frame = GetImageViewFrame( ); ImageView.Image = SourceImage; // and turn on the blocker fully, so we still only see // the cropped part of the image FullscreenBlocker.Layer.Opacity = 1.00f; // and finally animate down the blocker, so it restores // the original editing appearance AnimateBlocker(true); }) ); } break; } case CropMode.Previewing: { // create the cropped image CroppedImage = CropImage(SourceImage, new CGRect(CropView.Frame.X - CropViewMinPos.X, CropView.Frame.Y - CropViewMinPos.Y, CropView.Frame.Width, CropView.Frame.Height)); // Kick off an animation that will simulate cropping and scaling up the image. UIView.Animate(.5f, 0, UIViewAnimationOptions.CurveEaseInOut, // ANIMATING new Action(delegate { // animate in the blocker fully, which will black out the non-cropped parts of the image. FullscreenBlocker.Layer.Opacity = 1.00f; // fade out the cropper border CropView.Layer.Opacity = 0.00f; }) // DONE ANIMATING , new Action(delegate { // set the scaled cropped image, seamlessly replacing full image ImageView.Frame = CropView.Frame; ImageView.Image = CroppedImage; // and turn off the blocker completely (nothing to block now, since we're literally using // the cropped image FullscreenBlocker.Layer.Opacity = 0.00f; // and kick off a final (chained) animation that scales UP the cropped image to fill the viewport. UIView.Animate(.5f, 0, UIViewAnimationOptions.CurveEaseInOut, new Action(delegate { ImageView.Frame = GetImageViewFrame( ); }), null); })); break; } } Mode = mode; }
void SetMode(CropMode mode) { if (mode == Mode) { throw new Exception(string.Format("Crop Mode {0} requested, but already in that mode.", mode)); } switch (mode) { case CropMode.Editing: { // If we're entering edit mode for the first time if (Mode == CropMode.None) { // Animate in the mask SimpleAnimator_Float floatAnimator = new SimpleAnimator_Float(MaskLayer.Opacity, MaskFadeAmount, MaskFadeTime, delegate(float percent, object value) { Rock.Mobile.Threading.Util.PerformOnUIThread(delegate { MaskLayer.Opacity = (float)value; }); }, null); floatAnimator.Start( ); // turn on our cropper CropView.Visibility = ViewStates.Visible; // and set the source image to the scaled source. ImageView.SetImageBitmap(ScaledSourceImage); } // else we're coming FROM Preview Mode, so we need to animate else { Animating = true; // setup the dimension changes System.Drawing.SizeF startSize = new System.Drawing.SizeF(ImageView.Width, ImageView.Height); System.Drawing.SizeF endSize = new System.Drawing.SizeF(CropView.Width, CropView.Height); PointF startPos = new PointF(ImageView.GetX( ), ImageView.GetY( )); PointF endPos = new PointF(CropView.GetX( ), CropView.GetY( )); // now animate the cropped image up to its full size AnimateImageView(ImageView, startPos, endPos, startSize, endSize, ImageAnimationTime, delegate { ImageView.SetImageBitmap(null); // release any cropped image we had. if (CroppedImage != null) { CroppedImage.Dispose( ); CroppedImage = null; } // release the scaled version if we had it if (ScaledCroppedImage != null) { ScaledCroppedImage.Dispose( ); ScaledCroppedImage = null; } ImageView.SetImageBitmap(ScaledSourceImage); ImageView.LayoutParameters.Width = ScaledSourceImage.Width; ImageView.LayoutParameters.Height = ScaledSourceImage.Height; // center the image ImageView.SetX((ScreenSize.Width - ImageView.LayoutParameters.Width) / 2); ImageView.SetY((ScreenSize.Height - ImageView.LayoutParameters.Height) / 2); MaskLayer.Visibility = ViewStates.Visible; CropView.Visibility = ViewStates.Visible; SimpleAnimator_Float floatAnimator = new SimpleAnimator_Float(MaskLayer.Opacity, MaskFadeAmount, MaskFadeTime, delegate(float percent, object value) { Rock.Mobile.Threading.Util.PerformOnUIThread(delegate { MaskLayer.Opacity = (float)value; CropView.Alpha = percent; }); }, // FINISHED MASK FADE-OUT delegate { Rock.Mobile.Threading.Util.PerformOnUIThread(delegate { Animating = false; }); }); floatAnimator.Start( ); }); } break; } case CropMode.Previewing: { // don't allow a state change while we're animating Animating = true; SimpleAnimator_Float floatAnimator = new SimpleAnimator_Float(MaskLayer.Opacity, 1.00f, MaskFadeTime, delegate(float percent, object value) { Rock.Mobile.Threading.Util.PerformOnUIThread(delegate { MaskLayer.Opacity = (float)value; CropView.Alpha = 1.0f - percent; }); }, // FINISHED MASK FADE-IN delegate { Rock.Mobile.Threading.Util.PerformOnUIThread(delegate { // hide the mask and cropper MaskLayer.Visibility = ViewStates.Gone; CropView.Visibility = ViewStates.Gone; // create the cropped image CroppedImage = CropImage(SourceImage, new System.Drawing.RectangleF(CropView.GetX( ) - CropViewMinPos.X, CropView.GetY( ) - CropViewMinPos.Y, CropView.LayoutParameters.Width, CropView.LayoutParameters.Height)); // create a scaled version of the cropped image float scaledWidth = (float)CroppedImage.Width * (1.0f / ScreenToImageScalar); float scaledHeight = (float)CroppedImage.Height * (1.0f / ScreenToImageScalar); ScaledCroppedImage = Bitmap.CreateScaledBitmap(CroppedImage, (int)scaledWidth, (int)scaledHeight, false); // set the scaled cropped image ImageView.SetImageBitmap(null); ImageView.SetImageBitmap(ScaledCroppedImage); // start the scaled cropped image scaled down further to match its size within the full image. ImageView.SetX(CropView.GetX( )); ImageView.SetY(CropView.GetY( )); ImageView.LayoutParameters.Width = CropView.Width; ImageView.LayoutParameters.Height = CropView.Height; // setup the dimension changes System.Drawing.SizeF startSize = new System.Drawing.SizeF(ScaledCroppedImage.Width, ScaledCroppedImage.Height); System.Drawing.SizeF endSize; if (ScreenSize.Width < ScreenSize.Height) { endSize = new System.Drawing.SizeF(ScreenSize.Width, (float)System.Math.Ceiling(ScreenSize.Width * (startSize.Width / startSize.Height))); } else { endSize = new System.Drawing.SizeF((float)System.Math.Ceiling(ScreenSize.Height * (startSize.Height / startSize.Width)), ScreenSize.Height); } PointF startPos = new PointF(CropView.GetX( ), CropView.GetY( )); PointF endPos = new PointF((ScreenSize.Width - endSize.Width) / 2, (ScreenSize.Height - endSize.Height) / 2); // now animate the cropped image up to its full size AnimateImageView(ImageView, startPos, endPos, startSize, endSize, ImageAnimationTime, delegate { Animating = false; }); }); }); floatAnimator.Start( ); break; } } Mode = mode; }
public frmUNIcastPlayer() { InitializeComponent(); // Load settings IniFile ini = new IniFile(Path.Combine(Environment.CurrentDirectory, IniFile)); string str = ini.IniReadValue(Section, KeyStream); if (!Address.TryParse(str, out streamAddress)) { streamAddress = DefaultStreamAddress; ini.IniWriteValue(Section, KeyStream, streamAddress.ToString()); } str = ini.IniReadValue(Section, KeyMessage); if (!Address.TryParse(str, out messageAddress)) { messageAddress = DefaultMessageAddress; ini.IniWriteValue(Section, KeyMessage, messageAddress.ToString()); } str = ini.IniReadValue(Section, KeyHWA); if (!Boolean.TryParse(str, out enableHWA)) { enableHWA = DefaultHWA; ini.IniWriteValue(Section, KeyHWA, enableHWA.ToString()); } Debug.WriteLine("streamAddress: " + streamAddress); Debug.WriteLine("messageAddress: " + messageAddress); Debug.WriteLine("HWA: " + enableHWA); // Last supported VLC version: VLC 2.0.8 "Twoflower" string[] args = new string[] { "-I", "dummy", "--ignore-config", // don't display file path "--no-video-title-show", // keep showing logo // http://stackoverflow.com/questions/15992874/logo-appears-for-only-a-second-and-then-disappears "--sub-filter=logo", // Caching value for network resources, in milliseconds. "--network-caching=60", // C:\Program Files (x86)\VideoLAN\VLC\plugins" @"--plugin-path=VLC_PLUGIN_PATH" }; // Enable hardware acceleration based on settings if (enableHWA) { List <string> argsList = args.ToList(); argsList.Add("--ffmpeg-hw"); args = argsList.ToArray(); } else { ibtnHWA.Visible = false; } instance = new VlcInstance(args); player = null; cropMode = CropMode.NoCropping; margin = this.Width - ucVLC.Width; this.MinimumSize = DefaultClientSize; Debug.WriteLine(LibVlc.GetLibVlcVersion()); media = new VlcMedia(instance, String.Format("udp://@{0}", streamAddress)); player = new VlcMediaPlayer(media); stoppedDelegate = new LibVlc.EventCallbackDelegate(MediaPlayerStopped); playingDelegate = new LibVlc.EventCallbackDelegate(MediaPlayerPlaying); player.EventAttach(LibVlc.libvlc_event_e.libvlc_MediaStateChanged, stoppedDelegate); player.EventAttach(LibVlc.libvlc_event_e.libvlc_MediaPlayerStopped, stoppedDelegate); player.EventAttach(LibVlc.libvlc_event_e.libvlc_MediaPlayerPlaying, playingDelegate); player.Drawable = ucVLC.Handle; //ucVLC.BringToFront(); player.Play(); multicastClient = new MulticastClient(messageAddress.IP, messageAddress.Port); multicastClient.OnInputPositionReceived += multicastClient_OnInputPositionReceived; multicastClient.BeginReceive(); }
void SetMode( CropMode mode ) { if( mode == Mode ) { throw new Exception( string.Format( "Crop Mode {0} requested, but already in that mode.", mode ) ); } switch( mode ) { case CropMode.Editing: { // if we're entering Editing for the first time, setup is simple. if ( Mode == CropMode.None ) { // fade in the blocker, which will help the user // see what they're supposed to be doing AnimateBlocker( true ); } // If we're coming BACK from previewing if ( Mode == CropMode.Previewing ) { // Then we need to reverse the animation we played to crop the image. UIView.Animate( .5f, 0, UIViewAnimationOptions.CurveEaseInOut, // ANIMATING new Action( delegate { // animate the cropped image down to its original size. ImageView.Frame = CropView.Frame; } ) // DONE ANIMATING , new Action( delegate { // done, so now set the original image (which will // seamlessly replace the cropped image) ImageView.Frame = GetImageViewFrame( ); ImageView.Image = SourceImage; // and turn on the blocker fully, so we still only see // the cropped part of the image FullscreenBlocker.Layer.Opacity = 1.00f; // and finally animate down the blocker, so it restores // the original editing appearance AnimateBlocker( true ); } ) ); } break; } case CropMode.Previewing: { // create the cropped image CroppedImage = CropImage( SourceImage, new CGRect( CropView.Frame.X - CropViewMinPos.X, CropView.Frame.Y - CropViewMinPos.Y, CropView.Frame.Width , CropView.Frame.Height ) ); // Kick off an animation that will simulate cropping and scaling up the image. UIView.Animate( .5f, 0, UIViewAnimationOptions.CurveEaseInOut, // ANIMATING new Action( delegate { // animate in the blocker fully, which will black out the non-cropped parts of the image. FullscreenBlocker.Layer.Opacity = 1.00f; // fade out the cropper border CropView.Layer.Opacity = 0.00f; } ) // DONE ANIMATING , new Action( delegate { // set the scaled cropped image, seamlessly replacing full image ImageView.Frame = CropView.Frame; ImageView.Image = CroppedImage; // and turn off the blocker completely (nothing to block now, since we're literally using // the cropped image FullscreenBlocker.Layer.Opacity = 0.00f; // and kick off a final (chained) animation that scales UP the cropped image to fill the viewport. UIView.Animate( .5f, 0, UIViewAnimationOptions.CurveEaseInOut, new Action( delegate { ImageView.Frame = GetImageViewFrame( ); } ), null ); } ) ); break; } } Mode = mode; }