Dynamic image assigned to live tile does not show? - c#

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.

Related

InsertInlineImage or ReplaceImage URI

I'm writing a WinForms application. I created a Google Doc template file that contains placeholders like {{name}} for various text elements. I can successfully make a copy of this document and use the BatchUpdateDocumentRequest to modify them just fine.
However, I also have an embedded image in the document. I can obtain the objectId for this image just fine. I either want to replace this image with another or remove it from my template and then append my new image to the end of the document. In both cases, the InsertInlineImage or ReplaceImage classes require a URI of the image to insert or replace with. This is where I have an issue.
The image itself has been captured from a control on the WinForms. Its actually a chart. I've saved the image in PNG format since I know that is one of the formats supported by Google drive/docs. I figured in order to use it in the batch update, I would need to upload it first, so I did and got its file id and webcontentlink back in the response.
I'm not locked into any particular way of doing this. I originally tried creating an HTML file, uploading but then it would strip the image from it, so became useless, so I switched gears to using a Google Doc as my template and just try to replace elements in it instead. This went well until I got to the image.
Essentially no matter what I try to specify as the URI, it says the file in not in a supported format.
As far as I can tell, Google expects the URI to actually end in .png or be a real link versus a download URL you'd get from Google Drive.
Here is an example of the code I'm using to attempt to replace the image. The strImageObjectId is the objectId of the Embedded Object image in the template document copy that I want to replace. The Uri is what Google needs to pull the new image from. I'm happy to pull it from my local computer or Google Drive if only I could get it to accept it somehow.
BatchUpdateDocumentRequest batchUpdateRequest = new BatchUpdateDocumentRequest {
Requests = new List<Google.Apis.Docs.v1.Data.Request>()
};
request = new Google.Apis.Docs.v1.Data.Request {
ReplaceImage = new ReplaceImageRequest() {
ImageObjectId = strImageObjectId,
Uri = strChartWebContentLink
}
};
batchUpdateRequest.Requests.Add(request);
DocumentsResource.BatchUpdateRequest updateRequest =
sDocsService.Documents.BatchUpdate(batchUpdateRequest, strCopyFileId);
BatchUpdateDocumentResponse updateResponse = updateRequest.Execute();
I'm happy to use whatever method will get me to a point where I an end up with a Google Doc on Google Drive that was based on a template in which I can replace various text elements, but most importantly add/replace an image.
Thanks so much for the advice.
I got to the point were I believe I was specifying the URI correctly, but then I started getting an access forbidden error instead.
I didn't have time to hunt this one down, so I went back to creating an HTML template with my image, uploading as a Google Doc, exporting to PDF, and then uploading as a PDF. This ended up working because originally I was using a BMP as the file format and that is not supported by Google Docs, so I changed to a PNG instead and it worked just fine.
I think Google Docs needs to add the ability to add an image using a MemoryStream or some other programmatic base64 resource instead of purely being based on URIs and running into temporary upload or permission issues.
Hey I'm doing the same thing with you,
and I got this, by modify the download link format.
from this:
https://docs.google.com/uc?export=download&id={{YOUR GDRIVE IMAGE
ID}
to this
https://docs.google.com/uc?export=view&id={{YOUR GDRIVE IMAGE ID}
e.g :
uri: "https://docs.google.com/uc?export=view&id=1cjgyHqtYSgS0CBT4x-9eQIHRzOIfGgv-"
but the image should be set for public privilege

canon SDk Article by Johannes Bildstein

In Canon SDK sample, how can I take a photo with certain resolution such as 200-300 dpi or change the resolution programmatically, and save the taken photo in another file type, here I need to save in .TIF format? I can't find any function to do it.
author of the article here.
you can change the image resolution by setting the PropID_ImageQuality with one of the ImageQuality enums. Note that not every camera supports every enum value and the actual image resolution depends on the camera and sensor. If you need a pixel-exact image you'll have to resize it yourself.
Also, the image you download from the camera is not modified by the SDK so you can only get the image format that the camera has, usually CR2 and/or Jpg.
To get a tif from a raw file you can use the SDKs image methods. To create a raw image use the EdsCreateImageRef method and to save it use the EdsSaveImage method. As a target you can use EdsTargetImageType.TIFF (or TIFF16 for 16bit per channel).
EDIT:
quick sample for saving an image to tiff (not tested):
IntPtr imgRef;
//Open image
IntPtr inStream;
EDSDK.EdsCreateFileStream("inFile.cr2", EdsFileCreateDisposition.OpenExisting, FileAccess.Read, out inStream);
EDSDK.EdsCreateImageRef(inStream, out imgRef);
EDSDK.EdsRelease(inStream);
//do whatever you like with imgRef now
//Save image
IntPtr outStream;
var settings = new EdsSaveImageSetting();
EDSDK.EdsCreateFileStream("outFile.tif", EdsFileCreateDisposition.CreateAlways, EdsFileAccess.Write, out outStream);
EDSDK.EdsSaveImage(imgRef, EdsTargetImageType.TIFF, settings, outStream);
EDSDK.EdsRelease(outStream);
To get a TIFF image, shoot in RAW format and after downloading the image use the EdsSaveImage function with the EdsTargetImageType set to kEdsTargetImageType_TIFF. The DPI resolution is not relevant directly, but you can always use tools like Exiftool to set the DPI explicitly.

