Titanium mobile Get saved image path - titanium-mobile

i have been using this code to store an image from imageviewer to device memory.
blobObj = imageView.toImage();
var f = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory,'img.png');
f.write(blobObj);
Titanium.Media.saveToPhotoGallery(f,{
success: function(e) {
Titanium.UI.createAlertDialog({
title:'Photo Gallery',
message:'Check your photo gallery for image '
}).show();
},
error: function(e) {
Titanium.UI.createAlertDialog({
title:'Error saving',
message:e.error
}).show();
}
});
What i want is to get the native path of currently saved image from memory
Thankyou

Dear Please see the below example to get native path where the image is stored in titanium
file system
// Native path
var filename = "image.png";
// Create the file in the application directory
bgImage = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, filename);
// Write the image to the new file (image created from camera)
bgImage.write(image);
// bgImage.nativePath, it is alos native path, but you can get through below code.
nativePath = Titanium.Filesystem.applicationDataDirectory + Ti.Filesystem.separator + filename;
alert(nativePath);
Hopefully, it will for you. It is working on my side.

As this only works on iOS (see docs) i guess you are on iOS Platform.
If you create an image via blobObj = imageView.toImage(); you will receive a Titanium.Blob object. This object can be persisted somewhere in your app, it can also be temporarily available in memory.
If you store this image to the media gallery you won't get a file path to this image as this is not allowed by the iOS platform. So finally: What you want to do is not possible.
But: You can store the image yourself persistently within your app's data storage (using Ti.Filesystem).
To retrieve a file path for the temp object use f.nativePath or f.resolve().
Don't forget: You'll never get a path to the media gallery's photos. Even if you load an image from there you'll get a temporary path.

Related

Xamarin - how to reset image cache for a specific image

In my Xamarin app I upload a new "user profile" image on the server, then I try to update the image with the new version of the image (Noticed that the image uri is the still the same).
There is an image cache provided by Xamarin, I need to invalidate it to force the image to reload from the server. But it seems that the Image cache cannot be invalidated ! I find no solution !
I have try several solutions, but find no way ! Even when I restart the application I get the old version of the image.
I have try some stuffs like this :
(MediaImageSource as UriImageSource).CacheValidity = new TimeSpan(-1);
FFImageLoading.Forms.CachedImage.InvalidateCache(MediaImageSource, FFImageLoading.Cache.CacheType.All, true);
FFImageLoading.ImageService.Instance.InvalidateCacheAsync(FFImageLoading.Cache.CacheType.All);
But nothing work, any idea is welcome ? Thx
I do the following:
// this.Img is the FFImageLoading.CachedImage in my view
var source = this.Img.Source as FileImageSource;
// Reset cache using the global instance (the key is the file name, I assume it is the uri for UriImageSource)
await ImageService.Instance.InvalidateCacheEntryAsync( source.File, CacheType.All, true );
// Reassign the image source (since the binding has not changed per se, the UI may miss the change otherwise)
this.Img.Source = new FileImageSource(...);
This reloads the image and FFImageLoading even does a nice fade animation when it changes.
There is actually a static method in CachedImage that accepts any kid of ImageSource, so there is no need to guess the key:
FFImageLoading.Forms.CachedImage.InvalidateCache(myImageSource, CacheType.All, true);

Persistence of Image name using IOS8 Photos and iCloud Photo Sharing

