zimmer9
asked on
How to resolve the error: An object reference is required for the non-static field, method or property in a C# console application?
I am writing a C# console application to merge 2 TIFF records into 1 merged file (multipage TIff image).
1 record is comprised of the front images of checks.
1 recorrd is comprised of the back images of checks.
I want to give the user the ability to read the front image of a particular check image and then read the back image of the same check.
The img variable contains the front images of checks.
The img1 variable contains the back images of checks.
I am getting the error:
An object reference is required for the non-static field, method or property 'ReadBinary.BinaryFileTest .ConvertFr omByteArra y(byte[])'
---------
Byte[] img = bytes.Skip(irecpositionrev ised + irectypelength).Take(intpo s1revised) .ToArray() ;
Byte[] img1 = bytes.Skip(irecpositionrev ised + irectypelength + intpos1revised).Take(intpo s2revised) .ToArray() ;
MergeTwoImages(ConvertFrom ByteArray( img), ConvertFromByteArray(img1) ); <--- error occurs here
private Image ConvertFromByteArray(byte[ ] input)
{
using (var ms = new MemoryStream(input))
{
return Image.FromStream(ms);
}
}
public static Bitmap MergeTwoImages(Image firstImage, Image secondImage)
{
if (firstImage == null)
{
throw new ArgumentNullException("fir stImage");
}
if (secondImage == null)
{
throw new ArgumentNullException("sec ondImage") ;
}
int outputImageWidth = firstImage.Width > secondImage.Width ? firstImage.Width : secondImage.Width;
int outputImageHeight = firstImage.Height + secondImage.Height + 1;
Bitmap outputImage = new Bitmap(outputImageWidth, outputImageHeight, System.Drawing.Imaging.Pix elFormat.F ormat32bpp Argb);
using (Graphics graphics = Graphics.FromImage(outputI mage))
{
graphics.DrawImage(firstIm age, new Rectangle(new Point(), firstImage.Size),
new Rectangle(new Point(), firstImage.Size), GraphicsUnit.Pixel);
graphics.DrawImage(secondI mage, new Rectangle(new Point(0, firstImage.Height + 1), secondImage.Size),
new Rectangle(new Point(), secondImage.Size), GraphicsUnit.Pixel);
}
return outputImage;
}
1 record is comprised of the front images of checks.
1 recorrd is comprised of the back images of checks.
I want to give the user the ability to read the front image of a particular check image and then read the back image of the same check.
The img variable contains the front images of checks.
The img1 variable contains the back images of checks.
I am getting the error:
An object reference is required for the non-static field, method or property 'ReadBinary.BinaryFileTest
---------
Byte[] img = bytes.Skip(irecpositionrev
Byte[] img1 = bytes.Skip(irecpositionrev
MergeTwoImages(ConvertFrom
private Image ConvertFromByteArray(byte[
{
using (var ms = new MemoryStream(input))
{
return Image.FromStream(ms);
}
}
public static Bitmap MergeTwoImages(Image firstImage, Image secondImage)
{
if (firstImage == null)
{
throw new ArgumentNullException("fir
}
if (secondImage == null)
{
throw new ArgumentNullException("sec
}
int outputImageWidth = firstImage.Width > secondImage.Width ? firstImage.Width : secondImage.Width;
int outputImageHeight = firstImage.Height + secondImage.Height + 1;
Bitmap outputImage = new Bitmap(outputImageWidth, outputImageHeight, System.Drawing.Imaging.Pix
using (Graphics graphics = Graphics.FromImage(outputI
{
graphics.DrawImage(firstIm
new Rectangle(new Point(), firstImage.Size), GraphicsUnit.Pixel);
graphics.DrawImage(secondI
new Rectangle(new Point(), secondImage.Size), GraphicsUnit.Pixel);
}
return outputImage;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.