public override void Measure() //todo: Will lead to NullReferenceException when recreated window on some maps: s/552702 { if (!_isStart && _status != OsuModel.Status) { _isStart = true; } if (!_isStart) { return; } if (_currentMapPath != OsuModel.Idle.NowMap.Folder) { _currentMapPath = OsuModel.Idle.NowMap.Folder; var currentBgPath = Path.Combine(_currentMapPath, OsuModel.Idle.NowMap.BackgroundFilename); if (File.Exists(currentBgPath)) { _oldBg = _newBg; _newBg = RenderTarget.LoadBitmap(currentBgPath); _lastBgIsNull = false; } else if (_defaultBg != null) { if (_lastBgIsNull) { return; } _oldBg = _newBg; _newBg = _defaultBg; _lastBgIsNull = true; } else { return; } _fixedRectOld = _fixedRect; _fixedRect = GetBgPosition(_newBg.Size); var size = Settings.Render.WindowSize; if (_newBg != null) { _newBgObj = new BitmapObject(RenderTarget, _newBg, Origin.Default, new Mathe.RawPoint(size.Width / 2, size.Height / 2)); } if (_oldBg != null) { _oldBgObj = new BitmapObject(RenderTarget, _oldBg, Origin.Default, new Mathe.RawPoint(size.Width / 2, size.Height / 2)); } _transformStyle = _rnd.Next(0, 3); if (sw.ElapsedMilliseconds < 600 && sw.ElapsedMilliseconds != 0) { _transformStyle = 99; } sw.Restart(); } }
static void Main(string[] args) { string mainDesign = "VIKINGS_COMOUFLAGE.pv"; string backgroundDesign = "leopard.png"; VectorDesign design = VectorDesign.Load(mainDesign, VectorDesignFileTypes.Pv); // Replace an image in a clipped group within a PV file with another image BitmapObject backgroundObj = null; // VectorDesign.ProcessObjects with iterate through all objects of an entire design // calling the supplied delegate passing each object as the single parameter. // The return value is the old image file provided the Name matches what is in the PV file // and the object found is a Bitmap Object. design.ProcessObjects(obj => { if (obj.Name == "<Linked File>" && obj is BitmapObject) { // Cast the obj to a BitmapObject as we will want information later from this backgroundObj = (BitmapObject)obj; // Read the new image file into a byte array var image = System.IO.File.ReadAllBytes(backgroundDesign); Pulse.VectorEngine.Resources.BitmapResource bitmapResource; // Read the image in the byte array into a Memory Stream using (var stream = new System.IO.MemoryStream(image)) { // Add the stream into the design's resources as a Bitmap Resource bitmapResource = design.ResourceManager.AddBitmapResource(stream); } // Create a new Bitmap Object // Set the BitmapResourceId to the newly created Bitmap Resource from above // Give the new object a name other than the original name in the PV file // as the same name would cause the Processing of Objects to get caught in an endless loop // Set a file name // Set the Matrix of the new Bitmap Object to the Matrix of the original // image as this will set the location of the new image to the old image BitmapObject bitmapObject = new BitmapObject(); bitmapObject.BitmapResourceId = bitmapResource.Id; bitmapObject.Name = "leopard"; bitmapObject.Filename = backgroundDesign; bitmapObject.Matrix = backgroundObj.Matrix; // We want to replace the old object with our new Bitmap Object obj = bitmapObject; } return obj; }); System.Diagnostics.Debug.Assert(backgroundObj != null); design.Render(@"ReplaceBackgroundImage.PNG", RenderFormats.Png, 200, design.ColourContext); }
/// <summary> /// Adiciona um novo objeto na lista. /// </summary> /// <param name="bitmap"></param> /// <param name="name"></param> private void AddObject(Bitmap bitmap, string name) { var imgObject = new BitmapObject() { Image = new Bitmap(bitmap), Name = name }; objectList.Add(imgObject); }
/// <summary> /// Adiciona as imagens selecionadas na lista. /// </summary> /// <param name="fileNames"></param> /// <param name="safeNames"></param> private void AddObject(string[] fileNames, string[] safeNames) { var length = fileNames.Length; for (var index = 0; index < length; index++) { var obj = new BitmapObject { Name = GetFileName(safeNames[index]), Image = new Bitmap(fileNames[index]) }; objectList.Add(obj); Application.DoEvents(); } }
public override void Measure() //todo: Will lead to NullReferenceException when recreated window on some maps: s/552702 { if (!_isStart && _status != OsuModel.Status) { _isStart = true; } if (!_isStart) { return; } if (_crtMapFile != OsuModel.Idle.NowMap.FilenameFull) { string oldMapBg = _crtMapBg; string oldMapPath = _crtMapPath; _crtMapFile = OsuModel.Idle.NowMap.FilenameFull; _crtMapBg = OsuModel.Idle.NowMap.BackgroundFilename; _crtMapPath = OsuModel.Idle.NowMap.Folder; LogUtil.LogInfo((_crtMapBg == null).ToString()); if (oldMapPath != _crtMapPath || oldMapBg != _crtMapBg) { var currentBgPath = Path.Combine(_crtMapPath, OsuModel.Idle.NowMap.BackgroundFilename); if (File.Exists(currentBgPath)) { _oldBg = _newBg; _newBg = RenderTarget.LoadBitmap(currentBgPath); _lastBgIsNull = false; } else if (_defaultBg != null) { if (_lastBgIsNull) { return; } _oldBg = _newBg; _newBg = _defaultBg; _lastBgIsNull = true; } else { return; } _fixedRectOld = _fixedRect; _fixedRect = GetBgPosition(_newBg.Size); var size = Settings.Render.WindowSize; if (_newBg != null) { _newBgObj = new BitmapObject(RenderTarget, _newBg, Origin.Default, new Mathe.RawPoint(size.Width / 2, size.Height / 2)); _newBgObjEffect = new BitmapObject(RenderTarget, _newBg, Origin.Default, new Mathe.RawPoint(size.Width / 2, size.Height / 2), true); } if (_oldBg != null) { _oldBgObj = new BitmapObject(RenderTarget, _oldBg, Origin.Default, new Mathe.RawPoint(size.Width / 2, size.Height / 2)); } _transformStyle = _rnd.Next(0, 3); if (_sw.ElapsedMilliseconds < 600 && _sw.ElapsedMilliseconds != 0) { _transformStyle = 99; } } try { OsuFile file = OsuFile.ReadFromFileAsync(OsuModel.Idle.NowMap.FilenameFull).Result; _barList = file.TimingPoints.GetTimingBars(); _11List = file.TimingPoints.GetTimings(1); _kiaiList = file.TimingPoints.GetTimingKiais(); } catch (NotSupportedException e) { LogUtil.LogError(e.Message); _barList = new double[0]; _11List = new double[0]; _kiaiList = new RangeValue <double> [0]; } _sw.Restart(); } }
private static BitmapObject[] GetBitmapObjects(string[] fnames, int maxSize, ICanvas canvas, out Size bmpSize, out Size dataSize, out GeoDo.RSS.Core.DrawEngine.CoordEnvelope viewPrjEvp, out GeoDo.RSS.Core.DF.CoordEnvelope viewGeoEvp, out float resolution) { bmpSize = Size.Empty; dataSize = new Size(); viewPrjEvp = null; viewGeoEvp = null; resolution = 0; List <BitmapObject> bmpObjs = new List <BitmapObject>(); BitmapObject bmpO; GeoDo.RSS.Core.DrawEngine.CoordEnvelope drawEvp = null; bool isFirst = true; foreach (string fname in fnames) { if (!File.Exists(fname)) { continue; } using (IRasterDataProvider prd = GeoDataDriver.Open(fname) as IRasterDataProvider) { IOverviewGenerator ov = prd as IOverviewGenerator; bmpSize = ov.ComputeSize(maxSize); Bitmap bmp = new Bitmap(bmpSize.Width, bmpSize.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); RasterIdentify identify = new RasterIdentify(fname); object[] sts = GetColorTableFunc(prd, identify.ProductIdentify, identify.SubProductIdentify); if (sts != null) { ov.Generate(new int[] { 1, 1, 1 }, sts, ref bmp); } else { int[] bands = prd.GetDefaultBands(); if (bands == null || bands.Length == 0) { return(null); } ov.Generate(bands, ref bmp); } drawEvp = GetDrawingEnvelop(canvas, prd); if (isFirst) { viewPrjEvp = drawEvp; ICoordinateTransform tans = canvas.CoordTransform; viewGeoEvp = PrjToGeoCoordEvp(viewPrjEvp, tans); resolution = prd.ResolutionX; dataSize = GetMaxDataSize(canvas, viewPrjEvp, prd, out viewGeoEvp); isFirst = false; } else { viewPrjEvp = viewPrjEvp.Union(drawEvp); dataSize = GetMaxDataSize(canvas, viewPrjEvp, prd, out viewGeoEvp); //如果分辩率不相等则取最大的分辨率 if (resolution < prd.ResolutionX) { resolution = prd.ResolutionX; } } bmpO = new BitmapObject(bmp, drawEvp); bmpObjs.Add(bmpO); } } return(bmpObjs.Count != 0 ? bmpObjs.ToArray() : null); }