/// <summary> /// Событие переключения кнопки инверсии цвета изображения. /// </summary> private void InvertColorButton_Click(object sender, RoutedEventArgs e) { if (InvertColorButton.IsChecked == true) { InvertColorEffect ice = new InvertColorEffect(); content.Effect = ice; InvColButFillImg.Fill = Brushes.White; } else { content.Effect = null; InvColButFillImg.Fill = new SolidColorBrush(Color.FromArgb(204, 17, 158, 218)); } }
/// <summary> /// 處理變動後的Image /// </summary> /// <param name="sourceImage">圖片來源</param> /// <param name="angle">旋轉角度</param> /// <param name="startX">裁切起始點X</param> /// <param name="startY">裁切起始點Y</param> /// <param name="width">裁切寬</param> /// <param name="height">裁切高</param> /// <param name="filePath">圖片路徑</param> public void DealNewImage(BitmapImage sourceImage, double angle, int startX, int startY, int width, int height, string filePath) { try { bool isEditRotate = sliderRotate.Value != defaultRotateAngle ? true : false; bool isEditWidth = border.Width != rectangle.Width ? true : false; bool isEditHeight = border.Height != rectangle.Height ? true : false; bool isEditBrightness = sliderBrightness.Value != defaultBrightness ? true : false; bool isEditContrast = sliderContrast.Value != defaultConstrast ? true : false; ContrastAdjustEffect effectBrightnessContrast = (ContrastAdjustEffect)filterBrightnessContrast.Effect; bool isEditSharpen = sliderSharpen.Value != defaultSharpen ? true : false; SharpenEffect effectSharpen = (SharpenEffect)filterSharpen.Effect; bool isEditDefog = sliderDefog.Value != defaultDefog ? true : false; bool isEditExposure = sliderExposure.Value != defaultExposure ? true : false; bool isEditGamma = sliderGamma.Value != defaultGamma ? true : false; ToneMappingEffect effectExposureGamma = (ToneMappingEffect)filterExposureGamma.Effect; bool isEditGrayScale = (bool)checkboxGrayScale.IsChecked ? true : false; GrayScaleEffect effectGrayScale = (GrayScaleEffect)filterGrayScale.Effect; bool isEditInvertColor = (bool)checkboxInvertColor.IsChecked ? true : false; InvertColorEffect effectInvertColor = (InvertColorEffect)filterInvertColor.Effect; if (isEditRotate || isEditWidth || isEditWidth) { TransformGroup transformGroup = new TransformGroup(); RotateTransform rotateTransform = new RotateTransform(angle); rotateTransform.CenterX = sourceImage.PixelWidth / 2.0; rotateTransform.CenterY = sourceImage.PixelHeight / 2.0; transformGroup.Children.Add(rotateTransform); TranslateTransform translateTransform = new TranslateTransform(); translateTransform.X = -startX; translateTransform.Y = -startY; transformGroup.Children.Add(translateTransform); DrawingVisual vis = new DrawingVisual(); RenderTargetBitmap rtb; using (DrawingContext cont = vis.RenderOpen()) { cont.PushTransform(transformGroup); cont.DrawImage(sourceImage, new Rect(new Size(sourceImage.PixelWidth, sourceImage.PixelHeight))); cont.Close(); rtb = new RenderTargetBitmap(width, height, 96d, 96d, PixelFormats.Default); SaveNewImage(rtb, vis, filePath); sourceImage = new CreateBitmapImage().BitmapImageOriginal(ImageInfo.Image_FullPath); } } if (isEditBrightness || isEditContrast) { DrawingVisual vis = new DrawingVisual(); RenderTargetBitmap rtb = new RenderTargetBitmap(sourceImage.PixelWidth, sourceImage.PixelHeight, 96d, 96d, PixelFormats.Default);; using (DrawingContext cont = vis.RenderOpen()) { cont.DrawImage(sourceImage, new Rect(new Size(sourceImage.PixelWidth, sourceImage.PixelHeight))); cont.Close(); vis.Effect = effectBrightnessContrast; SaveNewImage(rtb, vis, filePath); sourceImage = new CreateBitmapImage().BitmapImageOriginal(ImageInfo.Image_FullPath); } } if (isEditSharpen) { DrawingVisual vis = new DrawingVisual(); RenderTargetBitmap rtb = new RenderTargetBitmap(sourceImage.PixelWidth, sourceImage.PixelHeight, 96d, 96d, PixelFormats.Default);; using (DrawingContext cont = vis.RenderOpen()) { cont.DrawImage(sourceImage, new Rect(new Size(sourceImage.PixelWidth, sourceImage.PixelHeight))); cont.Close(); vis.Effect = effectSharpen; SaveNewImage(rtb, vis, filePath); sourceImage = new CreateBitmapImage().BitmapImageOriginal(ImageInfo.Image_FullPath); } } if (isEditDefog || isEditExposure || isEditGamma) { DrawingVisual vis = new DrawingVisual(); RenderTargetBitmap rtb = new RenderTargetBitmap(sourceImage.PixelWidth, sourceImage.PixelHeight, 96d, 96d, PixelFormats.Default);; using (DrawingContext cont = vis.RenderOpen()) { cont.DrawImage(sourceImage, new Rect(new Size(sourceImage.PixelWidth, sourceImage.PixelHeight))); cont.Close(); vis.Effect = effectExposureGamma; SaveNewImage(rtb, vis, filePath); sourceImage = new CreateBitmapImage().BitmapImageOriginal(ImageInfo.Image_FullPath); } } if (isEditGrayScale) { DrawingVisual vis = new DrawingVisual(); RenderTargetBitmap rtb = new RenderTargetBitmap(sourceImage.PixelWidth, sourceImage.PixelHeight, 96d, 96d, PixelFormats.Default);; using (DrawingContext cont = vis.RenderOpen()) { cont.DrawImage(sourceImage, new Rect(new Size(sourceImage.PixelWidth, sourceImage.PixelHeight))); cont.Close(); vis.Effect = effectGrayScale; SaveNewImage(rtb, vis, filePath); sourceImage = new CreateBitmapImage().BitmapImageOriginal(ImageInfo.Image_FullPath); } } if (isEditInvertColor) { DrawingVisual vis = new DrawingVisual(); RenderTargetBitmap rtb = new RenderTargetBitmap(sourceImage.PixelWidth, sourceImage.PixelHeight, 96d, 96d, PixelFormats.Default);; using (DrawingContext cont = vis.RenderOpen()) { cont.DrawImage(sourceImage, new Rect(new Size(sourceImage.PixelWidth, sourceImage.PixelHeight))); cont.Close(); vis.Effect = effectInvertColor; SaveNewImage(rtb, vis, filePath); sourceImage = new CreateBitmapImage().BitmapImageOriginal(ImageInfo.Image_FullPath); } } } catch (Exception ex) { ErrorLog.ErrorMessageOutput(ex.ToString()); } }
/// <summary> /// Событие переключения кнопки инверсии цвета изображения. /// </summary> private void InvertColorButton_Click(object sender, RoutedEventArgs e) { if (InvertColorButton.IsChecked == true) { InvertColorEffect ice = new InvertColorEffect(); content.Effect = ice; InvColButFillImg.Fill = Brushes.White; } else { content.Effect = null; InvColButFillImg.Fill = new SolidColorBrush(Color.FromArgb(204, 17, 158, 218)); } }
public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; graphics.GraphicsProfile = GraphicsProfile.HiDef; graphics.PreferredBackBufferWidth = 1920; graphics.PreferredBackBufferHeight = 1080; IsMouseVisible = true; kbm = new KeyboardStateManager(this); camera = new Base3DCamera(this, .5f, 20000); camera.Position = new Vector3(0, 0, 0); Components.Add(camera); Services.AddService(typeof(Base3DCamera), camera); skyBox = new BaseSkyBox(this, "Textures/SkyBox/NebulaBlue"); Components.Add(skyBox); bunny = new Base3DObject(this, "Models/bunny", "Shaders/RenderObjectNotTangentsOrTexCoords"); bunny.Position = new Vector3(2, -1.5f, -20); bunny.LightPosition = LightPosition; Components.Add(bunny); cube = new Base3DObject(this, "Models/cube"); cube.Position = new Vector3(0, 0, -10); cube.ColorAsset = "Textures/h2mcpCube"; cube.BumpAsset = "Textures/h2mcpCubeNormal"; cube.LightPosition = LightPosition; Components.Add(cube); bunnies = new Base3DObject[10]; for (int s = 0; s < 10; s++) { bunnies[s] = new Base3DObject(this, "Models/Bunny"); bunnies[s].Position = new Vector3(20 + (s * 12), -1.5f, -10 - (s * 12)); bunnies[s].ColorAsset = "Textures/WindmillTopColor"; bunnies[s].BumpAsset = "Textures/WindmillTopNormal"; bunnies[s].LightPosition = LightPosition; Components.Add(bunnies[s]); } landShark = new Base3DObject(this, "Models/landShark"); landShark.Position = new Vector3(-20, 0, -10); landShark.ColorAsset = "Textures/Speeder_diff"; landShark.BumpAsset = "Textures/Speeder_bump"; landShark.LightPosition = LightPosition; Components.Add(landShark); earth = new Base3DObject(this, "Models/sphere"); earth.Position = new Vector3(0, 0, -200); earth.ColorAsset = "Textures/Earth_Diffuse"; earth.BumpAsset = "Textures/Earth_NormalMap"; earth.LightPosition = LightPosition; Components.Add(earth); ppManager = new PostProcessingManager(this); fog = new FogEffect(this, 50, 100, Color.DarkSlateGray); fog.Enabled = false; ppManager.AddEffect(fog); GodRays = new CrepuscularRays(this, LightPosition, "Textures/flare", 1500, .99f, .99f, .5f, .12f, .25f); GodRays.Enabled = false; ppManager.AddEffect(GodRays); sun = new SunEffect(this, LightPosition); sun.Enabled = false; ppManager.AddEffect(sun); bloom = new BloomEffect(this, 1.25f, 1f, 1f, 1f, .25f, 4f); bloom.Enabled = false; ppManager.AddEffect(bloom); dof = new DepthOfFieldEffect(this, 5, 30); dof.Enabled = false; ppManager.AddEffect(dof); haze = new HeatHazeEffect(this, "Textures/bumpmap", false); haze.Enabled = false; ppManager.AddEffect(haze); radialBlur = new RadialBlurEffect(this, 0.009f); radialBlur.Enabled = false; ppManager.AddEffect(radialBlur); ripple = new RippleEffect(this); ripple.Enabled = false; ppManager.AddEffect(ripple); sepia = new SepiaEffect(this); sepia.Enabled = false; ppManager.AddEffect(sepia); greyScale = new GreyScaleEffect(this); greyScale.Enabled = false; ppManager.AddEffect(greyScale); invert = new InvertColorEffect(this); invert.Enabled = false; ppManager.AddEffect(invert); colorFilter = new ColorFilterEffect(this, Color.White, .5f, .5f, .5f); colorFilter.Enabled = false; ppManager.AddEffect(colorFilter); bleach = new BleachEffect(this, 1); bleach.Enabled = false; ppManager.AddEffect(bleach); scanLines = new ScanLinesEffect(this, .001f, .001f, 128); scanLines.Enabled = false; ppManager.AddEffect(scanLines); deRezed = new DeRezedEffect(this, 128); deRezed.Enabled = false; ppManager.AddEffect(deRezed); }