how to load a image to the fields in a table

Hi All,

My requirement is i need to create a base table for loading the image1 → field1, image2 → field 2, and so on…

I have created abase atble and added fields with Type → Container and EDt → Bitmap.

Now i would like to know how to proceed for loading a image aganist a field.

So that when i create a form with same name as the BaseTable , and when i select on the field options that was created as was said earlier as image1 → field1, image2 → field2, the field image selected must be populated in my report. kindly help me to solve my issue.

If you want to load the image from a file, you can use BinaryIo (new(), read()) or BinData (loadFile(), getData()) class. If in doubt, follow the implementation of CompanyImage form.

Hi, lilly

For loading image you just follow the steps of CompnyImage form.By the help of this You can Easily understand. In CompanyImage form see the Show logo method steps. For storing purpose just take Container.

R@Vi…

Hi Martin and Ravi,

Thanks for your reply. Can you just help me with an example.

I have loaded the images by using resources and got it through report. But My requirement is using a new base table with each field associated to a image and the customer will also have an option of inserting new images too.

Can you plz explain me step by step.

Which part is unclear to you?

Based on the information you’ve already got, you should be able to import a picture and save it as binary data to a database field. Then add Bitmap control to your report and fill it by a display method returning your database field as Bitmap.

Again, take a look at company logo. It’s printed on SalesInvoice, among others.

Hi Lilly,

if you want Print the Image For Every Field …k

for Form level u Can go through first design->grid->in that grid you can Take windows(right click on grid u can get it) ,in the windows property

you can find imagename,imagefit… in imageName you can give path of image and imagefit yuo can set “Size to Fit” and you can adjust width,height as you like…

for Reports same as design level(what ever pageheader,body etc) you can right click on section(what u want) then find bitmap in that properties you can set

imagename(same as above-‘path’),and chage yes to ResizeBitmap… and Adjust width.height ,then check both form and repoprt…

HI Lilly,

first you can take field in table As Container->then give “EDT” as Bitmap after

come to form Methods we Can write as below codes in methods…

in Class Declaration:

public class FormRun extends ObjectRun
{
Container image;
str imageFilePathName;
}

and then write a another Name as Upload Image Method in Methods

like:

void UploadImage()
{

FilenameFilter filter;
Bindata binData;
int _hwnd;

//haredCaptial SharedCaptial;

str extention, path, nameOfFile;

;
filter = [‘Image Files’,’.bmp;.jpg;.gif;.jpeg’];
binData = new BinData();

imageFilePathName = WinAPI::getOpenFileName(_hwnd,filter,’’, “@SYS53008”, ‘’,’’);

if (imageFilePathname && WinAPI::fileExists(imageFilePathName))
{
[path, nameOfFile, extention] = fileNameSplit(imageFilePathName);
if (extention == ‘.bmp’ ||
extention == ‘.jpg’ ||
extention == ‘.gif’ ||
extention == ‘.jpeg’)
{
binData.loadFile(imageFilePathName);

image = binData.getData();
element.ShowLogo();
ExmpleTable.FieldName = image;
}
else
{
throw error("@SYS89176");
}
}

}

then in the Design of Form ,you can take a button in that button method ucan write like this:

void clicked()
{
;
element.UploadImage();
}

try this it will work i hope…

Thank Ramesh…It is working…gud…

Hi Ramesh,

Thanks for your reply… Will surely work on it and revert you back soon…

Hi Ramesh,

Thanks for your reply… I got an error in showlogo() method stating “variable is not of type class”

for //image.image(logoImage); and for its width, height…y?

Hi Lilly,

instead of that code You can use like this…

/////////////////////////////////////////////////////////////////////////////////

void ShowLogo()
{
Image logoImage;
;
try
{
element.lock();
if (fi)
{
logoImage = new Image();
logoImage.setData(fi);

logoImage.resize(1000 ,300,0 );

}

element.resetSize();
element.unLock();
}
catch (Exception::Warning)
{
throw error(strfmt("@SYS19312", imageFilePathName));
}
}

check it…

Hi Ramesh,

Thanks for the reply… will check and let you know :slight_smile:

Hi martin,

I followed your piece of code, at bindata.loadfile() line of code I get a error message ‘Unable to load the file c:\sample.jpg’.

I don’t know where it is going wrong, need your help to guide me. My goal is basically to copy a image from local disk into the table field for display in a report. I have given full access to the image file on disk.

my code is

protected void UploadImage(str fileName)
{

FilenameFilter filter;
Bindata binData;
int _hwnd;
Container image;
str imageFilePathName;
Set permissionSet;
InteropPermission _perm;

//haredCaptial SharedCaptial;
#define.FileName(fileName)

str extention, path, nameOfFile;

;
filter = [‘Image Files’,’.bmp;.jpg;.gif;.jpeg’];
binData = new BinData();
imageFilePathName = strfmt(@"%1%2",WinApi::getFolderPath(8),#FileName);
imageFilePathName = @‘C:’+#FileName;

// imageFilePathName = WinAPI::getOpenFileName(_hwnd,filter,#FileName, “@SYS53008”, ‘’,’’);

if (imageFilePathname && WinAPI::fileExists(imageFilePathName))
{
[path, nameOfFile, extention] = fileNameSplit(imageFilePathName);
if (extention == ‘.bmp’ ||
extention == ‘.jpg’ ||
extention == ‘.gif’ ||
extention == ‘.jpeg’)
{
_perm = new InteropPermission(InteropKind::ClrInterop);
permissionSet = new Set(Types::Class);
//permissionSet.add(_perm);
permissionSet.add(new FileIoPermission(imageFilePathName,‘r’));
CodeAccessPermission::assertMultiple(permissionSet);
//interopPermission = new InteropPermission(InteropKind::ClrInterop);
//perm = new FileIOPermission(FilePath,‘r’);
//multipleSet =new Set(Types::Class);
binData= new BinData();
binData.loadFile(imageFilePathName);
image = binData.getData();
binData.setData(image);
//element.ShowLogo();
purchPurchaseOrderHeader.WFPOStatusWaterMark = image;
CodeAccessPermission::revertAssert();
}
else
{
throw error("@SYS89176");
}
}

}

Your code uses a local path (c:…) and it’s possible that it’s executed on a different computer than where the file exists and where you set permissions (if AX client and AOS are not on the same machine). Or the code runs on AOS and the AOS service account doesn’t have sufficient permissions.

You can also try to open the file though .NET Interop - you may get an exception with more information:

System.Exception ex;
try
{
    System.IO.File::Open(filePath, System.IO.FileMode::Open};
}
catch (Exception::CLRError)
{
    ex = CLRInterop::getLastException();
    throw error(ex.ToString());
}

Hi martin,

Thanks for your prompt reply. Unfortunately your piece of code does not display any descriptive error message.

Can you help me to accomplish this other way around. I have added a image windows form control and attaching image to it.

I don’t know how to access the form control image in a class. Simply i want to copy the image from from control and put it in a image container in class method.

Any help would be appreciated.

Regards,

sid

Pass a reference to the FormWindowControl to the class and then call image() method on the control.