Reference an Image

I am trying to reference an image when a text box matches the name of it. I have images that indicate layout of a part.

My Code that references this:

	private void CallImageAdapterEqualsMethod()
	{
		try
		{
			
			// Declare and Initialize EpiDataView Variables
			var Image = "GS_" + tbOrderImageSize.Text;
			MessageBox.Show(Image);
			// Declare and create an instance of the Adapter.
			ImageAdapter adapterImage = new ImageAdapter(this.oTrans);
			adapterImage.BOConnect();

			// Declare and Initialize Variables
			// TODO: You may need to replace the default initialization with valid values as required for the BL method call.
		
			// Call Adapter method
			bool result = adapterImage.Equals(Image);
			pbSizeLayout.Image = adapterImage.Equals(Image);
			

			// Cleanup Adapter Reference
			adapterImage.Dispose();

		} catch (System.Exception ex)
		{
			ExceptionBox.Show(ex);
		}
	}
	
	//Order - Size Dimension
private void refreshBasicImage()
	{
		string fname1 = tbOrderImageSize.Text;
		if (fname1 == "") 
			{
			}
			else 
			{
			CallImageAdapterEqualsMethod();	
			}
	}

My Message Box Shows the correct name of GS_Vertical but nothing shows up in my image box :frowning:

Is there another way to link to the Image Maintenance Folder?

in the tools is an epipicturebox. That’s what the screen that you show is using. Can you just use that and bind it with the properties that the stock ones use? (I haven’t done it before, but that’s where I think I would start.)

edit : that looks like what you are doing.

I don’t see a Get anywhere, Let me look at the BL tester.

Interesing, when I try to open the image adapter dll I get this error.

image

Guess the BL test can’t play with images??

edit: I needed to open the contract.BO, not the adapter.

Here are some of the methods that go with that adapter.

so you should be able to check for whether it exists using ExistsImateID(string ImageID);

Then if it exists, get the image. I’m not sure what exactly I’m looking at so I don’t know for sure where to go from there.

I bet if you look at a trace when you are switching, you can get the method calls from there.

I use The EpiPictureBox object. to show images from our location on the server. In order to show the part picture if exists:

string file = BuildImagePath(); //from the image location path we deduct from the customerID /partnumber/revnumber  etc...
				if (File.Exists(file)) 
				{
					ImagePieceRev.Image = Image.FromFile(file); 
					
				}

The images were saved the same size pixels as the picturebox size …

Not sure if that helps you … but works well for us.

Pierre

1 Like

Here’s a way to pull in from the images Epicor stores in the database (which is what it looks like you’re trying to do) and bind them to an EpiPictureBox. Be sure to add the references at the top.

using Erp.Adapters;
using System.Drawing;
using System.IO;


private void DisplayImage (string imageID)
{
	//instantiate the adapter
	using (ImageAdapter ia = new ImageAdapter(this.oTrans))
	{
		//connect
		ia.BOConnect();
		try
		{
			if (ia.ExistsImageID(imageID) && ia.GetByID(imageID))	//make sure the ImageID is valid
			{
				//the image content is a Base64 encoded string
				//convert the string to an image and assign it to the picture box
				epiPictureBoxC1.Image = Base64ToImage((string)ia.ImageData.Image.Rows[0]["ImageContent"]);
			}
			else
				EpiMessageBox.Show("Invalid ImageID");
		}
		catch (Exception ex) { ExceptionBox.Show(ex); }
	}
}

private Image Base64ToImage(string base64String)
{
	// Convert base 64 string to byte[]
	byte[] imageBytes = Convert.FromBase64String(base64String);
	// Convert byte[] to Image
	using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
	{
		Image image = Image.FromStream(ms, true);
		return image;
	}
}
2 Likes

Okay, I’m getting closer…

	//Order - Size Dimension
private void refreshBasicImage()
	
	{
		MessageBox.Show("Starting Basic Image");
		string imageID = "GS_Vertical";
		using (ImageAdapter ia = new ImageAdapter(this.oTrans))
		{
			ia.BOConnect();
		try
		{
			if (ia.ExistsImageID(imageID) && ia.GetByID(imageID))
			{
				MessageBox.Show("Image ID");
				pbSizeLayout.Image = ia.ImageData.Image.Rows[0]["ImageContent"];
				
			}
			else
			MessageBox.Show("No Image ID");
		}
		catch (Exception ex) { ExceptionBox.Show(ex); }
	}
	}

I have this code and I am getting the first Message Box about “Starting BAsic Image”, then I get the second Message Box of “Image ID”. and then voila…nothing shows in the Picture Box. So, I’m wondering what I am doing wrong?

The ImageContent is a Base64 string. You need to convert it to an Image before you assign it to the picture box.

private Image Base64ToImage(string base64String)
{
	// Convert base 64 string to byte[]
	byte[] imageBytes = Convert.FromBase64String(base64String);
	// Convert byte[] to Image
	using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
	{
		Image image = Image.FromStream(ms, true);
		return image;
	}
}
2 Likes

Thank you everyone.
Here is my code that works:

	//Order - Size Dimension
private void refreshBasicImage()
	{
		string imageID = "GS_" + tbOrderImageSize.Text;
		using (ImageAdapter ia = new ImageAdapter(this.oTrans))
		{
			ia.BOConnect();
		try
		{
			if (ia.ExistsImageID(imageID) && ia.GetByID(imageID))
			{
				pbSizeLayout.Image = Convert.FromBase64String(ia.ImageData.Image.Rows[0]["ImageContent"].ToString());
			}
			else
				MessageBox.Show("No Image ID");
			}
		catch (Exception ex) { ExceptionBox.Show(ex); }
	}
		}

1 Like

I am trying to do something similar in a dashboard customization, I put the code behind a button to test it, but I get this error when I try to compile:

Error: CS0708 - line 61 (125) - ‘epiButton1_Click’: cannot declare instance members in a static class

I can’t remember if it is
using System.Drawing;

Shannon Kearney

Thanks Shannon, I got the reference sorted, I updated my original question with my current issue now. Basic c# I am sure just can’t work out, it’s this that causes the error ImageAdapter(this.oTrans)?

Do you remember the references you used?