Dynamics AX CompanyImage to Image File - axapta

I need to export the images stored in CompanyImage table to a image files.
How can I do it?
Reading the table I obtain a Bitmap field but how to know the type of image to build the correct extension and save it to file?

Finally I found the solution.
To export the image from CompanyImage:
// Grant clrinterop permission.
new InteropPermission(InteropKind::ClrInterop).assert();
image = new Image();
image.setData(companyImage.Image);
result = image.saveImage(#"c:\test.jpg",3);
CodeAccessPermission::revertAssert();
To know the original type:
image.saveType();

The above code wouldn't work right away. Here's the code that would run:
bindata bin = new bindata();
str content;
container image;
CompanyImage companyImage;
;
select companyImage;
image = companyImage.Image;
bin.setData(image);
content=bin.base64Encode();
AifUtil::saveBase64ToFile("c:\\temp\\test.tif", content);

Related

Xamarin - CachedImage - Access the downloaded file

I am using the CachedImage component of ffimageloading. I have a kind of gallery with a carousel view.
All the images are loaded through an internet URL, they are not local images. I would like to add the image sharing function. But I don't want to download the file again, I would like to know if there is a way to access the file that the CachedImage component already downloaded to be able to reuse it in the share function.
try using MD5Helper
var path = ImageService.Instance.Config.MD5Helper.MD5("https://yourfileUrlOrKey")'
Thanks Jason
I share with you how part of my code is:
var key = ImageService.Instance.Config.MD5Helper.MD5("https://yourfileUrlOrKey");
var imagePath = await ImageService.Instance.Config.DiskCache.GetFilePathAsync(key);
var tempFile = Path.Combine(Path.GetTempPath(), "test.jpg");
if (File.Exists(tempFile))
{
File.Delete(tempFile);
}
File.Copy(imagePath, tempFile);
await Share.RequestAsync(new ShareFileRequest
{
Title = "Test",
File = new ShareFile(tempFile)
});
The temporary file I believe, since the cached file has no extension and the applications do not recognize the type.

Adding text to a JPG image in ASP.net C# and save to file on server

I'm using the following code (credit to Dolph Larson) to take a pre-made image file in bitmap format on an ASP.net server, draw a string on it and save it to file on the server. In the original code, he dumps the bitmap to the OutputStream, but I'd like to dump it instead to a file.
The version of code below successfully creates the new file, but when I open it, the string does not appear drawn on the image in the new file. I imagine I am missing a step -- when I use bitMapImage.Save("bitmaptest.jpg", ImageFormat.Jpeg) am I just re-saving the original instead of the modified version?
Here is the code:
//Load the Image to be written on.
Bitmap bitMapImage = new
System.Drawing.Bitmap(Server.MapPath("generic.jpg"));
Graphics graphicImage = Graphics.FromImage(bitMapImage);
graphicImage.SmoothingMode = SmoothingMode.AntiAlias;
graphicImage.DrawString("testing 1 2 3",
new Font("Arial", 20, FontStyle.Bold),
SystemBrushes.WindowText, new Point(0, 0));
Response.ContentType = "image/jpeg";
bitMapImage.Save("bitmaptest.jpg", ImageFormat.Jpeg);
graphicImage.Dispose();
bitMapImage.Dispose();
Thanks in advance!
Your code works just fine; You simply need to specify the path where you want to save the image:
Example:
//Load the Image to be written on.
Bitmap bitMapImage = new
System.Drawing.Bitmap((#"c:\\foo\\generic.jpg"));
Graphics graphicImage = Graphics.FromImage(bitMapImage);
graphicImage.DrawString("testing 1 2 3",
new Font("Arial", 20, FontStyle.Bold),
SystemBrushes.WindowText, new Point(0, 0));
bitMapImage.Save("c:\\foo\\bitmaptest.jpg", ImageFormat.Jpeg);
graphicImage.Dispose();
bitMapImage.Dispose();
Note In your case, bitMapImage.Save needs to be as follows: bitMapImage.Save(Server.MapPath("~/Images")+"newImage.jpg",ImageFormat.Jpeg); since you are attempting to save the image on an asp.net app. ~/Images in my example is just the virtual directory Images inside your app.
Yes ..You are saving the same image .You have to create a ne wbitmap and save it:-
Bitmap bitMapNew = Bitmap.FromHbitmap(graphicImage.GetHdc());
bitMapNew.Save("bitmaptest.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
Add these lines instead of your bitMapImage.save

PDFizer: how to inset picture in generated pdf document?

i'm using PDFizer library for .NET from here - PDFizer
and i need help... how i can convert all html document(including pictures stored in it) to PDF with this library? Now i can only generate pdf without images...
After some testing, this is what you need to do:
Create a Folder in which you will have all of your Images.
If you already have an instance of Pdfizer.HtmlToPdfConverter change the ImagePath Attribute to point to the folder where your images reside.
Include the <img> tags in your html code.
Make sure the images are in the folder.
Note: I tried adding Png files and got a conversion error. Here is an example I took from the site you provided, plus my modifications:
System.Text.StringBuilder sbHtml = new System.Text.StringBuilder();
sbHtml.Append("<html>");
sbHtml.Append("<body>");
sbHtml.Append("<font size='14'>My Document Title Line</font>");
sbHtml.Append("<img src='trollface.jpg' />");
sbHtml.Append("<br />");
sbHtml.Append("This is my document text");
sbHtml.Append("</body>");
sbHtml.Append("</html>");
//create file stream to PDF file to write to
using (System.IO.Stream stream = new System.IO.FileStream
(sPathToWritePdfTo, System.IO.FileMode.OpenOrCreate))
{
// create new instance of Pdfizer
Pdfizer.HtmlToPdfConverter htmlToPdf = new Pdfizer.HtmlToPdfConverter();
// open stream to write Pdf to to
htmlToPdf.Open(stream);
htmlToPdf.ImagePath = Server.MapPath(ResolveUrl("~/Images"));
// write the HTML to the component
htmlToPdf.Run(sbHtml.ToString());
// close the write operation and complete the PDF file
htmlToPdf.Close();
}
}
Good luck!

Image to be loaded into pdf file created from Sharepoint Server Images Folder

I am using ItextSharp Library to generate pdf files on a button click on my SharePoint Site. I want to use a logo on the pdf whose image resides on the Images Folder of Sharepoint. I am unable to do that.
Can someone help me with it.
Below is the code that I am using which is getting the instance from window32 which I dont want.
protected void button1_OnClick(object sender, EventArgs e)
{
Font Arial = FontFactory.GetFont("Arial", 12, BaseColor.GREEN);
Font Verdana = FontFactory.GetFont("Verdana", 16, Font.BOLDITALIC, new BaseColor(125, 88, 15));
string imagepath = SPContext.Current.Web + "/_layouts/Images/Image1.png";
using (var ms = new MemoryStream())
{
using (var document = new Document(PageSize.A4,50,50,15,15))
{
PdfWriter.GetInstance(document, ms);
document.Open();
Paragraph img = new Paragraph();
Image jpg = Image.GetInstance(imagepath); --- Getting an error here stating "Could not find a part of the path 'c:\windows\system32\inetsrv\CustomSystem\_layouts\Images\Image1.png'"
img.Add(jpg );
}
}
}
Please help!
I'm not too familiar with SharePoint development but you're problem is with this line:
string imagepath = SPContext.Current.Web + "/_layouts/Images/Image1.png";
This string must be an absolute path path such as c:\www\sites\image.png, not a relative one which it is right now. I can tell its relative because when you ask ASP.Net to get something for you but you don't specify a path it looks in %WINDOWS%.
I don't know how you're using SPContext.Current.Web but according to the docs calling .ToString() on it returns the title of the website which is what would happen if you concatenated it with a string like you are. My guess is that you don't need that but could be wrong.
If the layouts folder is a subfolder of the folder that the file you are working on is in then you should be able to use Server.MapPath to get the absolute path:
string imagepath = Server.MapPath("_layouts/Images/Image1.png");
i have done like this in my sharepoint site
string url = "http://fspl-dsktp-038:8000/Style%20Library/FSPL/CorporateLogo.png";
//iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(Server.MapPath("images") + "//images/FSPL LOGO.png");
iTextSharp.text.Image logo =iTextSharp.text.Image.GetInstance(url);
logo.ScaleAbsolute(90, 90);
Imagecell.AddElement(logo);
gvTable.AddCell(Imagecell);

Using fileupload in listview edittemplate asp.net

In a ListView edittemplate, I need to allow the user to replace an image. When the form is submitted for updating how can I determine if the user is uploading a new image and get that file info?
Thanks,
James
You could try something like this if you want to compare file size. Granted file size comparison is not the best but FileInfo has lots of other attributes you should be able to use to make sure.
FileInfo oldFileInfo; // get old file's fileInfo
var tempPath = "some-temp-path-";
var tempFile = String.Format("{0}\{1}", tempPath, FileUpload1.FileName);
FileUpload1.SaveAs(tempFile);
FileInfo tempFileInfo = new FileInfo(tempFile);
if(tempFileInfo.Length == oldFileInfo.Length)
{
// ask to upload a different image
}
else
{
// do other stuff
}
Grab the name off of the FileUpload.PostedFile.

Resources