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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:16:13+00:00 2026-05-17T20:16:13+00:00

I’m trying to load images (pdfs and Word documents) from a memory stream so

  • 0

I’m trying to load images (pdfs and Word documents) from a memory stream so I can manipulate them before they get added to a pdf. Whenever I try and load a bitmap or a GIF I get one of the dreaded GDI+ errors.

This call…

System.Drawing.Bitmap myImage = System.Drawing.Image.FromStream(docStream);  

Generates this error…

System.Runtime.InteropServices.ExternalException occurred
  Message="A generic error occurred in GDI+."
  Source="System.Drawing"
  ErrorCode=-2147467259
  StackTrace:
       at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
       at System.Drawing.Image.FromStream(Stream stream)  

and this call…

System.Drawing.Bitmap myImage = new System.Drawing.Bitmap(docStream);

Generates this error…

System.ArgumentException occurred
  Message="Parameter is not valid."
  Source="System.Drawing"
  StackTrace:
       at System.Drawing.Bitmap..ctor(Stream stream)

The code works for png, jpg and tif, but not for bmp or GIF.

It’s basically:

MemoryStream docStream = GetMemoryStream(filePath);
// The next line errors...
System.Drawing.Bitmap myImage = new System.Drawing.Bitmap(docStream);

    private MemoryStream GetMemoryStream(string file)
    {
        FileStream fs = null;
        Byte[] bytes;
        int len;

        fs = File.OpenRead(file);
        len = (int)fs.Length - 1;
        bytes = new Byte[len];
        fs.Read(bytes, 0, len);

        return new MemoryStream(bytes);

    }

I’m not closing the MemoryStream anywhere and unless the png and jpg aren’t affected by a closed MemoryStream I don’t think that’s the issue. When I look at the image files using a hex editor it doesn’t appear that the encoding is incorrect. I’ve also tried different file sizes, just in case.

At this point I’m pretty much at a loss. Any help would be greatly appreciated.

Thanks.

  • 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-17T20:16:14+00:00Added an answer on May 17, 2026 at 8:16 pm
        len = (int)fs.Length - 1;
    

    Not sure why you thought that was a good idea, used to program in VB? Drop the -1, you want to read all the bytes, not all the bytes minus the last one. File.ReadAllBytes() would be a good choice.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.