How to save/retrieve images from disk in windows form application?

What I am trying to do is, I want to save an image ("scanned image of receipt") upon each ticket generation and store its reference(image name) in mssql database.
Scenario:
The user will select the image from a source through OpenDialogBox & will click save button. Now what I want my application to do is, copy the file from source, change its file name to TicketID (TicketID will be unique everytime so the image name will always remain unique) and then save to a specific folder (which will store all images) and store the filename in database.
I have never used images in C# before, so I have no idea on how to actually do it. So I would really appreciate if someone could link me to a tutorial or something...
P.S. I am using visual studio 2012 and MQ SQL Server 2012.
you can do the following
1- on the save event assuming that your scanned Image called image
var ticketID=Guid.NewGuid().ToString(); // this method will ensure that the name of image will be unique all the time
var path="savingPath" + "/" + ticketID + ".jpg";
// the image path you can save it in the database
image.Save(path);
2- when you want to load the image
// retrieve the image path from database
var image=Image.FromFile(path);
hope that this will help you
If you don't need anything overly fancy in terms of processing the System.Drawing library should meet your needs.
Depending on how you want to architect your app you can pass a directory path directly into the constructor of your Image implementation. e.g.
var myImage = new Bitmap("C:\\somepath\\filename.jpg");
Or you could abstract away the location access you can just pass in a stream (which comes from a byte array, file operation, web request, whatever)
var myImage = new Bitmap(stream);
Saving an image is easy. The image class has a save method
image.Save("C:\\somepath\\filename2.jpg")
http://msdn.microsoft.com/en-us/library/9t4syfhh(v=vs.110).aspx

Simple photo taking, storing, loading on Windows Phone

In my application I have a data entry view which I'd also like to give the user the option to store a photograph. Currently, using the tutorial at http://msdn.microsoft.com/en-US/library/windowsphone/develop/hh394006(v=vs.105).aspx, I've got a button which lets me take the photo, and can display it back properly at the bottom of the view.
However, I'd like this photo to be saved as part of the record. I thought it would be simple to save the location of the file as a string(I can access this by using PhotoResultObject.OriginalFileName), then display the photo again by using a URI like in my code here. This is inside the cameraCaptureTask_Completed method, e is a PhotoResult object.
string imageLoc = e.OriginalFileName;
Uri imageUri = new Uri(imageLoc, UriKind.RelativeOrAbsolute);
StreamResourceInfo resourceInfo = Application.GetResourceStream(imageUri);
BitmapImage bmp = new BitmapImage();
bmp.SetSource(resourceInfo.Stream);
myImage.Source = bmp;
However, this gives me an Argument exception, or various other exceptions when I move things around. I'm pretty new to c# so I'm really certain what's going on.
I reckon it's something to do with trying to access the photo straight from the phone memory, but I haven't found any other clear ways to store photos which will stay accessible inside the app.
Any tips on where I'm going wrong or how to accomplish my aim would be appreciated greatly!

WP8 Some remote images not showing in secondary tile

I'm trying to set a remote image for a flipTileData:
var tileData = new FlipTileData();
tileData.BackgroundImage = new Uri("http://slurm.trakt.us/images/fanart/735.8-940.jpg", UriKind.RelativeOrAbsolute);
tileData.Count = count;
tileData.BackTitle = title;
tileData.Title = title;
tileData.WideBackgroundImage = new Uri("http://slurm.trakt.us/images/fanart/735.8-940.jpg", UriKind.RelativeOrAbsolute);
ShellTile.Create(new Uri(string.Format("/ShowPage.xaml?id={0}", id), UriKind.Relative), tileData, true);
However, like the example above the image doesn't show but other images work perfectly just like the one below:
"http://slurm.trakt.us/images/fanart/97.14-940.jpg"
Is there any limitation or constraint that I have to be aware of for WP8 tile images? I really can't understand why some work and others don't.
Based on MS Doc, there are some restrictions about the size of the image as well as the time to be downloaded then you're using external Uris (resources)
If references a remote resource, the maximum
allowed size of the Tile image is 80 KB, with a maximum download time
of 15 seconds.
from http://msdn.microsoft.com/en-us/library/ff402545(VS.92).aspx.
So, I know that the problem you're facing it with the WideBackgroundImage , and the working has a size of 130KB, and the non-working image has a size of 161KB. So, I think you should be using images with that size of 130KB or lower for the WideBackgroundImage property, and that may work in your case. I haven't found a documented constraint on this property, but it makes sense if Microsoft is also applying this restriction.
Herber

Categories

Resources