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 7654919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:22:46+00:00 2026-05-31T12:22:46+00:00

I am creating images in various formats in WPF using BitmapEncoder. For example, to

  • 0

I am creating images in various formats in WPF using BitmapEncoder. For example, to create a png image from a FrameworkElement, i am using the following code,

        BitmapEncoder imgEncoder = new PngBitmapEncoder();
        RenderTargetBitmap renderBitmap = new RenderTargetBitmap(32, 32, 96d, 96d, PixelFormats.Pbgra32);
        renderBitmap.Render(controlToConvert);
        imgEncoder.Frames.Add(BitmapFrame.Create(renderBitmap));

I like to create an .ico file in the same way. But I cannot find any IconBitmapEncoder in WPF. Is there any other way to do it?

Regards,

Jawahar

  • 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-05-31T12:22:47+00:00Added an answer on May 31, 2026 at 12:22 pm

    There is none.

    I have tried to save images as *.ico in the past and other .NET classes did not really help (if i remember correctly they could only decode, not encode; but maybe i just did something wrong). *.ico can be a container for PNG images (there may be backwards compatibility issues though), so you can stick a full PNG in there with the right headers which could be found on wikipedia.

    Example implementation:

    public static class PngToIcoConverter
    {
        public static byte[] Convert(byte[] data)
        {
            Image source;
            using (var inStream = new MemoryStream(data))
            {
                source = Image.FromStream(inStream);
            }
            byte[] output;
            using (var outStream = new MemoryStream())
            {
                // Header
                {
                    // Reserved
                    outStream.WriteByte(0);
                    outStream.WriteByte(0);
                    // File format (ico)
                    outStream.WriteByte(1);
                    outStream.WriteByte(0);
                    // Image count (1)
                    outStream.WriteByte(1);
                    outStream.WriteByte(0);
                }
    
                // Image entry
                {
                    // Width
                    outStream.WriteByte((byte)source.Width);
                    // Height
                    outStream.WriteByte((byte)source.Height);
                    // Number of colors (0 = No palette)
                    outStream.WriteByte(0);
                    // Reserved
                    outStream.WriteByte(0);
                    // Color plane (1)
                    outStream.WriteByte(1);
                    outStream.WriteByte(0);
                    // Bits per pixel
                    var bppAsLittle = IntToLittle2(Image.GetPixelFormatSize(source.PixelFormat));
                    outStream.Write(bppAsLittle, 0, 2);
                    // Size of data in bytes
                    var byteCountAsLittle = IntToLittle4(data.Length);
                    outStream.Write(byteCountAsLittle, 0, 4);
                    // Offset of data from beginning of file (data begins right here = 22)
                    outStream.WriteByte(22);
                    outStream.WriteByte(0);
                    outStream.WriteByte(0);
                    outStream.WriteByte(0);
                    // Data
                    outStream.Write(data, 0, data.Length);
                }
                output = outStream.ToArray();
            }
            return output;
        }
    
        private static byte[] IntToLittle2(int input)
        {
            byte[] b = new byte[2];
            b[0] = (byte)input;
            b[1] = (byte)(((uint)input >> 8) & 0xFF);
            return b;
        }
        private static byte[] IntToLittle4(int input)
        {
            byte[] b = new byte[4];
            b[0] = (byte)input;
            b[1] = (byte)(((uint)input >> 8) & 0xFF);
            b[2] = (byte)(((uint)input >> 16) & 0xFF);
            b[3] = (byte)(((uint)input >> 24) & 0xFF);
            return b;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating several image dynamically using the following code: function refresh_gallery(galleryidentifier, albumid) {
I'm trying to create a transparent png image and layer various other pngs and
I'm creating some videos from a collection of images, I subsequently wish to play
Is there any free tool available for creating and editing PNG Images?
i am using itextsharp and creating a PDF with images. currently the images i
I have been creating an image gallery with jQuery, all is done. The images
I'm using this php class ( http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php ) for creating the different sized images
I am creating an image dynamically using php. The image is being created if
I want to dynamically create some image from Java and save it to a
I'm in the process of creating a gallery which displays several formats of images

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.