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

  • Home
  • SEARCH
  • 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 8553403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:38:36+00:00 2026-06-11T14:38:36+00:00

Any clue why that error happens? outputStream cannot be null Thank you! public FileContentResult

  • 0

Any clue why that error happens?

outputStream  cannot be null

Thank you!

public FileContentResult DisplayFont(string fontID)
        {
            int fontSize = 12;

            string fontName = "Arial";

            System.Drawing.Font rectangleFont = new System.Drawing.Font(fontName, fontSize, FontStyle.Bold);

            int height = 150;

            int width = 250;

            Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);

            Graphics g = Graphics.FromImage(bitmap);

            g.SmoothingMode = SmoothingMode.AntiAlias;

            Color backgroundColor = Color.White;

            g.Clear(backgroundColor);

            g.DrawString(fontName, rectangleFont,SystemBrushes.WindowText, new PointF(10, 40));

            Stream outputStream = null;

            bitmap.Save(outputStream,  ImageFormat.Jpeg); // ERROR

            byte[] byteArray = ReadFully(outputStream);

            g.Dispose();

            bitmap.Dispose(); 

            return new FileContentResult(byteArray, "image/jpeg");
        }



 public static byte[] ReadFully(Stream input)
        {
            byte[] buffer = new byte[16 * 1024];
            using (MemoryStream ms = new MemoryStream())
            {
                int read;
                while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
                {
                    ms.Write(buffer, 0, read);
                }
                return ms.ToArray();
            }
        }
  • 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-11T14:38:37+00:00Added an answer on June 11, 2026 at 2:38 pm

    OutputStream is null. It should be,

     Stream outputStream = new MemoryStream();
    

    EDIT:

    int height = 150;
    int width = 250;
    byte []byteArray=null;
    
    using (Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb))
    {
        int fontSize = 12;
        string fontName = "Arial";
        System.Drawing.Font rectangleFont = new System.Drawing.Font(fontName, fontSize, FontStyle.Bold);
        Graphics g = Graphics.FromImage(bitmap);
        g.SmoothingMode = SmoothingMode.AntiAlias;
        Color backgroundColor = Color.White;
        g.Clear(backgroundColor);
        g.DrawString(fontName, rectangleFont, SystemBrushes.WindowText, new PointF(10, 40));
    
        using (MemoryStream outputStream = new MemoryStream())
        {
            bitmap.Save(outputStream, ImageFormat.Jpeg);
            byteArray = outputStream.ToArray();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be a dummy question, but I cannot find any clue in all
I spent about hour and did not find any clue how to highlight my
I tried: config.assets.logger = nil And config.assets.logger = false Any clue how to get
I was asked this question today by a colleague, and couldn't find any clue
I have no clue of where to start on this. I've never done any
Any Access guru's out there that can help me out? Trying to figure out
Any phone numbers that begin with these ranges correct: ex: 772123322 The length is
In Radiant CMS when I'm trying to save any page that has any PageType
Javascript has this great callback window.onerror . It's quite convenient to track any error.
When I try to run 'rails server' it's giving me an error saying that

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.