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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:09:46+00:00 2026-05-25T17:09:46+00:00

Im having an issue where I got a method that takes an Image object,

  • 0

Im having an issue where I got a method that takes an Image object, processes it to 1 colour channel (the other 2 are solid black) then returns a new image from the process.

Now the issue I have is that when I create the new image in the method and I look at the object during debugging the image object appears perfectly fine. BUT when I return it to an empty Image object the properties inside that Image object all show “System.ArgumentException”

here is the code of that Method:

    public Image GetRedImage(Image sourceImage)
    {
        using (Bitmap bmp = new Bitmap(sourceImage))
        using (Bitmap redBmp = new Bitmap(sourceImage.Width, sourceImage.Height))
        {
            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    Color pxl = bmp.GetPixel(x, y);
                    Color redPxl = Color.FromArgb((int)pxl.R, 1, 1);

                    redBmp.SetPixel(x, y, redPxl);
                }
            }
            Image tout = (Image)redBmp;

            return tout;
        }

    }

anyone got any ideas on what the hell is going on?

many 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-25T17:09:46+00:00Added an answer on May 25, 2026 at 5:09 pm

    by using the using blocks you are disposing the images as soon as you leave the using scope.

    try to replace these two lines from the top:

    using (Bitmap bmp = new Bitmap(sourceImage))
    using (Bitmap redBmp = new Bitmap(sourceImage.Width, sourceImage.Height))
    

    with:

    Bitmap bmp = new Bitmap(sourceImage);
    Bitmap redBmp = new Bitmap(sourceImage.Width, sourceImage.Height);
    

    now it should work, depending on your program logic you will have to dispose those images manually afterwards.

    you could probably dispose bmp also with the using but surely not the redBmp object as you are basically returning it, so either you clone it and return a clone, or you do not dispose it, or you return a disposed unusable object like what is happening right now.

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

Sidebar

Related Questions

Having an issue here that I have tried everything I can think of but
I'm having an issue with a query that currently uses LEFT JOIN weblog_data AS
I'm having an issue with a standard ASP.NET page that has a TextBox and
I'm having trouble with this. I've got WorkItem which has a method DoWork. WorkItem
I'm having an issue with trying to add a quantity to a product that
I'm having an issue with PBEWithMD5AndDES encryption in iOS. I've got my strings encrypting
I'm having some inheritance issues as I've got a group of inter-related abstract classes
Having an issue with random individuals trying to access an intranet site with a
The issue I'm having is issue with is I'm trying to get the paintComponent
I'm having an issue with my regex. I want to capture <% some stuff

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.