public static Vector2 ScaleFromTo(Vector2 from, Vector2 to, ScaleMode scaleMode = ScaleMode.StretchToFill) { Vector2 scale = Vector2.one; scale.x = to.x / from.x; scale.y = to.y / from.y; switch (scaleMode) { case ScaleMode.ScaleAndCrop: scale.x = scale.y = Mathf.Max(scale.x, scale.y); break; case ScaleMode.ScaleToFit: scale.x = scale.y = Mathf.Min(scale.x, scale.y); break; case ScaleMode.StretchToFill: //Do nothing break; default: Debug.LogException(new System.NotImplementedException("The Received ScaleMode." + scaleMode.ToString() + " is not implemented.")); break; } return scale; }
public void Initialize(Vector2 referenceButtonSize, Vector2 referenceScreenSize, int scaleMode) { this.referenceButtonSize = referenceButtonSize; this.referenceScreenSize = referenceScreenSize; this.scaleMode = (ScaleMode)scaleMode; SetNewButtonSize(); }
// from http://blogs.wankuma.com/ch3cooh/archive/2008/07/07/147667.aspx public static Image GetScaledImage(Image srcImg, int maxW, int maxH, ScaleMode mode) { int srcW = srcImg.Width; int srcH = srcImg.Height; Rectangle srcRect = new Rectangle(0, 0, srcW, srcH); int dstW, dstH; // FIXME 正方形の画像の場合は? // fitのときに横方向がはみ出す(縦に合わせられる)場合がある if ((srcW > srcH && mode == ScaleMode.Fit) || (srcH > srcW && mode == ScaleMode.Full)) { dstW = maxW; dstH = (int)(((float)dstW / (float)srcW) * srcH); } else { dstH = maxH; dstW = (int)(((float)dstH / (float)srcH) * srcW); } Image dstImg = new Bitmap(dstW, dstH, PixelFormat.Format16bppRgb565); Rectangle dstRect = new Rectangle(0, 0, dstW, dstH); Graphics g = Graphics.FromImage(dstImg); g.DrawImage(srcImg, dstRect, srcRect, GraphicsUnit.Pixel); g.Dispose(); return dstImg; }
public GalleryModelBuilder(String baseHttpUrl, String siteName, String galleryHttpRootPath, String contentFilePath, String galleryRootFilePath, ScaleMode scaledImageScaleMode, double scaledImageWidth, double scaledImagedHeight, ScaleMode thumbScaleMode, double thumbImageWidth, double thumbImagedHeight) { _contentFilePath = contentFilePath; _baseHttpUrl = baseHttpUrl; _galleryContentRootFilePath = galleryRootFilePath; _galleryContentRootHttpPath = galleryHttpRootPath; _galleryHttpPathFormat = Settings.Default.Http_GalleryHttpPathFormat; _galleryHttpEnhancedPathFormat = Settings.Default.Http_GalleryHttpEnhancedPathFormat; _galleriesIndexHttpPathFormat = Settings.Default.Http_GalleriesIndexHttpPathFormat; _galleryCoverFileName = Settings.Default.File_GalleryCoverFileName; _imageFileTypeFilter = Settings.Default.Image_FileTypeFilter; _galleryFolderOriginalImages = Settings.Default.Folders_OringinalImages; _galleryFolderScaledImages = Settings.Default.Folders_ScaledImages; _galleryFolderThumbs = Settings.Default.Folders_Thumbs; _zipFileLQFormat = Settings.Default.Zip_FileNameFormat_LowQuality; _zipFileHQFormat = Settings.Default.Zip_FileNameFormat_HighQuality; _galleriesIndexHttpPath = String.Format(_galleriesIndexHttpPathFormat, _baseHttpUrl); _imageProcessor = new GalleryImageProcessor(scaledImageScaleMode, scaledImageWidth, scaledImagedHeight, thumbScaleMode, thumbImageWidth, thumbImagedHeight); _dataProcessor = new GalleryDataProcessor(); _feedBuilder = new GalleryFeedBuilder(siteName, _galleriesIndexHttpPath); _coverRenderer = new GalleryCoverRenderer(_contentFilePath); }
/// <summary> /// Creates a new instance of FeatureSymbolizer /// </summary> protected FeatureSymbolizer() { _scaleMode = ScaleMode.Simple; _smoothing = true; _isVisible = true; _unit = GraphicsUnit.Pixel; }
private static Rectangle CalculateSourceRect(Size sourceImage, Size thumbImage, ScaleMode scaleMode) { int previewHeight = thumbImage.Height; int previewWidth = thumbImage.Width; switch (scaleMode) { case ScaleMode.Crop: double wRatio = (double)sourceImage.Width / previewWidth; double hRatio = (double)sourceImage.Height / previewHeight; double coef = (double)previewHeight / previewWidth; int resultWidth; int resultHeight; if (wRatio < hRatio) { resultWidth = sourceImage.Width; resultHeight = (int)Math.Truncate(sourceImage.Width * coef); return new Rectangle(0, (sourceImage.Height - resultHeight) / 2, resultWidth, resultHeight); } else { resultHeight = sourceImage.Height; resultWidth = (int)Math.Truncate(sourceImage.Height / coef); return new Rectangle((sourceImage.Width - resultWidth) / 2, 0, resultWidth, resultHeight); } case ScaleMode.Insert: return new Rectangle(0, 0, sourceImage.Width, sourceImage.Height); default: return new Rectangle(0, 0, sourceImage.Width, sourceImage.Height); } }
public void init(Vector2 butSize, Vector2 screenSize, ScaleMode scaleMode) { refButtonSize = butSize; refScreenSize = screenSize; smode = scaleMode; setButtonSize(); }
public static UrlBuilder Scale(this UrlBuilder target, ScaleMode mode) { if(target == null) throw new ArgumentNullException(nameof(target)); target.QueryCollection.Add("scale", AddScaleString(mode)); return target; }
public void endDrag() { if (scaleMode == ScaleMode.none) return; scaleMode = ScaleMode.none; editableObject.draged = false; this.enabled = false; editableObject.rigidbody.detectCollisions = true; }
/// <summary> /// /// </summary> /// <param name="position"></param> /// <param name="size"></param> /// <param name="tex"></param> /// <param name="texCoords"></param> /// <param name="scaleMode"></param> /// <param name="drawAlpha"></param> /// <param name="drawTransparent"></param> /// <param name="mat"></param> public Image( Vector2 position, Vector2 size, Texture tex = null, Rect? texCoords = null, ScaleMode scaleMode = ScaleMode.ScaleToFit, bool drawAlpha = false, bool drawTransparent = true, Material mat = null ) : base( position, size ) { DrawTexture = tex; Scale = scaleMode; DrawAlpha = drawAlpha; DrawTransparent = drawTransparent; DrawMaterial = mat; TexCoords = texCoords; }
public BasicButtonGUI(Rect r, Texture down, Texture up, Texture disableDown, Texture disableUp, bool bKeepSt = true) { TexDown = down; TexUp = up; TexDownDisable = disableDown; TexUpDisable = disableUp; rec = r; mKeepState = bKeepSt; scaleMode = ScaleMode.ScaleToFit; disableOnMouseMove = true; }
public override void Reset() { texture = null; left = 0; top = 0; width = 1; height = 1; scaleMode = ScaleMode.StretchToFill; alphaBlend = true; imageAspect = 0; normalized = true; }
//----------------------------------------------------- // Affiche une texture tilée. A appeler d'un OnGUI // (la texture sera devant toutes les GUITextures). public static void TileGUItexture(Texture texture, Rect tile, Rect areaToFill, ScaleMode scaleMode) { // Tiles an <areaToFill> with a <texture> which is scaled to the size // of a <tile> using a given <scaleMode>. Author: Isaac Manning Dart for (float y = areaToFill.y; y < areaToFill.y + areaToFill.height; y = y + tile.height) { for (float x = areaToFill.x; x < areaToFill.x + areaToFill.width; x = x + tile.width) { tile.x = x; tile.y = y; GUI.DrawTexture(tile, texture, scaleMode); } } }
public override void Reset() { this.texture = null; this.screenRect = null; this.left = 0f; this.top = 0f; this.width = 1f; this.height = 1f; this.scaleMode = ScaleMode.StretchToFill; this.alphaBlend = true; this.imageAspect = 0f; this.normalized = true; }
public GalleryImageProcessor(ScaleMode scaledImageScaleMode, double scaledImageWidth, double scaledImagedHeight, ScaleMode thumbScaleMode, double thumbImageWidth, double thumbImagedHeight) { _scaledImageScaleMode = scaledImageScaleMode; _scaledImageWidth = scaledImageWidth; _scaledImagedHeight = scaledImagedHeight; _thumbScaleMode = thumbScaleMode; _thumbImageWidth = thumbImageWidth; _thumbImageHeight = thumbImagedHeight; }
public FlexPaginator(C1FlexGrid flex, ScaleMode scaleMode, Size pageSize, Thickness margin, int maxPages) { // save parameters _margin = margin; _scaleMode = scaleMode; _pageSize = pageSize; // adjust page size for margins before building grid images pageSize.Width -= (margin.Left + margin.Right); pageSize.Height -= (margin.Top + margin.Bottom); // get grid images for each page _pages = flex.GetPageImages(scaleMode, pageSize, maxPages); }
private static string AddScaleString(ScaleMode value) { if(value == ScaleMode.Both) return "both"; if(value == ScaleMode.DownscaleOnly) return "down"; if(value == ScaleMode.UpscaleCanvas) return "canvas"; if(value == ScaleMode.UpscaleOnly) return "up"; throw new NotImplementedException("Unrecognized ScaleMode value: " + value); }
private static Rectangle CalculateSourceRect(string name, Size sourceImage, ScaleMode scaleMode) { int previewHeight = limitHeight.ContainsKey(name) ? limitHeight[name] : 0; int previewWidth = limitWidth.ContainsKey(name) ? limitWidth[name] : 0; int resultWidth; int resultHeight; if (scaleMode == ScaleMode.Cut) { double wRatio = (double)sourceImage.Width / (double)previewWidth; double hRatio = (double)sourceImage.Height / (double)previewHeight; double coef = (double)previewHeight / (double)previewWidth; if (wRatio < hRatio) { resultWidth = sourceImage.Width; resultHeight = (int)Math.Truncate(sourceImage.Width * coef); } else { resultHeight = sourceImage.Height; resultWidth = (int)Math.Truncate(sourceImage.Height / coef); } return new Rectangle(0, 0, resultWidth, resultHeight); } else { if (sourceImage.Width > sourceImage.Height) { int shift = (int)Math.Truncate((sourceImage.Width - sourceImage.Height) / (double)2); return new Rectangle(0, -shift, sourceImage.Width, sourceImage.Height + shift * 2); } else { int shift = (int)Math.Truncate((sourceImage.Height - sourceImage.Width) / (double)2); return new Rectangle(-shift, 0, sourceImage.Width + shift * 2, sourceImage.Height); } } }
public ImageView(ImageView imageView) { LeftMargin = imageView.LeftMargin; TopMargin = imageView.TopMargin; RightMargin = imageView.RightMargin; BottomMargin = imageView.BottomMargin; Width = imageView.Width; Height = imageView.Height; Position = imageView.Position; Scale = imageView.Scale; Offset = imageView.Offset; ImageTexture = imageView.ImageTexture; ImageRect = imageView.ImageRect; ImageScaleMode = imageView.ImageScaleMode; IsDirty = imageView.IsDirty; Rect = imageView.Rect; }
/// <summary> /// Sets the rectangle for this item /// <summary> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <param name="w">The width.</param> /// <param name="h">The height.</param> public virtual void SetRectangle(float x, float y, float w, float h, bool isWorld, ScaleMode scale) { Scale = scale; WorldCoords = Vector2.zero; IsWorld = isWorld; if (w <= 1 && h <= 1 ) { w = Screen.width * w; h = Screen.height * h; } if (isWorld) { WorldCoords = new Vector2(x, y); } else { if (x <= 1 && y <= 1) { x = Screen.width * x; y = Screen.height * y; } } if (Scale == ScaleMode.ScaleToFit) { if (Content.image != null) { float r = Math.Min(w / Content.image.width, h / Content.image.height); w = Content.image.width * r; h = Content.image.height * r; } } Rectangle = new Rect(x, y, w, h); }
private static Rectangle CalculateDestRect(Size sourceImage, Size thumbImage, ScaleMode scaleMode, int delta) { double hvr = (double)sourceImage.Width / (double)sourceImage.Height; switch (scaleMode) { case ScaleMode.Insert: thumbImage.Width -= delta * 2; thumbImage.Height -= delta * 2; double hRatio = (double)thumbImage.Height / sourceImage.Height; double wRatio = (double)thumbImage.Width / sourceImage.Width; double ratio = hRatio < wRatio ? hRatio : wRatio; int resultSourceImageWidth = (int)(sourceImage.Width * ratio); var resultSourceImageHeight = (int)(sourceImage.Height * ratio); if (thumbImage.Width > resultSourceImageWidth) { int offset = ((thumbImage.Width + delta * 2) - resultSourceImageWidth) / 2; return new Rectangle(offset, 0 + delta, resultSourceImageWidth, resultSourceImageHeight); } if (thumbImage.Height > resultSourceImageHeight) { var offset = ((thumbImage.Height + delta * 2) - resultSourceImageHeight) / 2; return new Rectangle(0 + delta, offset, resultSourceImageWidth, resultSourceImageHeight); } break; case ScaleMode.FixedWidth: int destImageHeight = (int)(thumbImage.Width / hvr); return new Rectangle(0, 0, thumbImage.Width, destImageHeight); case ScaleMode.FixedHeight: int destImageWidth = (int)(thumbImage.Height * hvr); return new Rectangle(0, 0, destImageWidth, thumbImage.Height); } return new Rectangle(0, 0, thumbImage.Width, thumbImage.Height); }
public MainWindow() { InitializeComponent(); CreateDXPlayer(); GlobalEnv.ReadConfiguration(); sliderTimeline.Value = 0; sliderTimeline.IsEnabled = false; ShowPlayTime(0.0); sliderVolume.Minimum = 0; sliderVolume.Maximum = 0xFFFF; sliderVolume.Value = GlobalEnv.audioVolume; isWindowToVideoSize = GlobalEnv.isWindowToVideoSize == 0 ? false : true; IsRecording = null; scaleMode = (ScaleMode)GlobalEnv.scale_mode; aspectRatio = (AspectRatioType)GlobalEnv.aspect_ratio; Left = GlobalEnv.windowLocation.Left; Top = GlobalEnv.windowLocation.Top; gridMain.Width = GlobalEnv.windowLocation.Width; gridMain.Height = GlobalEnv.windowLocation.Height; SizeToContent = System.Windows.SizeToContent.WidthAndHeight; State = PLAYER_STATE.STATE_STOPPED; EventManager.RegisterClassHandler(typeof(Control), Control.PreviewKeyDownEvent, new KeyEventHandler(winMain_KeyDown)); EventManager.RegisterClassHandler(typeof(Control), Control.PreviewMouseWheelEvent, new MouseWheelEventHandler(winMain_MouseWheel)); }
private Vector4 GetDrawingDimensions(ScaleMode scaleMode, ref Rect uvRect) { Vector4 returnSize = Vector4.zero; if (mainTexture != null) { var padding = Vector4.zero; var textureSize = new Vector2(mainTexture.width, mainTexture.height); { // Adjust textureSize based on orientation #if UNITY_PLATFORM_SUPPORTS_VIDEOTRANSFORM if (HasValidTexture()) { Matrix4x4 m = Helper.GetMatrixForOrientation(Helper.GetOrientation(_mediaPlayer.Info.GetTextureTransform())); textureSize = m.MultiplyVector(textureSize); textureSize.x = Mathf.Abs(textureSize.x); textureSize.y = Mathf.Abs(textureSize.y); } #endif // Adjust textureSize based on alpha packing if (_mediaPlayer != null) { if (_mediaPlayer.m_AlphaPacking == AlphaPacking.LeftRight || _mediaPlayer.m_StereoPacking == StereoPacking.LeftRight) { textureSize.x /= 2f; } else if (_mediaPlayer.m_AlphaPacking == AlphaPacking.TopBottom || _mediaPlayer.m_StereoPacking == StereoPacking.TopBottom) { textureSize.y /= 2f; } } } Rect r = GetPixelAdjustedRect(); // Fit the above textureSize into rectangle r int spriteW = Mathf.RoundToInt(textureSize.x); int spriteH = Mathf.RoundToInt(textureSize.y); var size = new Vector4(padding.x / spriteW, padding.y / spriteH, (spriteW - padding.z) / spriteW, (spriteH - padding.w) / spriteH); { if (textureSize.sqrMagnitude > 0.0f) { if (scaleMode == ScaleMode.ScaleToFit) { float spriteRatio = textureSize.x / textureSize.y; float rectRatio = r.width / r.height; if (spriteRatio > rectRatio) { float oldHeight = r.height; r.height = r.width * (1.0f / spriteRatio); r.y += (oldHeight - r.height) * rectTransform.pivot.y; } else { float oldWidth = r.width; r.width = r.height * spriteRatio; r.x += (oldWidth - r.width) * rectTransform.pivot.x; } } else if (scaleMode == ScaleMode.ScaleAndCrop) { float aspectRatio = textureSize.x / textureSize.y; float screenRatio = r.width / r.height; if (screenRatio > aspectRatio) { float adjust = aspectRatio / screenRatio; uvRect = new Rect(uvRect.xMin, (uvRect.yMin * adjust) + (1f - adjust) * 0.5f, uvRect.width, adjust * uvRect.height); } else { float adjust = screenRatio / aspectRatio; uvRect = new Rect(uvRect.xMin * adjust + (0.5f - adjust * 0.5f), uvRect.yMin, adjust * uvRect.width, uvRect.height); } } } } returnSize = new Vector4(r.x + r.width * size.x, r.y + r.height * size.y, r.x + r.width * size.z, r.y + r.height * size.w); } return(returnSize); }
public static RectangleParams MakeTextured(Rect rect, Rect uv, Texture texture, ScaleMode scaleMode, ContextType panelContext) { var playmodeTintColor = panelContext == ContextType.Editor ? UIElementsUtility.editorPlayModeTintColor : Color.white; // Fill the UVs according to scale mode // Comparing aspects ratio is error-prone because the screenRect may end up being scaled by the // transform and the corners will end up being pixel aligned, possibly resulting in blurriness. float srcAspect = (texture.width * uv.width) / (texture.height * uv.height); float destAspect = rect.width / rect.height; switch (scaleMode) { case ScaleMode.StretchToFill: break; case ScaleMode.ScaleAndCrop: if (destAspect > srcAspect) { float stretch = uv.height * (srcAspect / destAspect); float crop = (uv.height - stretch) * 0.5f; uv = new Rect(uv.x, uv.y + crop, uv.width, stretch); } else { float stretch = uv.width * (destAspect / srcAspect); float crop = (uv.width - stretch) * 0.5f; uv = new Rect(uv.x + crop, uv.y, stretch, uv.height); } break; case ScaleMode.ScaleToFit: if (destAspect > srcAspect) { float stretch = srcAspect / destAspect; rect = new Rect(rect.xMin + rect.width * (1.0f - stretch) * .5f, rect.yMin, stretch * rect.width, rect.height); } else { float stretch = destAspect / srcAspect; rect = new Rect(rect.xMin, rect.yMin + rect.height * (1.0f - stretch) * .5f, rect.width, stretch * rect.height); } break; default: throw new NotImplementedException(); } var rp = new RectangleParams { rect = rect, uv = uv, color = Color.white, texture = texture, scaleMode = scaleMode, playmodeTintColor = playmodeTintColor }; return(rp); }
public static IMImage DrawTexture(this VisualTreeBuilder cache, Rect position, Texture image, ScaleMode scaleMode, bool alphaBlend, float imageAspect) { IMImage iMImage; cache.NextElement <IMImage>(out iMImage); iMImage.position = position; iMImage.image = image; iMImage.scaleMode = scaleMode; iMImage.alphaBlend = alphaBlend; iMImage.imageAspect = imageAspect; return(iMImage); }
private static bool CacheImage(string originalPath, string fileName, string cacheFolder, PictureSize thumbnailImageSize, ScaleMode scaleMode, bool useBgImage, int delta) { string sourcePath = Path.Combine(HttpContext.Current.Server.MapPath(originalPath), fileName); Bitmap image; using (FileStream stream = new FileStream(sourcePath, FileMode.Open)) { image = new Bitmap(stream); } string cachePath = HttpContext.Current.Server.MapPath("~/ImageCache/" + cacheFolder); if (!Directory.Exists(cachePath)) Directory.CreateDirectory(cachePath); string cachedImagePath = Path.Combine(cachePath, fileName); using (FileStream stream = new FileStream(cachedImagePath, FileMode.CreateNew)) { return ScaleImage(cacheFolder, image, new Size(thumbnailImageSize.Width, thumbnailImageSize.Height), stream, scaleMode, useBgImage, delta); } }
private static void ScaleAndSaveOriginalImage(Bitmap image, Stream saveTo, int width, int height, ScaleMode scaleMode) { Size thumbImage = new Size(width, height); int delta = 0; Rectangle sourceRect = CalculateSourceRect(image.Size, thumbImage, scaleMode); //Rectangle sourceRect = new Rectangle(0, 0, image.Width, image.Height); Rectangle destRect = CalculateDestRect(image.Size, thumbImage, scaleMode, delta); //Rectangle destRect; //int resultSourceImageWidth = image.Width; //int resultSourceImageHeight = image.Height; //if (image.Width <= width && image.Height <= height) //{ // destRect = new Rectangle(0, 0, image.Width, image.Height); //} //else //{ // double wRatio = (double)width / image.Width; // ? // double hRatio = (double)height / image.Height; // ? // double ratio = hRatio < wRatio ? hRatio : wRatio; // resultSourceImageWidth = (int)(image.Width * ratio); // resultSourceImageHeight = (int)(image.Height * ratio); // destRect = new Rectangle(0, 0, resultSourceImageWidth, resultSourceImageHeight); //} //Bitmap thumbnailImage = new Bitmap(resultSourceImageWidth, resultSourceImageHeight); //System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(thumbnailImage); //graphics.FillRectangle(new SolidBrush(Color.White), 0, 0, resultSourceImageWidth, resultSourceImageHeight); //graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; //graphics.DrawImage(image, destRect, sourceRect, GraphicsUnit.Pixel); //thumbnailImage.Save(saveTo, System.Drawing.Imaging.ImageFormat.Jpeg); //saveTo.Position = 0; Bitmap thumbnailImage; if (scaleMode == ScaleMode.Insert) thumbnailImage = new Bitmap(thumbImage.Width, thumbImage.Height); else thumbnailImage = new Bitmap(destRect.Width, destRect.Height); System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(thumbnailImage); if (scaleMode == ScaleMode.Insert) graphics.FillRectangle(new SolidBrush(Color.White), 0, 0, thumbImage.Width, thumbImage.Height); else graphics.FillRectangle(new SolidBrush(Color.White), 0, 0, destRect.Width, destRect.Height); graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; graphics.DrawImage(image, destRect, sourceRect, GraphicsUnit.Pixel); thumbnailImage.Save(saveTo, System.Drawing.Imaging.ImageFormat.Jpeg); saveTo.Position = 0; }
public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hashCode = 41; if (Type != null) { hashCode = hashCode * 59 + Type.GetHashCode(); } if (Visible != null) { hashCode = hashCode * 59 + Visible.GetHashCode(); } if (ShowLegend != null) { hashCode = hashCode * 59 + ShowLegend.GetHashCode(); } if (LegendGroup != null) { hashCode = hashCode * 59 + LegendGroup.GetHashCode(); } if (Opacity != null) { hashCode = hashCode * 59 + Opacity.GetHashCode(); } if (UId != null) { hashCode = hashCode * 59 + UId.GetHashCode(); } if (Ids != null) { hashCode = hashCode * 59 + Ids.GetHashCode(); } if (CustomData != null) { hashCode = hashCode * 59 + CustomData.GetHashCode(); } if (Meta != null) { hashCode = hashCode * 59 + Meta.GetHashCode(); } if (MetaArray != null) { hashCode = hashCode * 59 + MetaArray.GetHashCode(); } if (SelectedPoints != null) { hashCode = hashCode * 59 + SelectedPoints.GetHashCode(); } if (HoverInfo != null) { hashCode = hashCode * 59 + HoverInfo.GetHashCode(); } if (HoverInfoArray != null) { hashCode = hashCode * 59 + HoverInfoArray.GetHashCode(); } if (HoverLabel != null) { hashCode = hashCode * 59 + HoverLabel.GetHashCode(); } if (Stream != null) { hashCode = hashCode * 59 + Stream.GetHashCode(); } if (Transforms != null) { hashCode = hashCode * 59 + Transforms.GetHashCode(); } if (UiRevision != null) { hashCode = hashCode * 59 + UiRevision.GetHashCode(); } if (Y != null) { hashCode = hashCode * 59 + Y.GetHashCode(); } if (X != null) { hashCode = hashCode * 59 + X.GetHashCode(); } if (X0 != null) { hashCode = hashCode * 59 + X0.GetHashCode(); } if (Y0 != null) { hashCode = hashCode * 59 + Y0.GetHashCode(); } if (Name != null) { hashCode = hashCode * 59 + Name.GetHashCode(); } if (Orientation != null) { hashCode = hashCode * 59 + Orientation.GetHashCode(); } if (Bandwidth != null) { hashCode = hashCode * 59 + Bandwidth.GetHashCode(); } if (ScaleGroup != null) { hashCode = hashCode * 59 + ScaleGroup.GetHashCode(); } if (ScaleMode != null) { hashCode = hashCode * 59 + ScaleMode.GetHashCode(); } if (SpanMode != null) { hashCode = hashCode * 59 + SpanMode.GetHashCode(); } if (Span != null) { hashCode = hashCode * 59 + Span.GetHashCode(); } if (Line != null) { hashCode = hashCode * 59 + Line.GetHashCode(); } if (FillColor != null) { hashCode = hashCode * 59 + FillColor.GetHashCode(); } if (Points != null) { hashCode = hashCode * 59 + Points.GetHashCode(); } if (Jitter != null) { hashCode = hashCode * 59 + Jitter.GetHashCode(); } if (PointPos != null) { hashCode = hashCode * 59 + PointPos.GetHashCode(); } if (Width != null) { hashCode = hashCode * 59 + Width.GetHashCode(); } if (Marker != null) { hashCode = hashCode * 59 + Marker.GetHashCode(); } if (Text != null) { hashCode = hashCode * 59 + Text.GetHashCode(); } if (TextArray != null) { hashCode = hashCode * 59 + TextArray.GetHashCode(); } if (HoverText != null) { hashCode = hashCode * 59 + HoverText.GetHashCode(); } if (HoverTextArray != null) { hashCode = hashCode * 59 + HoverTextArray.GetHashCode(); } if (HoverTemplate != null) { hashCode = hashCode * 59 + HoverTemplate.GetHashCode(); } if (HoverTemplateArray != null) { hashCode = hashCode * 59 + HoverTemplateArray.GetHashCode(); } if (Box != null) { hashCode = hashCode * 59 + Box.GetHashCode(); } if (MeanLine != null) { hashCode = hashCode * 59 + MeanLine.GetHashCode(); } if (Side != null) { hashCode = hashCode * 59 + Side.GetHashCode(); } if (OffsetGroup != null) { hashCode = hashCode * 59 + OffsetGroup.GetHashCode(); } if (AlignmentGroup != null) { hashCode = hashCode * 59 + AlignmentGroup.GetHashCode(); } if (Selected != null) { hashCode = hashCode * 59 + Selected.GetHashCode(); } if (Unselected != null) { hashCode = hashCode * 59 + Unselected.GetHashCode(); } if (HoverOn != null) { hashCode = hashCode * 59 + HoverOn.GetHashCode(); } if (XAxis != null) { hashCode = hashCode * 59 + XAxis.GetHashCode(); } if (YAxis != null) { hashCode = hashCode * 59 + YAxis.GetHashCode(); } if (IdsSrc != null) { hashCode = hashCode * 59 + IdsSrc.GetHashCode(); } if (CustomDataSrc != null) { hashCode = hashCode * 59 + CustomDataSrc.GetHashCode(); } if (MetaSrc != null) { hashCode = hashCode * 59 + MetaSrc.GetHashCode(); } if (HoverInfoSrc != null) { hashCode = hashCode * 59 + HoverInfoSrc.GetHashCode(); } if (YSrc != null) { hashCode = hashCode * 59 + YSrc.GetHashCode(); } if (XSrc != null) { hashCode = hashCode * 59 + XSrc.GetHashCode(); } if (TextSrc != null) { hashCode = hashCode * 59 + TextSrc.GetHashCode(); } if (HoverTextSrc != null) { hashCode = hashCode * 59 + HoverTextSrc.GetHashCode(); } if (HoverTemplateSrc != null) { hashCode = hashCode * 59 + HoverTemplateSrc.GetHashCode(); } return(hashCode); } }
/// <summary> /// Helper function that creates a sprite that will contain a texture from the TextureCache /// based on the frameId The frame ids are created when a Texture packer file has been loaded. /// </summary> /// <param name="imageId">The image url of the texture.</param> /// <param name="crossorigin">if you want to specify the cross-origin parameter.</param> /// <param name="scaleMode">The scale mode of the texture.</param> /// <returns>A new Sprite using a texture from the texture cache matching the frameId.</returns> public static extern Sprite FromImage(string imageId, bool crossorigin = false, ScaleMode scaleMode = ScaleMode.Default);
/// <summary> /// Draws texture using the built-in <see cref="GUI"/> class. /// </summary> public static void DrawTexture(Rect rect, Texture texture, ScaleMode scaleMode, bool alphaBlend) { GUI.DrawTexture(rect, texture, scaleMode, alphaBlend); }
/// <summary> /// Draws texture using the built-in <see cref="GUI"/> class. /// </summary> public static void DrawTexture(Rect rect, Texture texture, ScaleMode scaleMode) { DrawTexture(rect, texture, scaleMode, true); }
public static void DrawTexture(Rect position, Texture image, ScaleMode scaleMode, bool alphaBlend, float imageAspect) { }
public static Texture2D ScaledResized(Texture2D src, int width, int height, Color backgroundColor, float fillPercentage, FilterMode mode = FilterMode.Trilinear, ScaleMode anchor = ScaleMode.ScaleToFit) { var result = new Texture2D(width, height, TextureFormat.ARGB32, false); if (src == null) { Debug.LogWarning("Source texture is null"); return(result); } var rtt = CreateScaledTexture(src, width, height, backgroundColor, fillPercentage, mode, anchor); var texR = new Rect(0, 0, width, height); result.ReadPixels(texR, 0, 0, true); result.Apply(false); RenderTexture.active = null; rtt.Release(); return(result); }
private static RenderTexture CreateScaledTexture(Texture2D src, int width, int height, Color backgroundColor, float fillPercentage, FilterMode fmode = FilterMode.Trilinear, ScaleMode scaleMode = ScaleMode.ScaleToFit) { src.filterMode = fmode; src.Apply(true); var rtt = new RenderTexture(width, height, 32); RenderTexture.active = rtt; GL.LoadPixelMatrix(0, width, height, 0); GL.Clear(true, true, backgroundColor); fillPercentage = scaleMode == ScaleMode.ScaleToFit ? Mathf.Clamp01(fillPercentage) : 1; var scaledWidth = width * fillPercentage; var scaledHeight = height * fillPercentage; var xOffset = (width - scaledWidth) / 2f; var yOffset = (height - scaledHeight) / 2f; DrawTexture(new Rect(xOffset, yOffset, scaledWidth, scaledHeight), src, scaleMode); return(rtt); }
public static Bitmap Scale([NotNull] this Image image, Size size, ScaleMode scaleMode, float position = 0) => image.Size == size && image is Bitmap bitmap ? bitmap : Scale(image, new BitmapFormat(size, image.PixelFormat), scaleMode, position);
private void mitemScaleFFMPEG_Checked(object sender, RoutedEventArgs e) { scaleMode = ScaleMode.FFMPEG; UpdateScaleMode(); }
public static void DrawTexture(Rect position, Texture image, ScaleMode scaleMode, bool alphaBlend) { DrawTexture(position, image, scaleMode, alphaBlend, 0f); }
public void SetImageOptions(Hashtable ht) { if(ht.ContainsKey(XMLHandler.CONTENT)) this.imageName = ht[XMLHandler.CONTENT] as string; if(ht.ContainsKey("scalemode")) this.scaleMode = (ScaleMode)System.Enum.Parse(typeof(ScaleMode), (string)ht["scalemode"]); if(ht.ContainsKey("alphablend")) this.alphaBlend = bool.Parse((string)ht["alphablend"]); if(ht.ContainsKey("imageaspect")) this.imageAspect = float.Parse((string)ht["imageaspect"]); }
/// <summary> /// 缩放、裁切图片 /// </summary> /// <param name="originalImage"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="mode"></param> /// <returns></returns> public static Image ResizeImageToAFixedSize(Image originalImage, int width, int height, ScaleMode mode) { GC.Collect(); int towidth = width; int toheight = height; int x = 0; int y = 0; int ow = originalImage.Width; int oh = originalImage.Height; switch (mode) { case ScaleMode.HW: break; case ScaleMode.W: if (height > 6000) { toheight = 6000; //变形 } else { toheight = originalImage.Height * width / originalImage.Width; //太大,作用空间内存太大 } break; case ScaleMode.H: towidth = originalImage.Width * height / originalImage.Height; break; case ScaleMode.Cut: if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight) { oh = originalImage.Height; ow = originalImage.Height * towidth / toheight; y = 0; x = (originalImage.Width - ow) / 2; } else { ow = originalImage.Width; oh = originalImage.Width * height / towidth; x = 0; y = (originalImage.Height - oh) / 2; } break; default: break; } //新建一个bmp图片 Image bitmap = new System.Drawing.Bitmap(towidth, toheight); //新建一个画布 Graphics g = System.Drawing.Graphics.FromImage(bitmap); //设置画布的描绘质量 g.CompositingQuality = CompositingQuality.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; //清空画布并以透明背景色填充 g.Clear(Color.Transparent); //在指定位置并且按指定大小绘制原图片的指定部分 g.DrawImage(originalImage, new Rectangle(0, 0, towidth, toheight), new Rectangle(x, y, ow, oh), GraphicsUnit.Pixel); g.Dispose(); return(bitmap); }
public static IRectGUIDrawer DrawTexture(this IRectGUIDrawer self, Rect position, Texture image, ScaleMode scaleMode) { GUI.DrawTexture(position, image, scaleMode); return(self); }
public static bool ScaleImage(string name, Bitmap image, Size thumbImage, Stream saveTo, ScaleMode scaleMode, bool useBgImage, int delta) { if (scaleMode == ScaleMode.Auto) { scaleMode = IsHorizontalImage(image.Size) ? ScaleMode.Crop : ScaleMode.Insert; } Rectangle sourceRect = CalculateSourceRect(image.Size, thumbImage, scaleMode); Rectangle destRect = CalculateDestRect(image.Size, thumbImage, scaleMode, delta); Bitmap thumbnailImage; if (useBgImage) { string backgroundImageSourcePath = Path.Combine(HttpContext.Current.Server.MapPath("~/Content/Images/bg"), "bg.jpg"); using (FileStream stream = new FileStream(backgroundImageSourcePath, FileMode.Open)) { thumbnailImage = new Bitmap(stream); System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(thumbnailImage); graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; graphics.DrawImage(image, destRect, sourceRect, GraphicsUnit.Pixel); thumbnailImage.Save(saveTo, System.Drawing.Imaging.ImageFormat.Jpeg); saveTo.Position = 0; } } else { if (scaleMode == ScaleMode.Insert) thumbnailImage = new Bitmap(thumbImage.Width, thumbImage.Height); else thumbnailImage = new Bitmap(destRect.Width, destRect.Height); System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(thumbnailImage); if (scaleMode == ScaleMode.Insert) graphics.FillRectangle(new SolidBrush(Color.White), 0, 0, thumbImage.Width, thumbImage.Height); else graphics.FillRectangle(new SolidBrush(Color.White), 0, 0, destRect.Width, destRect.Height); graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; graphics.DrawImage(image, destRect, sourceRect, GraphicsUnit.Pixel); thumbnailImage.Save(saveTo, System.Drawing.Imaging.ImageFormat.Jpeg); saveTo.Position = 0; } return true; }
public static Vector2 Scale(float Width = PreferredViewportWidth, float Height = PreferredViewportHeight, ScaleMode scaleMode = _scaleMode, int targetX = 0, int targetY = 0) { if (targetX == 0) { targetX = graphics.GraphicsDevice.Viewport.Width; } if (targetY == 0) { targetY = graphics.GraphicsDevice.Viewport.Height; } float h = targetX / Width; float v = targetY / Height; switch (scaleMode) { #pragma warning disable CS0162 // Unreachable code detected case ScaleMode.FitHorizontal: return(new Vector2(h, h)); case ScaleMode.FitVertical: return(new Vector2(v, v)); case ScaleMode.FitBoth: return((v * Width > targetX) ? new Vector2(h, h) : new Vector2(v, v)); case ScaleMode.Stretch: default: return(new Vector2(h, v)); #pragma warning restore CS0162 // Unreachable code detected } }
public static void SaveOriginalImageWithDefinedDimentions(string filePath, string fileName, HttpPostedFileBase file, int destinationWidth, int destinationHeight, ScaleMode scaleMode) { string tmpFilePath = HttpContext.Current.Server.MapPath("~/Content/tmpImages"); tmpFilePath = Path.Combine(tmpFilePath, fileName); file.SaveAs(tmpFilePath); Bitmap image; string sourcePath = Path.Combine(HttpContext.Current.Server.MapPath("~/Content/tmpImages"), fileName); using (FileStream stream = new FileStream(sourcePath, FileMode.Open)) { image = new Bitmap(stream); } using (FileStream stream = new FileStream(filePath, FileMode.CreateNew)) { ScaleAndSaveOriginalImage(image, stream, destinationWidth, destinationHeight, scaleMode); } IOHelper.DeleteFile("~/Content/tmpImages", fileName); }
internal static bool CalculateScaledTextureRects(Rect position, ScaleMode scaleMode, float imageAspect, ref Rect outScreenRect, ref Rect outSourceRect) => throw new NotImplementedException();
public static IRectGUIDrawer DrawTexture(this IRectGUIDrawer self, Rect position, Texture image, ScaleMode scaleMode, bool alphaBlend, float imageAspect) { GUI.DrawTexture(position, image, scaleMode, alphaBlend, imageAspect); return(self); }
public static void ScalePictureFile(string absoluteSourcePath, string absoluteTargetPath, int newSize, ScaleMode mode, ImageFormat destinationFormat, int borderWidth, Color borderColor) { Image sourceImage = Image.FromFile(absoluteSourcePath); Image thumb = ScalePicture(sourceImage, newSize, mode, 0, borderColor); thumb.Save(absoluteTargetPath, destinationFormat); sourceImage.Dispose(); thumb.Dispose(); }
public static IRectGUIDrawer DrawTexture(this IRectGUIDrawer self, Rect position, Texture image, ScaleMode scaleMode, bool alphaBlend, float imageAspect, Color color, float borderWidth, float borderRadius) { GUI.DrawTexture(position, image, scaleMode, alphaBlend, imageAspect, color, borderWidth, borderRadius); return(self); }
public static void ScalePictureFile(string absoluteSourcePath, string absoluteTargetPath, int newSize, ScaleMode mode, ImageFormat destinationFormat) { ScalePictureFile(absoluteSourcePath, absoluteTargetPath, newSize, mode, destinationFormat, 0, Color.White); }
public extern RenderTexture(IRenderer renderer, float width = 100, float height = 100, ScaleMode scaleMode = ScaleMode.Default, Resolution?resolution = null);
public static void ScalePicturesInFolder(string sourceFolderAbsolutePath, string targetFolderAbsolutePath, int newSize, ScaleMode mode, ImageFormat destinationFormat) { DirectoryInfo sourceDirectory = new DirectoryInfo(sourceFolderAbsolutePath); foreach (FileInfo file in FileFinderTool.FindImageFilesInFolder(sourceFolderAbsolutePath)) { string destinationFile = Path.Combine(targetFolderAbsolutePath, file.Name); if (!Directory.Exists(targetFolderAbsolutePath)) { Directory.CreateDirectory(targetFolderAbsolutePath); } ScalePictureFile(file.FullName, Path.ChangeExtension(destinationFile, destinationFormat.ToString()), newSize, mode, destinationFormat); } }
public static RectangleParams MakeVectorTextured(Rect rect, Rect uv, VectorImage vectorImage, ScaleMode scaleMode, ContextType panelContext) { var playmodeTintColor = panelContext == ContextType.Editor ? UIElementsUtility.editorPlayModeTintColor : Color.white; var rp = new RectangleParams { rect = rect, uv = uv, color = Color.white, vectorImage = vectorImage, scaleMode = scaleMode, playmodeTintColor = playmodeTintColor }; return(rp); }
public static RenderTexture ResolveVideoToRenderTexture(Material resolveMaterial, RenderTexture targetTexture, ITextureProducer texture, ResolveFlags flags, ScaleMode scaleMode = ScaleMode.StretchToFill) { int targetWidth = texture.GetTexture(0).width; int targetHeight = texture.GetTexture(0).height; GetResolveTextureSize(texture.GetTextureAlphaPacking(), texture.GetTextureStereoPacking(), StereoEye.Left, ref targetWidth, ref targetHeight); if (targetTexture) { bool sizeChanged = (targetTexture.width != targetWidth || targetTexture.height != targetHeight); if (sizeChanged) { RenderTexture.ReleaseTemporary(targetTexture); targetTexture = null; } } if (!targetTexture) { RenderTextureReadWrite readWrite = ((flags & ResolveFlags.ColorspaceSRGB) == ResolveFlags.ColorspaceSRGB) ? RenderTextureReadWrite.sRGB : RenderTextureReadWrite.Linear; targetTexture = RenderTexture.GetTemporary(targetWidth, targetHeight, 0, RenderTextureFormat.ARGB32, readWrite); } // Set target mipmap generation support { bool requiresMipmap = (flags & ResolveFlags.Mipmaps) == ResolveFlags.Mipmaps; bool requiresRecreate = (targetTexture.IsCreated() && targetTexture.useMipMap != requiresMipmap); if (requiresRecreate) { targetTexture.Release(); } if (!targetTexture.IsCreated()) { targetTexture.useMipMap = targetTexture.autoGenerateMips = requiresMipmap; targetTexture.Create(); } } // Render resolve blit // TODO: combine these two paths into a single material blit { bool prevSRGB = GL.sRGBWrite; GL.sRGBWrite = targetTexture.sRGB; RenderTexture prev = RenderTexture.active; if (scaleMode == ScaleMode.StretchToFill) { Graphics.Blit(texture.GetTexture(0), targetTexture, resolveMaterial); } else { RenderTexture.active = targetTexture; bool partialAreaRender = (scaleMode == ScaleMode.ScaleToFit); if (partialAreaRender) { GL.Clear(false, true, Color.black); } VideoRender.DrawTexture(new Rect(0f, 0f, targetTexture.width, targetTexture.height), texture.GetTexture(0), scaleMode, texture.GetTextureAlphaPacking(), resolveMaterial); } RenderTexture.active = prev; GL.sRGBWrite = prevSRGB; } return(targetTexture); }
public bool Equals([AllowNull] Violin other) { if (other == null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return((Type == other.Type && Type != null && other.Type != null && Type.Equals(other.Type)) && (Visible == other.Visible && Visible != null && other.Visible != null && Visible.Equals(other.Visible)) && (ShowLegend == other.ShowLegend && ShowLegend != null && other.ShowLegend != null && ShowLegend.Equals(other.ShowLegend)) && (LegendGroup == other.LegendGroup && LegendGroup != null && other.LegendGroup != null && LegendGroup.Equals(other.LegendGroup)) && (Opacity == other.Opacity && Opacity != null && other.Opacity != null && Opacity.Equals(other.Opacity)) && (UId == other.UId && UId != null && other.UId != null && UId.Equals(other.UId)) && (Equals(Ids, other.Ids) || Ids != null && other.Ids != null && Ids.SequenceEqual(other.Ids)) && (Equals(CustomData, other.CustomData) || CustomData != null && other.CustomData != null && CustomData.SequenceEqual(other.CustomData)) && (Meta == other.Meta && Meta != null && other.Meta != null && Meta.Equals(other.Meta)) && (Equals(MetaArray, other.MetaArray) || MetaArray != null && other.MetaArray != null && MetaArray.SequenceEqual(other.MetaArray)) && (SelectedPoints == other.SelectedPoints && SelectedPoints != null && other.SelectedPoints != null && SelectedPoints.Equals(other.SelectedPoints)) && (HoverInfo == other.HoverInfo && HoverInfo != null && other.HoverInfo != null && HoverInfo.Equals(other.HoverInfo)) && (Equals(HoverInfoArray, other.HoverInfoArray) || HoverInfoArray != null && other.HoverInfoArray != null && HoverInfoArray.SequenceEqual(other.HoverInfoArray)) && (HoverLabel == other.HoverLabel && HoverLabel != null && other.HoverLabel != null && HoverLabel.Equals(other.HoverLabel)) && (Stream == other.Stream && Stream != null && other.Stream != null && Stream.Equals(other.Stream)) && (Equals(Transforms, other.Transforms) || Transforms != null && other.Transforms != null && Transforms.SequenceEqual(other.Transforms)) && (UiRevision == other.UiRevision && UiRevision != null && other.UiRevision != null && UiRevision.Equals(other.UiRevision)) && (Equals(Y, other.Y) || Y != null && other.Y != null && Y.SequenceEqual(other.Y)) && (Equals(X, other.X) || X != null && other.X != null && X.SequenceEqual(other.X)) && (X0 == other.X0 && X0 != null && other.X0 != null && X0.Equals(other.X0)) && (Y0 == other.Y0 && Y0 != null && other.Y0 != null && Y0.Equals(other.Y0)) && (Name == other.Name && Name != null && other.Name != null && Name.Equals(other.Name)) && (Orientation == other.Orientation && Orientation != null && other.Orientation != null && Orientation.Equals(other.Orientation)) && (Bandwidth == other.Bandwidth && Bandwidth != null && other.Bandwidth != null && Bandwidth.Equals(other.Bandwidth)) && (ScaleGroup == other.ScaleGroup && ScaleGroup != null && other.ScaleGroup != null && ScaleGroup.Equals(other.ScaleGroup)) && (ScaleMode == other.ScaleMode && ScaleMode != null && other.ScaleMode != null && ScaleMode.Equals(other.ScaleMode)) && (SpanMode == other.SpanMode && SpanMode != null && other.SpanMode != null && SpanMode.Equals(other.SpanMode)) && (Equals(Span, other.Span) || Span != null && other.Span != null && Span.SequenceEqual(other.Span)) && (Line == other.Line && Line != null && other.Line != null && Line.Equals(other.Line)) && (FillColor == other.FillColor && FillColor != null && other.FillColor != null && FillColor.Equals(other.FillColor)) && (Points == other.Points && Points != null && other.Points != null && Points.Equals(other.Points)) && (Jitter == other.Jitter && Jitter != null && other.Jitter != null && Jitter.Equals(other.Jitter)) && (PointPos == other.PointPos && PointPos != null && other.PointPos != null && PointPos.Equals(other.PointPos)) && (Width == other.Width && Width != null && other.Width != null && Width.Equals(other.Width)) && (Marker == other.Marker && Marker != null && other.Marker != null && Marker.Equals(other.Marker)) && (Text == other.Text && Text != null && other.Text != null && Text.Equals(other.Text)) && (Equals(TextArray, other.TextArray) || TextArray != null && other.TextArray != null && TextArray.SequenceEqual(other.TextArray)) && (HoverText == other.HoverText && HoverText != null && other.HoverText != null && HoverText.Equals(other.HoverText)) && (Equals(HoverTextArray, other.HoverTextArray) || HoverTextArray != null && other.HoverTextArray != null && HoverTextArray.SequenceEqual(other.HoverTextArray)) && (HoverTemplate == other.HoverTemplate && HoverTemplate != null && other.HoverTemplate != null && HoverTemplate.Equals(other.HoverTemplate)) && (Equals(HoverTemplateArray, other.HoverTemplateArray) || HoverTemplateArray != null && other.HoverTemplateArray != null && HoverTemplateArray.SequenceEqual(other.HoverTemplateArray)) && (Box == other.Box && Box != null && other.Box != null && Box.Equals(other.Box)) && (MeanLine == other.MeanLine && MeanLine != null && other.MeanLine != null && MeanLine.Equals(other.MeanLine)) && (Side == other.Side && Side != null && other.Side != null && Side.Equals(other.Side)) && (OffsetGroup == other.OffsetGroup && OffsetGroup != null && other.OffsetGroup != null && OffsetGroup.Equals(other.OffsetGroup)) && (AlignmentGroup == other.AlignmentGroup && AlignmentGroup != null && other.AlignmentGroup != null && AlignmentGroup.Equals(other.AlignmentGroup)) && (Selected == other.Selected && Selected != null && other.Selected != null && Selected.Equals(other.Selected)) && (Unselected == other.Unselected && Unselected != null && other.Unselected != null && Unselected.Equals(other.Unselected)) && (HoverOn == other.HoverOn && HoverOn != null && other.HoverOn != null && HoverOn.Equals(other.HoverOn)) && (XAxis == other.XAxis && XAxis != null && other.XAxis != null && XAxis.Equals(other.XAxis)) && (YAxis == other.YAxis && YAxis != null && other.YAxis != null && YAxis.Equals(other.YAxis)) && (IdsSrc == other.IdsSrc && IdsSrc != null && other.IdsSrc != null && IdsSrc.Equals(other.IdsSrc)) && (CustomDataSrc == other.CustomDataSrc && CustomDataSrc != null && other.CustomDataSrc != null && CustomDataSrc.Equals(other.CustomDataSrc)) && (MetaSrc == other.MetaSrc && MetaSrc != null && other.MetaSrc != null && MetaSrc.Equals(other.MetaSrc)) && (HoverInfoSrc == other.HoverInfoSrc && HoverInfoSrc != null && other.HoverInfoSrc != null && HoverInfoSrc.Equals(other.HoverInfoSrc)) && (YSrc == other.YSrc && YSrc != null && other.YSrc != null && YSrc.Equals(other.YSrc)) && (XSrc == other.XSrc && XSrc != null && other.XSrc != null && XSrc.Equals(other.XSrc)) && (TextSrc == other.TextSrc && TextSrc != null && other.TextSrc != null && TextSrc.Equals(other.TextSrc)) && (HoverTextSrc == other.HoverTextSrc && HoverTextSrc != null && other.HoverTextSrc != null && HoverTextSrc.Equals(other.HoverTextSrc)) && (HoverTemplateSrc == other.HoverTemplateSrc && HoverTemplateSrc != null && other.HoverTemplateSrc != null && HoverTemplateSrc.Equals(other.HoverTemplateSrc))); }
public static void DrawTexture(Rect destRect, Texture texture, ScaleMode scaleMode, AlphaPacking alphaPacking, Material material) { if (Event.current == null || Event.current.type == EventType.Repaint) { int sourceWidth = texture.width; int sourceHeight = texture.height; GetResolveTextureSize(alphaPacking, StereoPacking.Unknown, StereoEye.Both, ref sourceWidth, ref sourceHeight); float sourceRatio = (float)sourceWidth / (float)sourceHeight; Rect sourceRect = new Rect(0f, 0f, 1f, 1f); switch (scaleMode) { case ScaleMode.ScaleAndCrop: { float destRatio = destRect.width / destRect.height; if (destRatio > sourceRatio) { float adjust = sourceRatio / destRatio; sourceRect = new Rect(0f, (1f - adjust) * 0.5f, 1f, adjust); } else { float adjust = destRatio / sourceRatio; sourceRect = new Rect(0.5f - adjust * 0.5f, 0f, adjust, 1f); } } break; case ScaleMode.ScaleToFit: { float destRatio = destRect.width / destRect.height; if (destRatio > sourceRatio) { float adjust = sourceRatio / destRatio; destRect = new Rect(destRect.xMin + destRect.width * (1f - adjust) * 0.5f, destRect.yMin, adjust * destRect.width, destRect.height); } else { float adjust = destRatio / sourceRatio; destRect = new Rect(destRect.xMin, destRect.yMin + destRect.height * (1f - adjust) * 0.5f, destRect.width, adjust * destRect.height); } } break; case ScaleMode.StretchToFill: break; } GL.PushMatrix(); if (RenderTexture.active == null) { //GL.LoadPixelMatrix(); GL.LoadPixelMatrix(0f, Screen.width, Screen.height, 0f); } else { GL.LoadPixelMatrix(0f, RenderTexture.active.width, RenderTexture.active.height, 0f); } Graphics.DrawTexture(destRect, texture, sourceRect, 0, 0, 0, 0, GUI.color, material); GL.PopMatrix(); } }
private void mitemScaleDirectDraw_Checked(object sender, RoutedEventArgs e) { scaleMode = ScaleMode.DirectDraw; UpdateScaleMode(); }
void AssertImageScale(int imgWidth, int imgHeight, int reqWidth, int reqHeight, ScaleMode mode) { int outWidth, outHeight; Image.ComputeScale(imgWidth, imgHeight, reqWidth, reqHeight, mode, out outWidth, out outHeight); Assert.IsTrue(((double)imgWidth / imgHeight) - ((double)outWidth / outHeight) < 0.01); if (mode == ScaleMode.AspectFit) { Assert.IsTrue(outWidth <= reqWidth); Assert.IsTrue(outHeight <= reqHeight); } else if (mode == ScaleMode.AspectFill) { Assert.IsTrue(outWidth >= reqWidth); Assert.IsTrue(outHeight >= reqHeight); } }
public static void DrawTexture(Rect position, Texture image, ScaleMode scaleMode) { DrawTexture(position, image, scaleMode, alphaBlend: true); }
void OnSceneGUI() { GUI.changed = false; // Get the keyframes of the AnimationCurve to be manipulated Keyframe[] keys = script.spline.keys; // Set defaultLocalRotation so that the initial local rotation will be the zero point for the rotation limit if (!Application.isPlaying) script.defaultLocalRotation = script.transform.localRotation; if (script.axis == Vector3.zero) return; // Make the curve loop script.spline.postWrapMode = WrapMode.Loop; script.spline.preWrapMode = WrapMode.Loop; DrawRotationSphere(script.transform.position); // Display the main axis DrawArrow(script.transform.position, Direction(script.axis), colorDefault, "Axis", 0.02f); Vector3 swing = script.axis.normalized; // Editing tools GUI Handles.BeginGUI(); GUILayout.BeginArea(new Rect(10, Screen.height - 140, 440, 90), "Rotation Limit Spline", "Window"); // Scale Mode and Tangent Mode GUILayout.BeginHorizontal(); scaleMode = (ScaleMode)EditorGUILayout.EnumPopup("Drag Handle", scaleMode); tangentMode = (TangentMode)EditorGUILayout.EnumPopup("Drag Tangents", tangentMode); GUILayout.EndHorizontal(); EditorGUILayout.Space(); if (Inspector.Button("Rotate 90 degrees", "Rotate rotation limit around axis.", script, GUILayout.Width(220))) { if (!Application.isPlaying) Undo.RecordObject(script, "Handle Value"); for (int i = 0; i < keys.Length; i++) keys[i].time += 90; } // Cloning values from another RotationLimitSpline EditorGUILayout.BeginHorizontal(); if (Inspector.Button("Clone From", "Make this rotation limit identical to another", script, GUILayout.Width(220))) { CloneLimit(); keys = script.spline.keys; } clone = (RotationLimitSpline)EditorGUILayout.ObjectField("", clone, typeof(RotationLimitSpline), true); EditorGUILayout.EndHorizontal(); GUILayout.EndArea(); Handles.EndGUI(); // Draw keyframes for (int i = 0; i < keys.Length - 1; i++) { float angle = keys[i].time; // Start drawing handles Quaternion offset = Quaternion.AngleAxis(angle, swing); Quaternion rotation = Quaternion.AngleAxis(keys[i].value, offset * script.crossAxis); Vector3 position = script.transform.position + Direction(rotation * swing); Handles.Label(position, " " + i.ToString()); // Dragging Values if (selectedHandle == i) { Handles.color = colorHandles; switch(scaleMode) { case ScaleMode.Limit: float inputValue = keys[i].value; inputValue = Mathf.Clamp(Handles.ScaleValueHandle(inputValue, position, Quaternion.identity, 0.5f, Handles.SphereCap, 0), 0.01f, 180); if (keys[i].value != inputValue) { if (!Application.isPlaying) Undo.RecordObject(script, "Handle Value"); keys[i].value = inputValue; } break; case ScaleMode.Angle: float inputTime = keys[i].time; inputTime = Handles.ScaleValueHandle(inputTime, position, Quaternion.identity, 0.5f, Handles.SphereCap, 0); if (keys[i].time != inputTime) { if (!Application.isPlaying) Undo.RecordObject(script, "Handle Angle"); keys[i].time = inputTime; } break; } } // Handle select button if (selectedHandle != i) { Handles.color = Color.blue; if (Handles.Button(position, script.transform.rotation, 0.05f, 0.05f, Handles.SphereCap)) { selectedHandle = i; } } // Tangents if (selectedHandle == i) { // Evaluate positions before and after the key to get the tangent positions Vector3 prevPosition = GetAnglePosition(keys[i].time - 1); Vector3 nextPosition = GetAnglePosition(keys[i].time + 1); // Draw handles for the tangents Handles.color = Color.white; Vector3 toNext = (nextPosition - position).normalized * 0.3f; float outTangent = keys[i].outTangent; outTangent = Handles.ScaleValueHandle(outTangent, position + toNext, Quaternion.identity, 0.2f, Handles.SphereCap, 0); Vector3 toPrev = (prevPosition - position).normalized * 0.3f; float inTangent = keys[i].inTangent; inTangent = Handles.ScaleValueHandle(inTangent, position + toPrev, Quaternion.identity, 0.2f, Handles.SphereCap, 0); if (outTangent != keys[i].outTangent || inTangent != keys[i].inTangent) selectedHandle = i; // Make the other tangent match the dragged tangent (if in "Smooth" TangentMode) switch(tangentMode) { case TangentMode.Smooth: if (outTangent != keys[i].outTangent) { if (!Application.isPlaying) Undo.RecordObject(script, "Tangents"); keys[i].outTangent = outTangent; keys[i].inTangent = outTangent; } else if (inTangent != keys[i].inTangent) { if (!Application.isPlaying) Undo.RecordObject(script, "Tangents"); keys[i].outTangent = inTangent; keys[i].inTangent = inTangent; } break; case TangentMode.Independent: if (outTangent != keys[i].outTangent) { if (!Application.isPlaying) Undo.RecordObject(script, "Tangents"); keys[i].outTangent = outTangent; } else if (inTangent != keys[i].inTangent) { if (!Application.isPlaying) Undo.RecordObject(script, "Tangents"); keys[i].inTangent = inTangent; } break; } // Draw lines and labels to tangent handles Handles.color = Color.white; GUI.color = Color.white; Handles.DrawLine(position, position + toNext); Handles.Label(position + toNext, " Out"); Handles.DrawLine(position, position + toPrev); Handles.Label(position + toPrev, " In"); } } // Selected Point GUI if (selectedHandle != -1) { Handles.BeginGUI(); GUILayout.BeginArea(new Rect(Screen.width - 240, Screen.height - 200, 230, 150), "Handle " + selectedHandle.ToString(), "Window"); if (Inspector.Button("Delete", "Delete this handle", script)) { if (keys.Length > 4) { deleteHandle = selectedHandle; } else if (!Warning.logged) script.LogWarning("Spline Rotation Limit should have at least 3 handles"); } if (Inspector.Button("Add Handle", "Add a new handle next to this one", script)) { addHandle = selectedHandle; } // Clamp the key angles to previous and next handle angles float prevTime = 0, nextTime = 0; if (selectedHandle < keys.Length - 2) nextTime = keys[selectedHandle + 1].time; else nextTime = keys[0].time + 360; if (selectedHandle == 0) prevTime = keys[keys.Length - 2].time - 360; else prevTime = keys[selectedHandle - 1].time; // Angles float inputTime = keys[selectedHandle].time; inputTime = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("Angle", "Angle of the point (0-360)."), inputTime), prevTime, nextTime); if (keys[selectedHandle].time != inputTime) { if (!Application.isPlaying) Undo.RecordObject(script, "Handle Angle"); keys[selectedHandle].time = inputTime; } // Limits float inputValue = keys[selectedHandle].value; inputValue = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("Limit", "Max angular limit from Axis at this angle"), inputValue), 0, 180); if (keys[selectedHandle].value != inputValue) { if (!Application.isPlaying) Undo.RecordObject(script, "Handle Limit"); keys[selectedHandle].value = inputValue; } // In Tangents float inputInTangent = keys[selectedHandle].inTangent; inputInTangent = EditorGUILayout.FloatField(new GUIContent("In Tangent", "In tangent of the handle point on the spline"), inputInTangent); if (keys[selectedHandle].inTangent != inputInTangent) { if (!Application.isPlaying) Undo.RecordObject(script, "Handle In Tangent"); keys[selectedHandle].inTangent = inputInTangent; } // Out tangents float inputOutTangent = keys[selectedHandle].outTangent; inputOutTangent = EditorGUILayout.FloatField(new GUIContent("Out Tangent", "Out tangent of the handle point on the spline"), inputOutTangent); if (keys[selectedHandle].outTangent != inputOutTangent) { if (!Application.isPlaying) Undo.RecordObject(script, "Handle Out Tangent"); keys[selectedHandle].outTangent = inputOutTangent; } GUILayout.EndArea(); Handles.EndGUI(); } // Make sure the keyframes are valid; ValidateKeyframes(keys); // Replace the AnimationCurve keyframes with the manipulated keyframes script.spline.keys = keys; // Display limits for (int i = 0; i < 360; i+= 2) { float evaluatedLimit = script.spline.Evaluate((float)i); Quaternion offset = Quaternion.AngleAxis(i, swing); Quaternion evaluatedRotation = Quaternion.AngleAxis(evaluatedLimit, offset * script.crossAxis); Quaternion testRotation = Quaternion.AngleAxis(179.9f, offset * script.crossAxis); Quaternion limitedRotation = script.LimitSwing(testRotation); Vector3 evaluatedDirection = evaluatedRotation * swing; Vector3 limitedDirection = limitedRotation * swing; // Display the limit points in red if they are out of range bool isValid = Vector3.Distance(evaluatedDirection, limitedDirection) < 0.01f && evaluatedLimit >= 0; Color color = isValid? colorDefaultTransparent: colorInvalid; Vector3 limitPoint = script.transform.position + Direction(evaluatedDirection); Handles.color = color; if (i == 0) zeroPoint = limitPoint; Handles.DrawLine(script.transform.position, limitPoint); if (i > 0) { Handles.color = isValid? colorDefault: colorInvalid; Handles.DrawLine(limitPoint, lastPoint); if (i == 358) Handles.DrawLine(limitPoint, zeroPoint); } lastPoint = limitPoint; } // Deleting points if (deleteHandle != -1) { DeleteHandle(deleteHandle); selectedHandle = -1; deleteHandle = -1; } // Adding points if (addHandle != -1) { AddHandle(addHandle); addHandle = -1; } Handles.color = Color.white; if (GUI.changed) EditorUtility.SetDirty(script); }
//Base code from BobPowell.net //http://www.bobpowell.net/highqualitythumb.htm /// <summary> /// Scales an Image to another size /// </summary> /// <param name="original">The original Image to resize</param> /// <param name="newSizeInPixels">The size of the new Image to return</param> /// <param name="mode">How to interpret the "newSizeInPixels" parameter</param> /// <returns></returns> public static Image ScalePicture(Image originalImage, int newSizeInPixels, ScaleMode mode, int borderWidth, Color borderColor) { if (!Enum.IsDefined(typeof(ScaleMode), mode)) { throw new ArgumentException(string.Format("ScaleMode value of '{0}' is not defined", mode)); } //store original dimensions SizeF originalSize = new Size(originalImage.Width, originalImage.Height); SizeF newOuterSize = new SizeF(); float ratio = originalSize.Height / originalSize.Width; int shortestSide = (int)Math.Min(originalSize.Height, originalSize.Width); Orientation imageOrientation = (ratio < 1 ? Orientation.Landscape : Orientation.Portrait); switch (mode) { case ScaleMode.Percent: if (newSizeInPixels < 1) { throw new ArgumentException("Thumbnail size must be at least 1% of the original size"); } newOuterSize.Width = (int)(originalImage.Width * 0.01f * newSizeInPixels); newOuterSize.Height = (int)(originalImage.Height * 0.01f * newSizeInPixels); //shortestSideOnNewImage = (int) shortestSide * 0.01f * newSizeInPixels ; break; case ScaleMode.MaxWidthInPixels: newOuterSize.Width = newSizeInPixels; newOuterSize.Height = newOuterSize.Width * ratio; break; case ScaleMode.MaxHeightInPixels: newOuterSize.Height = newSizeInPixels; newOuterSize.Width = newOuterSize.Height / ratio; break; case ScaleMode.MaxSizeInPixels: newOuterSize = FitSize(originalImage.Height, originalImage.Width, newSizeInPixels); break; case ScaleMode.SquareCropInPixels: case ScaleMode.SquareFrame: newOuterSize.Height = newOuterSize.Width = newSizeInPixels; break; } Bitmap tn = new Bitmap((int)newOuterSize.Width, (int)newOuterSize.Height); Graphics g = Graphics.FromImage(tn); Rectangle destinationRectangle; Rectangle sourceRectangle; g.FillRectangle(Brushes.White, 0, 0, tn.Width, tn.Height); g.CompositingQuality = CompositingQuality.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBilinear; //SOURCE RECTANGLE if (mode == ScaleMode.SquareCropInPixels) { if (imageOrientation == Orientation.Portrait) { sourceRectangle = new Rectangle(0, 0, shortestSide, shortestSide); } else { sourceRectangle = new Rectangle((int)((originalImage.Width - shortestSide) / 2), 0, shortestSide, shortestSide); } } else { sourceRectangle = new Rectangle(0, 0, originalImage.Width, originalImage.Height); } if (mode == ScaleMode.SquareFrame) { SizeF innerImageSize = FitSize(originalImage.Height, originalImage.Width, newSizeInPixels - 2 * borderWidth); int topBorder = (int)(tn.Height - innerImageSize.Height) / 2; int leftBorder = (int)(tn.Width - innerImageSize.Width) / 2; destinationRectangle = new Rectangle(new Point(leftBorder, topBorder), Size.Round(innerImageSize)); //new Rectangle(borderWidth, borderWidth, tn.Width - borderWidth * 2, tn.Height - borderWidth * 2); } else { //DESTINATION RECTANGLE if (borderWidth > 0) { g.FillRectangle(new SolidBrush(borderColor), 0, 0, tn.Width, tn.Height); //todo: check if borders are wider than half of shortest side of image, in that case image is blank or worse //if(borderWidth > destinationRectangle = new Rectangle(borderWidth, borderWidth, tn.Width - borderWidth * 2, tn.Height - borderWidth * 2); } else { destinationRectangle = new Rectangle(0, 0, tn.Width, tn.Height); } } g.DrawImage(originalImage, destinationRectangle, sourceRectangle, GraphicsUnit.Pixel); g.DrawRectangle(Pens.Silver, destinationRectangle); if (borderWidth > 0) { //g.DrawRectangle(Pens.Black, destinationRectangle); } g.Dispose(); return((Image)tn); }