//--------------------------------------------------------------------------------------------------------- /// <summary> /// Изменение имени ресурса кисти. /// Метод автоматически вызывается после установки соответствующего свойства /// </summary> //--------------------------------------------------------------------------------------------------------- protected virtual void RaiseResourceNameChanged() { #if USE_WINDOWS System.Windows.Media.ImageBrush image_brush = mWindowsBrush as System.Windows.Media.ImageBrush; image_brush.ImageSource = XWindowsLoaderBitmap.LoadBitmapFromResource(Properties.Resources.ResourceManager, mResourceName); image_brush.Viewport = new System.Windows.Rect(0, 0, image_brush.ImageSource.Width, image_brush.ImageSource.Height); // 2) Информируем об изменении NotifyPropertyChanged(PropertyArgsWindowsBrush); #endif #if USE_GDI if (mDrawingBrush != null) { mDrawingBrush.Dispose(); } Object image = Properties.Resources.ResourceManager.GetObject(mResourceName); System.Drawing.Bitmap source = (System.Drawing.Bitmap)image; mDrawingBrush = new System.Drawing.TextureBrush(source, (System.Drawing.Drawing2D.WrapMode)GetTileMode()); #endif #if USE_SHARPDX if (mD2DBrush != null) { SharpDX.Direct2D1.BitmapBrush d2d_image_brush = mD2DBrush as SharpDX.Direct2D1.BitmapBrush; d2d_image_brush.Bitmap = XDirect2DManager.LoadFromResource(mResourceName); } #endif }
//--------------------------------------------------------------------------------------------------------- /// <summary> /// Обновление ресурса Direct2D /// </summary> /// <param name="forced">Принудительное создание ресурса Direct2D</param> //--------------------------------------------------------------------------------------------------------- public override void UpdateDirect2DResource(Boolean forced = false) { if (XDirect2DManager.D2DRenderTarget != null) { // Принудительное создание ресурса if (forced) { XDisposer.SafeDispose(ref mD2DBrush); } if (mD2DBrush == null) { SharpDX.Direct2D1.BitmapBrushProperties bbp = new SharpDX.Direct2D1.BitmapBrushProperties(); bbp.ExtendModeX = (SharpDX.Direct2D1.ExtendMode)mExtendModeX; bbp.ExtendModeY = (SharpDX.Direct2D1.ExtendMode)mExtendModeY; bbp.InterpolationMode = SharpDX.Direct2D1.BitmapInterpolationMode.NearestNeighbor; mD2DBrush = new SharpDX.Direct2D1.BitmapBrush(XDirect2DManager.D2DRenderTarget, XDirect2DManager.LoadFromResource(mResourceName), bbp); mD2DBrush.Transform = SharpDX.Matrix3x2.Scaling(mScale); } else { SharpDX.Direct2D1.BitmapBrush d2d_image_brush = mD2DBrush as SharpDX.Direct2D1.BitmapBrush; d2d_image_brush.Bitmap = XDirect2DManager.LoadFromResource(mResourceName); d2d_image_brush.ExtendModeX = (SharpDX.Direct2D1.ExtendMode)mExtendModeX; d2d_image_brush.ExtendModeY = (SharpDX.Direct2D1.ExtendMode)mExtendModeY; d2d_image_brush.Transform = SharpDX.Matrix3x2.Scaling(mScale); d2d_image_brush.InterpolationMode = SharpDX.Direct2D1.BitmapInterpolationMode.NearestNeighbor; } } }
//--------------------------------------------------------------------------------------------------------- /// <summary> /// Обновление данных изображения /// </summary> //--------------------------------------------------------------------------------------------------------- public override void Update() { if (mSource.IsCorrectPath) { if (mSource.TypeData == TCadImageSourceType.File) { mD2DBitmap = XDirect2DManager.LoadFromFile(mSource.PathData); } else { mD2DBitmap = XDirect2DManager.LoadFromResource(mSource.PathData); } mBoundsRect.Width = (Single)mD2DBitmap.PixelSize.Width; mBoundsRect.Height = (Single)mD2DBitmap.PixelSize.Height; } }