I am new to MonoTouch and I am trying to send an email with an image as attachment that a user will tame from camera or pick from gallery.
I have created the program and it runs correctly (I have an imageview controller which loads an image from uiimagepicker to imageview. Then I call MFMailComposeViewController but I don't know how to pass the image from imageview to addAttachmentdata method.
I suppose first I have to save the image from imageview as a file but I don't know how to do it and I can't find documentation for it.
First you need to turn the UIImage into an NSData, e.g. using AsPNG or AsJPG, then use the right MIME type for the image. Here's an example:
MFMailComposeViewController email = new MFMailComposeViewController ();
// any UIImage will do
UIImage img = UIImage.FromFile (".../anyimage.png");
email.AddAttachmentData (img.AsPNG (), "image/png", "image.png");
email.SetSubject ("Photo from my iPhone");
email.SetMessageBody ("Here's the attachment!", false);
controller.PresentModalViewController (email, false);
Note: the "image.png" is a suggested file name given to the recipient email software (i.e. it's not a local file in your device and does not need to match anything that exists).
Related
I have this little piece of code
var builder = new BodyBuilder();
var image = builder.LinkedResources.Add(logoPath);
image.ContentId = MimeUtils.GenerateMessageId();
textMsg = textMsg.Replace("{logo}", image.ContentId);
builder.HtmlBody = textMsg;
msg.Body = builder.ToMessageBody();
It works perfectly except that if I use a .png image it isn't attach to the mail but if it is an .svg it is attach. I tried to convert the svg to base64 but it didn't work.
As I show in the images below, if it is a .svg the image is attach at the top of the mail but if it is a.png it doesn't. Is it possible to do the same with .svg? I don't want the attached file.
The issue you are facing is a limitation of the receiving mail client, not anything you are doing wrong with the images in your email message.
The client you are using to receive the message does not support SVG and so has decided that whenever it encounters an SVG image, it will offer it to the user as an attachment.
I am writing an Outlook add-in to be able to insert automatically an image into an email using CID.
However, everytime I add an image as attachment (jpeg), the image is compressed automatically by Outlook and I have a big lost of quality.
Is it possible to avoid compression of images for attachment?
Here is the code that I am using so far:
var attachment = mailItem.Attachments.Add( #"D:\\image.jpg" , Outlook.OlAttachmentType.olEmbeddeditem , null , "Some image display name" );
string imageCid = "image.jpg#123";
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x370E001F", "image/jpeg"); // PR_ATTACH_MIME_TAG
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", imageCid); // PR_ATTACH_CONTENT_ID
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8514000B", true); // Hide attachment in the email
mailItem.HTMLBody = String.Format( "<body><img src=\"cid:{0}\" width='450' height='150' alt=''></body>" , imageCid);
Thanks a lot for any help
Not much you can do if the message is then displayed by Outlook. You can try to add the image immediately prior to it being sent (Aplication.ItemSend event).
I have a Windows Store app written in C# that works with photos. I want to show the last photo the user selected in the app in the medium size live tile (150 x 150). I am using the code below to do it. When I run the app I don't get any errors, but I don't see the selected photo in the live tile either. I know that I am doing at least some things right. I say this because if the user hasn't selected a photo yet, then I show a test image and I do see that image in the tile. But the test image comes from the app package using the ms-appx protocol, not from the app storage area.
I found a few SO posts on the subject but they are all for Windows Phone. I looked at the KnownFolders list for Windows Store app files, but nothing seemed to map to the SharedContent folder required for files meant for live tile use in Windows Phone. What is wrong with my code?
Note, the vvm.ActiveVideomark.GetThumbnail() call simply retrieves a bitmap as a WriteableBitmap object. As you can see in the code, I am resizing the image to the size required by the Medium live tile (150 x 150). ToJpegFileAsync() is an extension method that encodes a WriteableBitmap object to jpeg bytes and then writes those bytes to a file using the given file name. Both of these calls are well-tested and are not the source of the problem as far as I know.
TileUpdateManager.CreateTileUpdaterForApplication().Clear();
TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true);
var tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Image);
var tileImage = tileXml.GetElementsByTagName("image")[0] as XmlElement;
// Got a current photo?
if (vvm.ActiveVideomark == null)
// No, just show the regular logo image.
tileImage.SetAttribute("src", "ms-appx:///Assets/Logo.scale-100.png");
else
{
// Resize it to the correct size.
WriteableBitmap wbm = await vvm.ActiveVideomark.GetThumbnail();
WriteableBitmap wbm2 = wbm.Resize(150, 150, WriteableBitmapExtensions.Interpolation.Bilinear);
// Write it to a file so we can pass it to the Live Tile.
string jpegFilename = "LiveTile1.jpg";
StorageFile jpegFile = await wbm2.ToJpegFileAsync(jpegFilename);
// Yes, show the selected image.
tileImage.SetAttribute("src", jpegFile.Path);
}
The src attribute must contain a URI with ms-appx:///, ms-appdata:///local, or http[s]:// schemes. The StorageFile.Path property, as you're using with jpegFile.Path, is a local filesystem pathmame like c:\users\Robert\AppData... which won't be valid. So create your tile images in local app data, and then use ms-appdata:///local/ to refer to them in tile payloads.
I have a function that has a bitmap instance in windows form application. I want this bitmap instance to be converted into png and save the png into given folder in server.
Following is my piece of code:
public void uploadLayerIcon()
{
Bitmap icon = new Bitmap("C:\\Users\\HP\\Desktop\\mun.jpg");
icon.Save("http://192.168.1.30/muneem/erp/u.png",System.Drawing.Imaging.ImageFormat.Png);
}
I am getting error invalid uri format.
How to upload this bitmap to server from windows form application?
I just made a TestApplication to check, and the only thing is not working is just the URI of the destination. If you use something like this it should work:
icon.Save(#"\\192.168.1.30\muneem\erp\u.png", System.Drawing.Imaging.ImageFormat.Png);
Issue resolved.
I convert bitmap image to base64encoded string and send that string to php script. Now php script decode that string and write content to file which is placed in the given location provided by user.
I want to know how to create an image object having the "src info from an email". I already manage to get read the inbox, and to parse the html of it, and get out all of the "src = foo" from all the images in the email. My question is how do I then proceed to create an image using the information taken out from "src" in the of the html. I need this object in order to store it in a sharepoint picture library. Just want to know how to create the image object of the image stored in the html of the email.
Not sure about how to put it in SharePoint, but assuming you have a src in an extractedSrc variable:
WebClient webClient = new WebClient();
webClient.DownloadFile(extractedSrc, localFileName)
I guess there are two basic cases you have to consider, 1. The src attribute points to an external image (ie. image stored on a web site), 2. Src points to an image attached in the email.
For case 1. You need to download the image from the external server and then you can save it in your share point
For case 2. You have to decode the attachment sections of the email to extract the file data and then you can save it to your library