public static BitmapImage[] GetMenuIcons() { using (var bitmaps = new BitmapList(LoadMenuIcons())) { return(bitmaps.Select(ToBitmapImage).ToArray()); } }
public static BitmapImage[] GetStatusIcons(string fileName) { using (var bitmaps = new BitmapList(LoadStatusIcons(fileName))) { return(bitmaps.Select(ToBitmapImage).ToArray()); } }
public override void Draw() { int size = _mode.SquareSize, x = 0, y = 0; var p = _properties; // draw information bar InformationBar.Draw(_stopWatch.GetTime(), (_mode.Board as MinesweeperBoard).Flag); // draw each squares on the board foreach (string representativeChar in _mode.Board.DrawableBoard) { // draw the whole square Bitmap image = BitmapList.GetBitmap(representativeChar); // x and y must all be substracted with its respective offsets SplashKit.DrawBitmapOnWindow( SplashKit.CurrentWindow(), image, p.MarginLeft + x * size - p.SquareOffsetX, p.MarginTop + y * size - p.SquareOffsetY, p.SquareOptions ); // advances to another row if (x++ == _mode.Board.Width - 1) { x = 0; y++; } } }
/// <summary> /// 将图像路径集合转为位图列表。 /// </summary> /// <param name="imagePaths">给定的 <see cref="IEnumerable{String}"/>。</param> /// <returns>返回 <see cref="IBitmapList"/>。</returns> public static IBitmapList AsBitmaps(this IEnumerable <string> imagePaths) { var bitmaps = new BitmapList(); bitmaps.Add(imagePaths); return(bitmaps); }
/// <summary> /// 将图像路径转为位图列表。 /// </summary> /// <param name="imagePath">给定的图像路径。</param> /// <returns>返回 <see cref="IBitmapList"/>。</returns> public static IBitmapList AsBitmaps(this string imagePath) { var bitmaps = new BitmapList(); bitmaps.Add(imagePath); return(bitmaps); }
protected override IBitmapList DrawCore(IBitmapList bitmaps) { if (Options.Scale.Descriptors.Count < 1) { return(bitmaps); } var scaleBitmaps = new BitmapList(); var watermarkBitmaps = new BitmapList(); foreach (var bitmap in bitmaps) { var realBitmap = (SKBitmap)bitmap.Source; // 遍历缩放信息 foreach (var scaleDescriptor in Options.Scale.Descriptors) { // 如果源图尺寸小于缩放尺寸,则跳过当前缩放信息 if (realBitmap.Width <= scaleDescriptor.MaxSize.Width && realBitmap.Height <= scaleDescriptor.MaxSize.Height) { continue; } // 计算等比例缩放尺寸 var imageSize = new Size(realBitmap.Width, realBitmap.Height); var scaleSize = ImageHelper.ScaleSize(imageSize, scaleDescriptor.MaxSize); var scaleInfo = new SKImageInfo(scaleSize.Width, scaleSize.Height, realBitmap.Info.ColorType, realBitmap.Info.AlphaType); // 是否附加缩放尺寸后缀 var scaleNameFuffix = scaleDescriptor.FileNameSuffix; if (Options.Scale.AddScaleSizeSuffix) { scaleNameFuffix += $"-{scaleSize.Width}x{scaleSize.Height}"; } // 创建缩放位图描述符 var scaleBitmap = realBitmap.Resize(scaleInfo, Options.ResizeQuality); var descriptor = new BitmapDescriptor(scaleBitmap, bitmap.FilePath, scaleNameFuffix); scaleBitmaps.Add(descriptor); if (scaleDescriptor.AddWatermark) { watermarkBitmaps.Add(descriptor); } } } // 处理缩放位图集合的水印 if (watermarkBitmaps.Count > 0) { _watermarkDrawer.Draw(watermarkBitmaps); } return(scaleBitmaps); }
/// <summary> /// Modularization for drawing simplified board /// </summary> /// <param name="board">Stringified minesweeper board</param> /// <param name="rotate90Deg">Rotates the board 90 degrees (but the squares aren't)</param> private void DrawBoard(string[] board, bool rotate90Deg = false) { int x = 0, y = 0; var props = rotate90Deg ? _opponentProps : _playerProps; // draw each squares on the board foreach (string representativeChar in board) { // draw the whole square Bitmap image = BitmapList.GetBitmap(representativeChar); // x and y must all be substracted with its respective offsets SplashKit.DrawBitmapOnWindow( SplashKit.CurrentWindow(), image, props.MarginLeft + x * props.SquareSize - props.SquareOffsetX, props.MarginTop + y * props.SquareSize - props.SquareOffsetY, props.SquareOptions ); // advances to another row // player if (!rotate90Deg) { x++; if (x == _settings.BoardWidth) { x = 0; y++; } continue; } // opponent y++; if (y == _settings.BoardWidth) { y = 0; x++; } } }
public T LoadFromFile <T>(string assetName) { string extension = FileManager.GetExtension(assetName); if (FileManager.IsRelative(assetName)) { // get the absolute path using the current relative directory assetName = FileManager.RelativeDirectory + assetName; } string fullNameWithType = assetName + typeof(T).Name; // get the dictionary by the contentManagerName. If it doesn't exist, GetDisposableDictionaryByName // will create it. if (mDisposableDictionary.ContainsKey(fullNameWithType)) { #if PROFILE mHistory.Add(new ContentLoadHistory( TimeManager.CurrentTime, typeof(T).Name, fullNameWithType, ContentLoadDetail.Cached)); #endif return((T)mDisposableDictionary[fullNameWithType]); } else if (mNonDisposableDictionary.ContainsKey(fullNameWithType)) { return((T)mNonDisposableDictionary[fullNameWithType]); } else { #if PROFILE mHistory.Add(new ContentLoadHistory( TimeManager.CurrentTime, typeof(T).Name, fullNameWithType, ContentLoadDetail.HddFromFile)); #endif #if DEBUG // The ThrowExceptionIfFileDoesntExist // call used to be done before the checks // in the dictionaries. But whatever is held // in there may not really be a file so let's check // if the file exists after we check the dictionaries. FileManager.ThrowExceptionIfFileDoesntExist(assetName); #endif IDisposable loadedAsset = null; if (typeof(T) == typeof(Texture2D) || typeof(T) == typeof(Microsoft.Xna.Framework.Graphics.Texture2D)) { // for now we'll create it here, eventually have it in a dictionary: loadedAsset = textureContentLoader.Load(assetName); } #region Scene else if (typeof(T) == typeof(FlatRedBall.Scene)) { FlatRedBall.Scene scene = FlatRedBall.Content.Scene.SceneSave.FromFile(assetName).ToScene(mName); object sceneAsObject = scene; lock (mNonDisposableDictionary) { if (!mNonDisposableDictionary.ContainsKey(fullNameWithType)) { mNonDisposableDictionary.Add(fullNameWithType, scene); } } return((T)sceneAsObject); } #endregion #region EmitterList else if (typeof(T) == typeof(EmitterList)) { EmitterList emitterList = EmitterSaveList.FromFile(assetName).ToEmitterList(mName); mNonDisposableDictionary.Add(fullNameWithType, emitterList); return((T)((object)emitterList)); } #endregion #region Image #if !MONOGAME else if (typeof(T) == typeof(Image)) { switch (extension.ToLowerInvariant()) { case "gif": Image image = Image.FromFile(assetName); loadedAsset = image; break; } } #endif #endregion #region BitmapList #if !XBOX360 && !SILVERLIGHT && !WINDOWS_PHONE && !MONOGAME else if (typeof(T) == typeof(BitmapList)) { loadedAsset = BitmapList.FromFile(assetName); } #endif #endregion #region NodeNetwork else if (typeof(T) == typeof(NodeNetwork)) { NodeNetwork nodeNetwork = NodeNetworkSave.FromFile(assetName).ToNodeNetwork(); mNonDisposableDictionary.Add(fullNameWithType, nodeNetwork); return((T)((object)nodeNetwork)); } #endregion #region ShapeCollection else if (typeof(T) == typeof(ShapeCollection)) { ShapeCollection shapeCollection = ShapeCollectionSave.FromFile(assetName).ToShapeCollection(); mNonDisposableDictionary.Add(fullNameWithType, shapeCollection); return((T)((object)shapeCollection)); } #endregion #region PositionedObjectList<Polygon> else if (typeof(T) == typeof(PositionedObjectList <FlatRedBall.Math.Geometry.Polygon>)) { PositionedObjectList <FlatRedBall.Math.Geometry.Polygon> polygons = PolygonSaveList.FromFile(assetName).ToPolygonList(); mNonDisposableDictionary.Add(fullNameWithType, polygons); return((T)((object)polygons)); } #endregion #region AnimationChainList else if (typeof(T) == typeof(AnimationChainList)) { if (assetName.EndsWith("gif")) { #if WINDOWS_8 || UWP || DESKTOP_GL throw new NotImplementedException(); #else AnimationChainList acl = new AnimationChainList(); acl.Add(FlatRedBall.Graphics.Animation.AnimationChain.FromGif(assetName, this.mName)); acl[0].ParentGifFileName = assetName; loadedAsset = acl; #endif } else { loadedAsset = AnimationChainListSave.FromFile(assetName).ToAnimationChainList(mName); } mNonDisposableDictionary.Add(fullNameWithType, loadedAsset); } #endregion else if (typeof(T) == typeof(Song)) { var loader = new SongLoader(); return((T)(object)loader.Load(assetName)); } #if MONOGAME else if (typeof(T) == typeof(SoundEffect)) { T soundEffect; if (assetName.StartsWith(@".\") || assetName.StartsWith(@"./")) { soundEffect = base.Load <T>(assetName.Substring(2)); } else { soundEffect = base.Load <T>(assetName); } return(soundEffect); } #endif #region RuntimeCsvRepresentation #if !SILVERLIGHT else if (typeof(T) == typeof(RuntimeCsvRepresentation)) { #if XBOX360 throw new NotImplementedException("Can't load CSV from file. Try instead to use the content pipeline."); #else return((T)((object)CsvFileManager.CsvDeserializeToRuntime(assetName))); #endif } #endif #endregion #region SplineList else if (typeof(T) == typeof(List <Spline>)) { List <Spline> splineList = SplineSaveList.FromFile(assetName).ToSplineList(); mNonDisposableDictionary.Add(fullNameWithType, splineList); object asObject = splineList; return((T)asObject); } else if (typeof(T) == typeof(SplineList)) { SplineList splineList = SplineSaveList.FromFile(assetName).ToSplineList(); mNonDisposableDictionary.Add(fullNameWithType, splineList); object asObject = splineList; return((T)asObject); } #endregion #region BitmapFont else if (typeof(T) == typeof(BitmapFont)) { // We used to assume the texture is named the same as the font file // But now FRB understands the .fnt file and gets the PNG from the font file //string pngFile = FileManager.RemoveExtension(assetName) + ".png"; string fntFile = FileManager.RemoveExtension(assetName) + ".fnt"; BitmapFont bitmapFont = new BitmapFont(fntFile, this.mName); object bitmapFontAsObject = bitmapFont; return((T)bitmapFontAsObject); } #endregion #region Text else if (typeof(T) == typeof(string)) { return((T)((object)FileManager.FromFileText(assetName))); } #endregion #region Catch mistakes #if DEBUG else if (typeof(T) == typeof(Spline)) { throw new Exception("Cannot load Splines. Try using the List<Spline> type instead."); } else if (typeof(T) == typeof(Emitter)) { throw new Exception("Cannot load Emitters. Try using the EmitterList type instead."); } #endif #endregion #region else, exception! else { throw new NotImplementedException("Cannot load content of type " + typeof(T).AssemblyQualifiedName + " from file. If you are loading " + "through the content pipeline be sure to remove the extension of the file " + "name."); } #endregion if (loadedAsset != null) { lock (mDisposableDictionary) { // Multiple threads could try to load this content simultaneously if (!mDisposableDictionary.ContainsKey(fullNameWithType)) { mDisposableDictionary.Add(fullNameWithType, loadedAsset); } } } return((T)loadedAsset); } }
/// <summary> /// 构建图片 /// </summary> /// <param name="pageWidth">页宽</param> /// <param name="pageHeight">页高</param> public ZicoxPrintClient BuildBitmap(int pageWidth, int pageHeight) { BitmapList.ForEach(x => CommandBuilder.DrawBitmap(pageWidth, pageHeight, x)); return(this); }