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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:32:22+00:00 2026-06-16T03:32:22+00:00

I have two forms, form one handles the image compression and form two handles

  • 0

I have two forms, form one handles the image compression and form two handles the details.
Details like; browse for a bitmap, image quality and a save file name.

The problem i am having at the moment is the bitmap is returning to form one as null.
This then produces the error Object reference not set to an instance of an object

Where abouts is the problem?
Ive been staring at the screen too long and another pair of eyes could really help.

Code Form1:

    public void compressImg(Bitmap bitmp, string fileName, int quality)
            {

                //string fileName = Microsoft.VisualBasic.Interaction.InputBox("Enter a file name:", "Save File", "JPEGCompress", 250, 250);

                ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
                ImageCodecInfo ici = null;

                foreach (ImageCodecInfo codec in codecs)
                {
                    if (codec.MimeType == "image/jpeg")
                        ici = codec;
                }



                EncoderParameters ep = new EncoderParameters();
                ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)quality);
                bitmp.Save("C:\\" + fileName + ".jpg", ici, ep);

            }

 private void compressAnImageToolStripMenuItem_Click(object sender, EventArgs e)
            {

                string fileName;
                int quality;
                Bitmap bitmp;

                Form2 f2 = new Form2();
                f2.ShowDialog();
                fileName = f2.getFileName;
                quality = f2.getQuality;
                bitmp = f2.getBtmap;

                //Bitmap newbitmp = new Bitmap(bitmp);

                compressImg(bitmp, fileName, quality);

            }

Code Form2:

    public partial class Form2 : Form
    {

        public static string fileName;
        public static int quality;
        public Bitmap bitmp, bitmap1;

        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }

        public string getFileName
        {          
            get { return fileName; }
            set { fileName = txtFileName.Text; }
        }

        public int getQuality
        {
            get { return quality; }
            set { quality = imgQualTrkBar.Value; }
        }

        private void BtnSubmitInfo_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog2.ShowDialog() == DialogResult.OK)
            {
                bitmp = new Bitmap(openFileDialog2.FileName);

            }
        }

        public Bitmap getBtmap
        {
            get { return bitmap1; }
            set { bitmap1 = new Bitmap(bitmp); }
        }

    }
}
  • 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-16T03:32:23+00:00Added an answer on June 16, 2026 at 3:32 am

    Firstly, your error is because you’re storing your Bitmap object in bitmp.. but returning bitmap1 from your getBtmap property.

    Also, you’ve called your properties getSomething when they also have set accessors that don’t accept a value. This will confuse you (as will your variable names.. consider renaming them too).

    Consider this:

    frm.getFileName = "MY FILE NAME";
    

    ..that doesn’t store “MY FILE NAME”.. it stores the textbox value. Consider changing this logic.

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

Sidebar

Related Questions

I have created two forms in my Windows Application. One Form acts as a
I have an application that consists of two forms. One form displays data returned
I have two buttons at the top of a jQuery validated form: one saves
I am trying to have two submit buttons in my form - one accepts
I have two window form applications written in C, one holds a struct consisting
I have two template files: one for the form (loginFormTemplate) and one for the
I have two select fields in a form. Every time one of these select
I am using Asp.net dropdownlist in one of my form ..I have two dropdown
I have a form with two text boxes, one select drop down and one
I have a form with two combo boxes and couple of buttons. One of

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.