I am working on an app using Core Data which includes a Product file containing item description and image filename. In a previous version on a different platform this filename would contain something like “elephant.jpg” and its associated image would also be called “elephant.jpg”. In this way the data could be entered and validated off-line and then imported into the app.
Using IOS8 and the Photos framework I cannot do this as there appears to be no way of persistently attaching a name to a photo image. I have tried looking at the image metadata using :
PHImageManager.defaultManager().requestImageDataForAsset(asset, options: nil) {
imageData,dataUTI,orientation,info in
println("Info %#", info) }
However this returns info such as
/private/var/mobile/Media/PhotoData/PhotoCloudSharingData/8083971319/2cc2fcd0-d19b-4803-b34f-35a285bc1fab/100CLOUD/**IMG_0008.JPG**
where IMG_0008.JPG is not related to the original image.
I am currently getting partially around this by ensuring each image has a unique dateTime for its creationDate, storing this in the Product.fileName and using this to retrieve my image with
var fetchOptions = PHFetchOptions()
fetchOptions.predicate = NSPredicate(format: "creationDate == %#", imageCreationDate) // use CreationDate in predicate
var assets = PHAsset.fetchAssetsInAssetCollection(rec, options: fetchOptions)
However this is difficult to manage, and not easy to create datafiles which can be exported as the image has to be matched to the file after it has been imported to the iPad.
My problem would be solved if I could only attach a name to the image on iPhoto on my Mac which persisted after I shared the images with iCloud Photo Sharing.
I will be very grateful for any suggestions !

Images save to saved pics and retrieving back and displaying in my app in windows phone

Hello Friends I am New to WP7
i am working on small app now..
In that App i take one Pic from my camera and trying to save that in saved pictures with some name and i like to retrieve that Images and display again in my App Gallery screen
I am Using Pivot control for this app
in my first PivotItem Name is Gallery and second PivotItem name is Camera
Now i am working with camera fine
After taking my picture from camera i like to add some Note for that and save to my saved images and retrieving same image back and display in Gallery with Note wt i save
can any one say
how can i complete this App in good way
Code for save Images im using
mainpage.xaml.cs
private void saveimg_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
string fileName = myValue.ToShortDateString() + ".jpg";
var library = new MediaLibrary();
//library.SavePictureToCameraRoll(fileName, e.ChosenPhoto);
library.SavePicture(fileName, imageBits);
MessageBox.Show("Photo Saved to Picture Hub");
}
I need to Retrieve that that saved Image and display in my App when it loaded
If you need to access your image once it has been saved in the Media Library, you should also save it to the Isolated Storage.
Here is a tutorial that shows how to do that:
http://www.windowsphonegeek.com/tips/All-about-WP7-Isolated-Storage---Read-and-Save-Images
Save the image to Isolated Storage and Pictures Gallery. When wanting to see the image through the app, use image from Isolated Storage.
No need to use SQLite, use index numbers to save your image in Isolated storage, and also store comments with index numbers, that might ease you.

Setting BackBackgroundImage with local file for live tile WP7

this might be really simple and I've tried searching but I haven't been able to find a solution.
My problem is quite basic. I am having trouble setting the BackBackgroundImage uri path to a local static png that I've made.
Here is the code I am using to generate the tile:
ShellTile testtile = ShellTile.ActiveTiles.First();
if (testtile != null)
{
StandardTileData newtiledata = new StandardTileData
{
Title = "Test Title",
Count = 0,
BackContent = "Test Content",
BackBackgroundImage = new Uri("Content/BackTileIcon.png", UriKind.Relative)
};
testtile.Update(newtiledata);
}
The problem is that I can't get BackTileIcon.png to display. I get the "Test Content" displaying fine and the tile flips back to the front image OK, it's just the back image that I can't display.
If I open the XAP after building I can see that there is a Content folder and inside the content folder is the BackTileIcon.png file.
I can't work out the format I need for the Uri for a local image in a subfolder. I changed the Uri to point to my games large icon which is included in the root folder (so the Uri path is just "LargeAppIcon.png") and that works so I know the code updates the back image OK with a correct path.
Am I just doing something stupidly wrong here?
Thanks for any help :)
In order to use a local image in your live tile, the image has to be in the IsolatedStorage under the folder /Shared/ShellContentand and not in your project.
You either have to generate the image in the application and save it directly in the isolatedStorage, or copy your content image in there at runtime.

Image capture using CameraCapture

I am using a sample code from Microsoft windows SDK (CameraCapture, which is found in C:\Program Files\Windows Mobile 6 SDK\Samples\PocketPC\CPP\win32\CameraCapture) to capture image using windows mobile. The program save a image into a file, but I am interested to store the image into memory rather than any saving into storage.
any suggestions?
I don't have access to that particular sample but I assume that the project is using the CaptureCameraDialog class.
http://msdn.microsoft.com/en-us/library/microsoft.windowsmobile.forms.cameracapturedialog_members.aspx
Unfortunately using this class will only return the image path. You don't state why you need to save it in memory rather than on the disk but if your intention is to do some basic processing then you could just load it from the disk once captured.
using (CameraCaptureDialog cameraCapture = new CameraCaptureDialog())
{
cameraCapture.ShowDialog();
//get the name of the last image taken
string fileName = cameraCapture.FileName;
//Load the image from disk into our image object
Image image = new Bitmap(fileName);
}
A word of caution here. I believe when saved to disk the images will be in a compressed format, but when loaded into memory they will be uncompressed. It is very easy to cause an out of memory exception when working with images in the compact framework so I wouldn't recommend holding lots of images in memory at once especially if working with a hi resolution camera.

Resources