rguarascia.ts
rguarascia.ts

Reputation: 813

Getting a variable from another class file

I have two class files, one for my main form and calling things and another for my image processing code. My problem is that I create a Bitmap in the method in Class2 and I need it for Class1 to set the PictureBox.

public void Render(string bmpPath, decimal _Alpha, decimal _Red, decimal _Green, decimal _Blue)
{
    Bitmap imageFile = new Bitmap(bmpPath);
}

I just need to send it the bitmap but I don't know how to do that correctly. I tried creating another Bitmap but I need the Width and Height.

Upvotes: 0

Views: 74

Answers (3)

vandango
vandango

Reputation: 567

Call the Method Render from class1 in your class 2 and change the method to return the new image:

public Bitmap Render(string bmpPath, decimal _Alpha, decimal _Red, decimal _Green, decimal _Blue)
{
     return new Bitmap(bmpPath);
}

Upvotes: 0

User 12345678
User 12345678

Reputation: 7804

Make the method a function. The characteristic of a function is that it returns an object for somebody else to use, in this case class1.

public Bitmap Render(string bmpPath, decimal _Alpha, decimal _Red, decimal _Green, decimal _Blue)
{
    Bitmap imageFile = new Bitmap(bmpPath);
    return imagefile;
}

And now from Class1 (the Form)

var class2 = new Class2();
pictureBox1.Image = class2.Render(...);

Upvotes: 2

Adil
Adil

Reputation: 148120

You can return Bitmap instead of void from the method.

public Bitmap Render(string bmpPath, decimal _Alpha, decimal _Red, decimal _Green, decimal _Blue)
{
    Bitmap imageFile = new Bitmap(bmpPath);
    return imageFile;
}

In calling class (Class1)

Class2 class2 = new Class2();
pictureBox1.Image = class2.Render(/*your parameter passed here*/);

Upvotes: 1

Related Questions