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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:51:48+00:00 2026-06-16T05:51:48+00:00

I am trying to save an image I have processed in my program. e.g.

  • 0

I am trying to save an image I have processed in my program. e.g. added pseudocolor to the original image

I have tried a few methods, each time i get an error.

A generic error occurred in GDI+.

Can anyone tell me how to properly implement a save method?

Here is the latest attempt:

    using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace IMGPROC
{



    public partial class Form1 : Form
    {
        public Bitmap original_image, proc_image;

        public Form1()
        {
            InitializeComponent();
            original_image = null;
            proc_image = null;

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        public void Form1_Paint(object sender, PaintEventArgs e)
        {
            if (original_image != null)
            {
                Graphics g = e.Graphics;
                Rectangle r = new Rectangle(10, 50, original_image.Width, original_image.Height);
                g.DrawImage(original_image, r);


            }

        }

        //                OPEN IMAGE FILE
        /******************************************************************************************/

        private void openToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            // show the openFile dialog box            
            Graphics g = this.CreateGraphics();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                original_image = new Bitmap(openFileDialog1.FileName);

            }

            Rectangle r = new Rectangle(10, 50, original_image.Width, original_image.Height);
            g.DrawImage(original_image, r);
        }

        //                SAVE IMAGE FILE
        /******************************************************************************************/

        private void saveAsToolStripMenuItem_Click(object sender, System.EventArgs e)
        {
            SaveFileDialog save = new SaveFileDialog();
            save.Filter = "Bitmap Image (.bmp)|*.bmp|Gif Image (.gif)|*.gif |JPEG Image (.jpeg)|*.jpeg |Png Image (.png)|*.png |Tiff Image (.tiff)|*.tiff |Wmf Image (.wmf)|*.wmf |All files (*.*)|*.*";
            save.FilterIndex = 4;
            save.InitialDirectory = "C:\\";
            save.RestoreDirectory = true;

            if (save.ShowDialog() == DialogResult.OK)
            {
                proc_image.Save(save.InitialDirectory);
            }
        }

        //                 EXIT APPLICATION
        /************************************************************************************/

        private void exitToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            Dispose();
            Application.Exit();
        }

        private void btnRed_Click(object sender, System.EventArgs e)
        {


            Graphics g = this.CreateGraphics();

            int width = original_image.Width;
            int height = original_image.Height;

            Color pixel;

            Rectangle r = new Rectangle(535, 50, original_image.Width, original_image.Height);
            Rectangle r2 = new Rectangle(0, 0, original_image.Width, original_image.Height);
            Rectangle r3 = new Rectangle(10, 50, original_image.Width, original_image.Height);


            g.DrawImage(original_image, r3);

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

            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                   pixel = original_image.GetPixel(x, y);
                   proc_image.SetPixel(x, y, Color.FromArgb(pixel.R, 0, 0));   
                }
            } g.DrawImage(proc_image, r);

        }

        private void btnGreen_Click(object sender, System.EventArgs e)
        {

            Graphics g = this.CreateGraphics();

            int width = original_image.Width;
            int height = original_image.Height;

            Color pixel;

            Rectangle r = new Rectangle(535, 50, original_image.Width, original_image.Height);
            Rectangle r2 = new Rectangle(0, 0, original_image.Width, original_image.Height);
            Rectangle r3 = new Rectangle(10, 50, original_image.Width, original_image.Height);

            g.DrawImage(original_image, r3);

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

            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {

                  pixel = original_image.GetPixel(x, y);
                  bitmap_colour.SetPixel(x, y, Color.FromArgb(0, pixel.G, 0));

                }
            } g.DrawImage(bitmap_colour, r);

        }

        private void btnBlue_Click(object sender, System.EventArgs e)
        {

            Graphics g = this.CreateGraphics();

            int width = original_image.Width;
            int height = original_image.Height;

            Color pixel;

            Rectangle r = new Rectangle(535, 50, original_image.Width, original_image.Height);
            Rectangle r2 = new Rectangle(0, 0, original_image.Width, original_image.Height);
            Rectangle r3 = new Rectangle(10, 50, original_image.Width, original_image.Height);


            g.DrawImage(original_image, r3);

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

            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                   pixel = original_image.GetPixel(x, y);
                   bitmap_colour.SetPixel(x, y, Color.FromArgb(0, 0, pixel.B));
                }

            } g.DrawImage(bitmap_colour, r);

        }

        private void pseudocolorToolStripMenuItem_Click(object sender, System.EventArgs e)
        {
            checkImageOpen();

            btnRed.Visible = true;
            btnGreen.Visible = true;
            btnBlue.Visible = true;

            Graphics g = this.CreateGraphics();

            int width = original_image.Width;
            int height = original_image.Height;


            Rectangle r = new Rectangle(535, 50, original_image.Width, original_image.Height);
            Rectangle r2 = new Rectangle(0, 0, original_image.Width, original_image.Height);
            Rectangle r3 = new Rectangle(10, 50, original_image.Width, original_image.Height);


            g.DrawImage(original_image, r3);

        }

            }

        }
  • 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-16T05:51:50+00:00Added an answer on June 16, 2026 at 5:51 am
    if (save.ShowDialog() == DialogResult.OK)
    {
        proc_image.Save(save.FileName);
    }
    

    Can’t save some thing as a directory, and even if you could you wouldn’t want to use the initial directory..

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

Sidebar

Related Questions

I'm trying to save the value of each pixel in a gray scale image
I'm trying to get an image from URL and save it to the isolated
I'm trying to save an image to card and I get the error <
i am trying to save image outside of my web app directory. i have
I am trying to save image to SD card and I added some code
I am trying to save multiple image using this code. But instead its saving
Hello I am trying to save a bitmap image in a basic image editor
Using PHP I'm trying to download/save the following image: http://www.bobshop.nl/catalog/product_image.php?size=detail&id=42428 When you load this
I'm trying to upload and save a resized image in a db.BlobProperty field on
I am trying to save out a large image from flash using bitmapdata 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.