Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8663835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:05:16+00:00 2026-06-12T17:05:16+00:00

I develop Metro-application with SharpDx under Direct2D. I drew some picture using deviceContext .

  • 0

I develop Metro-application with SharpDx under Direct2D. I drew some picture using deviceContext. How I can save my picture to png-file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:05:17+00:00Added an answer on June 12, 2026 at 5:05 pm

    Solution:

      public class Direct2DImageEncoder
      {
        private readonly Direct2DFactoryManager factoryManager;
        private readonly Bitmap wicBitmap;
        private readonly WicRenderTarget renderTarget;
    
        private readonly int imageWidth, imageHeight;
    
        public Direct2DImageEncoder(int imageWidth, int imageHeight, int imageDpi)
        {
          this.imageWidth = imageWidth;
          this.imageHeight = imageHeight;      
    
          factoryManager = new Direct2DFactoryManager();
    
          wicBitmap = new Bitmap(factoryManager.WicFactory, imageWidth, imageHeight, SharpDX.WIC.PixelFormat.Format32bppBGR, BitmapCreateCacheOption.CacheOnLoad);
          var renderTargetProperties = new RenderTargetProperties(RenderTargetType.Default, new PixelFormat(Format.Unknown, AlphaMode.Unknown), imageDpi, imageDpi, RenderTargetUsage.None, FeatureLevel.Level_DEFAULT);
          renderTarget = new WicRenderTarget(factoryManager.D2DFactory, wicBitmap, renderTargetProperties);
          renderTarget.BeginDraw();
          renderTarget.Clear(Colors.White);
        }
    
        public void Save(Stream systemStream, Direct2DImageFormat format)
        {
          renderTarget.EndDraw();
    
          var stream = new WICStream(factoryManager.WicFactory, systemStream);
          var encoder = new BitmapEncoder(factoryManager.WicFactory, Direct2DConverter.ConvertImageFormat(format));
          encoder.Initialize(stream);
    
          var bitmapFrameEncode = new BitmapFrameEncode(encoder);
          bitmapFrameEncode.Initialize();
          bitmapFrameEncode.SetSize(imageWidth, imageHeight);
          bitmapFrameEncode.PixelFormat = SharpDX.WIC.PixelFormat.FormatDontCare;
          bitmapFrameEncode.WriteSource(wicBitmap);
    
          bitmapFrameEncode.Commit();
          encoder.Commit();
    
          bitmapFrameEncode.Dispose();
          encoder.Dispose();
          stream.Dispose();      
        }   
      }
    
      public class Direct2DFactoryManager
      {
        private readonly SharpDX.WIC.ImagingFactory wicFactory;
        private readonly SharpDX.Direct2D1.Factory d2DFactory;
        private readonly SharpDX.DirectWrite.Factory dwFactory;
    
        public Direct2DFactoryManager()
        {
          wicFactory = new SharpDX.WIC.ImagingFactory();
          d2DFactory = new SharpDX.Direct2D1.Factory();
          dwFactory = new SharpDX.DirectWrite.Factory();
        }
    
        public SharpDX.WIC.ImagingFactory WicFactory
        {
          get
          {
            return wicFactory;
          }
        }
    
        public SharpDX.Direct2D1.Factory D2DFactory
        {
          get
          {
            return d2DFactory;
          }
        }
    
        public SharpDX.DirectWrite.Factory DwFactory
        {
          get
          {
            return dwFactory;
          }
        }
      }
    
      public enum Direct2DImageFormat
      {
        Png, Gif, Ico, Jpeg, Wmp, Tiff, Bmp
      }
    
      public class Direct2DConverter
      {
        public static Guid ConvertImageFormat(Direct2DImageFormat format)
        {
          switch (format)
          {
            case Direct2DImageFormat.Bmp:
              return ContainerFormatGuids.Bmp;
            case Direct2DImageFormat.Ico:
              return ContainerFormatGuids.Ico;
            case Direct2DImageFormat.Gif:
              return ContainerFormatGuids.Gif;
            case Direct2DImageFormat.Jpeg:
              return ContainerFormatGuids.Jpeg;
            case Direct2DImageFormat.Png:
              return ContainerFormatGuids.Png;
            case Direct2DImageFormat.Tiff:
              return ContainerFormatGuids.Tiff;
            case Direct2DImageFormat.Wmp:
              return ContainerFormatGuids.Wmp;
          }
          throw new NotSupportedException();
        }
    
        #endregion
      }
    

    You should use methods of renderTarget for drawing

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to develop Metro style application using C# and XAML which has to
I currently develop a metro style app using mvvm light framework. I have some
I develop on J2ME test App, I can install in my old nokia using
I want to develop Windows WPF application using Kinect with great GUI/NUI. I've found
I develop an application using Struts, Spring, and Hibernate. My DAOs uses spring jdbc
Does Win8 App Store accept application written in c++? I develop wp7 app using
I want to develop an application for WP7 using HTML,CSS and Javascript something Similar
I develop some unit tests but fail on all SQL statements, can you please
How to develop an application UI like Metro for Windows Vista/7 github recently released
i am trying a develop a application..following is a snippet class metro_nodes { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.