private void HandleFileSaving() { string destination; // if file format is bitmap save directly to output directory if (renderSettings.FileFormat == FileFormat.bmp) { destination = renderSettings.FilePath + renderSettings.FileName + frameCount.ToString() + "." + renderSettings.FileFormat.ToString(); } // else save to temporary directory else { destination = tempDirectory + "\\" + renderSettings.FileName + frameCount.ToString() + ".bmp"; } // save file SurfaceLoader.Save(destination, ImageFileFormat.Bmp, renderSurface.RenderTarget); // if it as an image other than BMP do conversion if (renderSettings.FileFormat != FileFormat.bmp && renderSettings.FileFormat != FileFormat.avi) { DoImageFileConversion(); } // increment frameCount ++frameCount; }
/*------------------------------------------------------------------------- * 텍스쳐コピー * 例えば시스템메모リ상の텍스쳐をVRAMに전送する등 * 사이즈등はチェックしないので注意 * ---------------------------------------------------------------------------*/ static public bool CopyTexture(Device device, Texture dst_texture, Texture src_texture) { if (device == null) { return(false); } if (src_texture == null) { return(false); } if (dst_texture == null) { return(false); } try{ // 単純にコピー Surface dst = dst_texture.GetSurfaceLevel(0); Surface src = src_texture.GetSurfaceLevel(0); SurfaceLoader.FromSurface(dst, src, Filter.None, 0); dst.Dispose(); src.Dispose(); return(true); }catch { return(false); } }
///<summary> /// @copydoc HardwarePixelBuffer.Blit ///</summary> public override void Blit(HardwarePixelBuffer _src, BasicBox srcBox, BasicBox dstBox) { D3DHardwarePixelBuffer src = (D3DHardwarePixelBuffer)_src; if (surface != null && src.surface != null) { // Surface-to-surface Rectangle dsrcRect = ToD3DRectangle(srcBox); Rectangle ddestRect = ToD3DRectangle(dstBox); // D3DXLoadSurfaceFromSurface SurfaceLoader.FromSurface(surface, ddestRect, src.surface, dsrcRect, Filter.None, 0); } else if (volume != null && src.volume != null) { // Volume-to-volume Box dsrcBox = ToD3DBox(srcBox); Box ddestBox = ToD3DBox(dstBox); // D3DXLoadVolumeFromVolume VolumeLoader.FromVolume(volume, ddestBox, src.volume, dsrcBox, Filter.None, 0); } else { // Software fallback base.Blit(_src, srcBox, dstBox); } }
private async void ApplyEffect(CompositionImage image) { Task <CompositionDrawingSurface> task = null; // If we've requested a load time effect input, kick it off now if (_currentTechnique.LoadTimeEffectHandler != null) { task = SurfaceLoader.LoadFromUri(image.Source, Size.Empty, _currentTechnique.LoadTimeEffectHandler); } // Create the new brush, set the inputs and set it on the image CompositionEffectBrush brush = _currentTechnique.CreateBrush(); brush.SetSourceParameter("ImageSource", image.SurfaceBrush); image.Brush = brush; // If we've got an active task, wait for it to finish if (task != null) { CompositionDrawingSurface effectSurface = await task; // Set the effect surface as input brush.SetSourceParameter("EffectSource", _compositor.CreateSurfaceBrush(effectSurface)); } }
public void Render2() { if (device2 == null) //如果device为空则不渲染 { return; } device2.Clear(ClearFlags.Target, Color.DarkSlateBlue, 1.0f, 0); //清除windows界面为深蓝色 device2.BeginScene(); { //在此添加渲染图形代码 CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[4];//定义顶点 vertices[0].Position = new Vector4(150f, 400f, 0f, 1f); vertices[0].Color = Color.Yellow.ToArgb(); vertices[1].Position = new Vector4(panel2.Width / 2, 100f, 0f, 1f); vertices[1].Color = Color.Green.ToArgb(); vertices[2].Position = new Vector4(panel2.Width - 150f, 400f, 0f, 1f); vertices[2].Color = Color.Red.ToArgb(); device2.VertexFormat = CustomVertex.TransformedColored.Format; device2.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices); //截取panel2的截图 Surface backbuffer = device2.GetBackBuffer(0, 0, BackBufferType.Mono); SurfaceLoader.Save("Screenshot2.bmp", ImageFileFormat.Bmp, backbuffer); } device2.EndScene(); device2.Present(); }
public void SaveScreenshot(string fileName) { Surface backbuffer = d3d.Dx.GetBackBuffer(0, 0, BackBufferType.Mono); SurfaceLoader.Save(fileName, ImageFileFormat.Jpg, backbuffer); backbuffer.Dispose(); }
public static void SaveImage(Device device, string fileName, ImageFileFormat format) { using (Surface backbuffer = device.GetBackBuffer(0, 0, BackBufferType.Mono)) { SurfaceLoader.Save(fileName, format, backbuffer); } }
public static void LoadSurfaceFromVolumeSlice(VolumeTexture volumeTex, int mip, int slice, Filter filter, Surface surface) { VolumeDescription vd = volumeTex.GetLevelDescription(mip); OpsFormatHelper formatHelp = OpsFormatHelper.FindByFormat(vd.Format); Texture sliceTex = new Texture(volumeTex.Device, vd.Width, vd.Height, 1, Usage.None, formatHelp.Format, Pool.SystemMemory); Box box = new Box(); box.Left = 0; box.Right = vd.Width; box.Top = 0; box.Bottom = vd.Height; box.Front = slice; box.Back = slice + 1; LockedBox volumeLB; GraphicsStream volumeData = volumeTex.LockBox(0, box, LockFlags.ReadOnly, out volumeLB); int slicePitch; GraphicsStream sliceData = sliceTex.LockRectangle(mip, LockFlags.None, out slicePitch); CopyTextureData(volumeData, vd.Width, vd.Height, formatHelp, volumeLB.RowPitch, sliceData, slicePitch); sliceTex.UnlockRectangle(0); volumeTex.UnlockBox(mip); SurfaceLoader.FromSurface(surface, sliceTex.GetSurfaceLevel(0), filter, 0); sliceTex.Dispose(); }
public static Texture CloneTexture(Texture oldTexture, int width, int height, int mips, Format format, Usage usage, Filter filter, Pool pool) { Texture newTexture = new Texture(oldTexture.Device, width, height, mips, usage, format, pool); SurfaceLoader.FromSurface(newTexture.GetSurfaceLevel(0), oldTexture.GetSurfaceLevel(0), filter, 0); return(newTexture); }
private async void Page_Loaded(object sender, RoutedEventArgs e) { _backgroundImageVisual = _compositor.CreateSpriteVisual(); _imageContainer = _compositor.CreateContainerVisual(); _imageSurfaceBrush = _compositor.CreateSurfaceBrush(); _capabilities.Changed += HandleCapabilitiesChanged; ElementCompositionPreview.SetElementChildVisual(ImageCanvas, _imageContainer); // Load in image var uri = new Uri("ms-appx:///Assets/Landscapes/Landscape-7.jpg"); var surface = await SurfaceLoader.LoadFromUri(uri); var imageSurface = _compositor.CreateSurfaceBrush(surface); _imageSurfaceBrush.Surface = imageSurface.Surface; _imageSurfaceBrush.Stretch = CompositionStretch.Fill; _imageContainer.Size = new Vector2((float)ImageCanvas.ActualWidth, (float)ImageCanvas.ActualHeight); _imageContainer.Children.InsertAtTop(_backgroundImageVisual); UpdateVisualSizeAndPosition(); UpdateAlbumArt(); }
public static void CopyToCubeSide(OpsContext context, CubeTexture newTexture, string srcArg, CubeMapFace face, Filter filter) { if (srcArg == null || srcArg.Length == 0) { return; } OpsTexture src = context.GetTexture(srcArg); if (src == null) { throw new OpsException("Could not find source texture: " + srcArg); } if (src.Texture is CubeTexture) { SurfaceLoader.FromSurface(newTexture.GetCubeMapSurface(face, 0), ((CubeTexture)src.Texture).GetCubeMapSurface(face, 0), filter | (src.SRGB?Filter.SrgbIn:0), 0); } else if (src.Texture is Texture) { SurfaceLoader.FromSurface(newTexture.GetCubeMapSurface(face, 0), ((Texture)src.Texture).GetSurfaceLevel(0), filter | (src.SRGB?Filter.SrgbIn:0), 0); } else { throw new OpsException("Source texture is not a texture2D: " + srcArg); } }
/// <summary> /// バックバッファをPNG形式でファイルに保存します。 /// </summary> /// <param name="file">ファイル名</param> public void SaveToPng(string file) { using (Surface sf = device.GetBackBuffer(0, 0, BackBufferType.Mono)) if (sf != null) { SurfaceLoader.Save(file, ImageFileFormat.Png, sf); } }
public Picture(string _id, string dayfileName, string nightfileName) { this.id = _id; SurfaceLoader[,] sl = new SurfaceLoader[4, 2]; sl[0, 0] = new BitmapSurfaceLoader(dayfileName); sl[0, 1] = new BitmapSurfaceLoader(nightfileName); this.loaders = init(sl); }
} // _KeyDown().fim // [--- private void salvarImagem() { Surface backbuffer = device.GetBackBuffer(0, 0, BackBufferType.Mono); SurfaceLoader.Save("foto_tela.jpg", ImageFileFormat.Jpg, backbuffer); backbuffer.Dispose(); this.Text = "Ok. Imagem salva no disco"; }
#pragma warning disable 1998 private async void OnLoading(FrameworkElement sender, object args) { this.SizeChanged += OnSizeChanged; OnSizeChanged(this, null); m_noiseBrush.Surface = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Assets/noise.jpg")); m_noiseBrush.Stretch = CompositionStretch.UniformToFill; }
public Shell() { this.InitializeComponent(); SurfaceLoader.Initialize(ElementCompositionPreview.GetElementVisual(this).Compositor); CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true; CoreWindowLogic logic = new CoreWindowLogic(); ShellVM = DataContext as ShellViewModel; }
public MainPage(Rect imageBounds) { this.InitializeComponent(); // Initialize the surface loader SurfaceLoader.Initialize(ElementCompositionPreview.GetElementVisual(this).Compositor); // Show the custome splash screen ShowCustomSplashScreen(imageBounds); }
public DemoPage7() { this.InitializeComponent(); SurfaceLoader.Initialize(ElementCompositionPreview.GetElementVisual(this).Compositor); compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; StartExpressionAnimation(); }
public DemoPage5() { this.InitializeComponent(); SurfaceLoader.Initialize(ElementCompositionPreview.GetElementVisual(this).Compositor); compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; StartExpressionAnimation(); //ParallaxScrollingDemoListView.Loaded += ParallaxScrollingDemoListView_Loaded; }
protected override UIElement CreateShell(Frame rootFrame) { Dispatcher = Window.Current.Dispatcher; var compositor = ElementCompositionPreview.GetElementVisual(rootFrame).Compositor; SurfaceLoader.Initialize(compositor); Toolkit.Animations.SurfaceLoader.Initialize(compositor); _shell.CurrentFrame = rootFrame; return(_shell); }
public DemoPage6() { this.InitializeComponent(); SurfaceLoader.Initialize(ElementCompositionPreview.GetElementVisual(this).Compositor); rootVisual = ElementCompositionPreview.GetElementVisual(this); compositor = rootVisual.Compositor; AddInteractableImage(); }
// konoa modified. public Bitmap GetBitmap() { Bitmap retval; using (Surface backbuffer = device.GetBackBuffer(0, 0, BackBufferType.Mono)) using (GraphicsStream gStr = SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, backbuffer)) { retval = (Bitmap)Bitmap.FromStream(gStr); } return(retval); }
private CharacterContext(Character character) { // いもうとの定義 Character = character; // ルートディレクトリ BaseDirectory = character.Directory; // プロファイルを読み込む Profile = Profile.LoadFrom(Path.Combine(BaseDirectory, "profile.yml")) ?? new Profile { Age = Character.Age, TsundereLevel = Character.TsundereLevel }; // バルーン読み込み Balloon = BalloonManager.GetValueOrDefault(Profile.LastBalloon); // ルートからイメージ用ディレクトリを作る SurfaceLoader = new SurfaceLoader(Path.Combine(BaseDirectory, "images")); // ウィンドウを作成する BalloonWindow = new BalloonWindow { Context = this, Balloon = Balloon, LocationOffset = Profile.BalloonOffset }; CharacterWindow = new CharacterWindow { Context = this, BalloonWindow = BalloonWindow }; // メニューのコマンドを定義する var contextMenu = CharacterWindow.ContextMenu; contextMenu.CommandBindings.Add(new CommandBinding(Input.DefaultCommands.Character, CharacterCommand_Executed, CharacterCommand_CanExecute)); contextMenu.CommandBindings.Add(new CommandBinding(Input.DefaultCommands.Balloon, BalloonCommand_Executed, BalloonCommand_CanExecute)); contextMenu.CommandBindings.Add(new CommandBinding(Input.DefaultCommands.Option, OptionCommand_Executed)); contextMenu.CommandBindings.Add(new CommandBinding(Input.DefaultCommands.Version, VersionCommand_Executed)); contextMenu.CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, CloseCommand_Executed)); // スクリプトエンジンを作成する ScriptEngine = new ScriptEngine(Path.Combine(BaseDirectory, "scripts")); InitializeScriptEngine(); // スクリプトプレイヤーを作成 ScriptPlayer = new ScriptPlayer(this); RemoteConnectionManager = new RemoteConnectionManager(); RemoteCommandManager = new RemoteCommandManager(Character, RemoteConnectionManager); }
public Image Screenshot(ImageFileFormat format) { Surface backbuffer = device.GetBackBuffer(0, 0, BackBufferType.Mono); System.IO.Stream s = SurfaceLoader.SaveToStream(format, backbuffer); Image i = Image.FromStream(s); backbuffer.Dispose(); return(i); }
public static CubeTexture CloneCube(CubeTexture oldTexture, int size, int mips, Format format, Usage usage, Filter filter, Pool pool) { CubeTexture newTexture = new CubeTexture(oldTexture.Device, size, mips, usage, format, pool); SurfaceLoader.FromSurface(newTexture.GetCubeMapSurface(CubeMapFace.NegativeX, 0), oldTexture.GetCubeMapSurface(CubeMapFace.NegativeX, 0), filter, 0); SurfaceLoader.FromSurface(newTexture.GetCubeMapSurface(CubeMapFace.NegativeY, 0), oldTexture.GetCubeMapSurface(CubeMapFace.NegativeY, 0), filter, 0); SurfaceLoader.FromSurface(newTexture.GetCubeMapSurface(CubeMapFace.NegativeZ, 0), oldTexture.GetCubeMapSurface(CubeMapFace.NegativeZ, 0), filter, 0); SurfaceLoader.FromSurface(newTexture.GetCubeMapSurface(CubeMapFace.PositiveX, 0), oldTexture.GetCubeMapSurface(CubeMapFace.PositiveX, 0), filter, 0); SurfaceLoader.FromSurface(newTexture.GetCubeMapSurface(CubeMapFace.PositiveY, 0), oldTexture.GetCubeMapSurface(CubeMapFace.PositiveY, 0), filter, 0); SurfaceLoader.FromSurface(newTexture.GetCubeMapSurface(CubeMapFace.PositiveZ, 0), oldTexture.GetCubeMapSurface(CubeMapFace.PositiveZ, 0), filter, 0); return(newTexture); }
public Bitmap SaveToBitmap(Device device) { using (Surface backbuffer = device.GetBackBuffer(0, 0, BackBufferType.Mono)) { if (bufferSurface == null) { CreateBufferSurface(device, backbuffer.Description); } device.GetRenderTargetData(backbuffer, bufferSurface); } using (GraphicsStream gStr = SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, bufferSurface)) return((Bitmap)Bitmap.FromStream(gStr)); }
void lightPreviewControl2_OnNewPreview(object sender, EventArgs e) { // put texture onto side image preview Texture tex = (Texture)sender; GraphicsStream stream = SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, tex.GetSurfaceLevel(0)); Image img = Bitmap.FromStream(stream); pictureBox7.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox7.Image = img; tex.Dispose(); }
public void Run(OpsContext context, OpsStatement statement) { Slice2dArgs args = statement.Arguments as Slice2dArgs; ArrayList containers = statement.GetContent(context); if (containers.Count != 1) { throw new OpsException("Src argument does not resolve to 1 texture. Textures found: " + containers.Count); } OpsTexture container = containers[0] as OpsTexture; OpsConsole.WriteLine("Slicing from texture:{0} and saving as {1}", container.Name, args.Dst); OpsTexture result = new OpsTexture(); result.Name = args.Dst; result.SRGB = container.SRGB; Texture newTexture = null; if (container.Texture is Texture) { Texture srcTexture = container.Texture as Texture; SurfaceDescription sd = srcTexture.GetLevelDescription(args.Mips); newTexture = new Texture(srcTexture.Device, sd.Width, sd.Height, 1, Usage.None, sd.Format, Pool.Managed); SurfaceLoader.FromSurface(newTexture.GetSurfaceLevel(0), srcTexture.GetSurfaceLevel(0), Filter.Dither | Filter.Triangle | (container.SRGB?Filter.Srgb:0), 0); } else if (container.Texture is VolumeTexture) { VolumeTexture srcTexture = container.Texture as VolumeTexture; VolumeDescription vd = srcTexture.GetLevelDescription(args.Mips); newTexture = new Texture(srcTexture.Device, vd.Width, vd.Height, 1, Usage.None, vd.Format, Pool.Managed); OpsTextureHelper.LoadSurfaceFromVolumeSlice(srcTexture, args.Mips, args.Volume, Filter.Dither | Filter.Triangle | (container.SRGB?Filter.Srgb:0), newTexture.GetSurfaceLevel(0)); } else if (container.Texture is CubeTexture) { CubeTexture srcTexture = container.Texture as CubeTexture; SurfaceDescription sd = srcTexture.GetLevelDescription(args.Mips); newTexture = new Texture(srcTexture.Device, sd.Width, sd.Height, 1, Usage.None, sd.Format, Pool.Managed); SurfaceLoader.FromSurface(newTexture.GetSurfaceLevel(0), srcTexture.GetCubeMapSurface(args.Face, 0), Filter.Dither | Filter.Triangle | (container.SRGB?Filter.Srgb:0), 0); } result.Texture = newTexture; context.AddTexture(result); }
private void использоватьGPUToolStripMenuItem_Click(object sender, EventArgs e) { if (pictureBox1.Image == null) { return; } Surface newbb = dr.CreateRenderTarget(bmhm.Width, bmhm.Height, Format.A8R8G8B8, MultiSampleType.None, 0, true); Surface oldbb = dr.GetRenderTarget(0); dr.SetRenderTarget(0, newbb); dr.BeginScene(); dr.Clear(ClearFlags.Target, Color.Black, 1f, 0); //Очистка фона eff.SetValue("w", Matrix.Scaling(2.0f, 2.0f, 2.0f)); eff.SetValue("v", Matrix.RotationX(0)); eff.SetValue("p", Matrix.RotationX(0)); eff.SetValue("txh", txh); eff.SetValue("h", himax); eff.Begin(FX.None); eff.BeginPass(2); dr.VertexFormat = CustomVertex.PositionNormalTextured.Format; dr.DrawUserPrimitives(PrimitiveType.TriangleFan, 2, dp); eff.EndPass(); eff.End(); dr.EndScene(); if (pictureBox2.Image != null) { pictureBox2.Image.Dispose(); } if (gstr != null) { gstr.Dispose(); } gstr = SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, newbb); if (bmnm != null) { bmnm.Dispose(); } bmnm = (Bitmap)Image.FromStream(gstr); pictureBox2.Image = (Image)bmnm; hdv = (float)bmnm.Width / (float)bmnm.Height; if (txn != null) { txn.Dispose(); } txn = Texture.FromBitmap(dr, bmnm, Usage.None, Pool.Managed); dr.SetRenderTarget(0, oldbb); newbb.Dispose(); oldbb.Dispose(); }
public void SaveToBitmap() { using (Surface sf = device.GetBackBuffer(0, 0, BackBufferType.Mono)) if (sf != null) { string path = GetBitmapPath(); string dir = Path.GetDirectoryName(path); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } SurfaceLoader.Save(path, ImageFileFormat.Png, sf); } }