I'm developing an application where the user can add photos from windows phone 7 photo library and assign them to a particular view. To do this I save the OriginalFileName on the database (LINQ to SQL). Later I want to recover the photo and load it into the view. Do you know what I can do? currently I have this code but does not work.
When the user has selected the picture I keep his name in the variable fileName:
private void photoChooserTask_Completed (object sender, PhotoResult e)
{
BitmapImage image = new BitmapImage ();
e.OriginalFileName = fileName;
image.SetSource (e.ChosenPhoto);
this.Thumbnail.Source = image;
this.Thumbnail.Stretch = Stretch.UniformToFill;
}
Later, when the user wants to save this setting I save the fileName in database.
This is the code when I load the view that must contain the photo.
imgSource var = new BitmapImage (new Uri (picture.Url, UriKind.Absolute));
item.LeftImage.Source = imgSource;
Where picture.Url contains the filename.
Any idea? I saw on the internet that you can keep the whole image, but give it the best possible.
What you should do is save the picture returned from the PhotoChooserTask in the IsolatedStorage.
You will then be able to load it when needed.
Here is how to Read and Save Images.
For what you need is to get the picture by browsing the MediaLibrary without using PhotoChooserTask, because as you experienced, the file name might not be the same if you use different methods.
For the custom MediaLibrary browsing interface, you could refer to this codeplex project:
https://multiphotochooser.codeplex.com/
Related
Why this does not load the image?
private void OnButtonClickedLoadImage(object sender, EventArgs e)
{
ImageSource imgSrc =
ImageSource.FromFile("C:\\MyApp\\MyPicture.png");
ImageViewerc.Source = imgSrc;
}
If you want to load local images, in Android, Place images in the Resources/drawable directory with Build Action: AndroidResource. In ios, The preferred way to manage and support images since iOS 9 is to use Asset Catalog Image Sets. Then use Asset Catalog Image Sets. The picture name can get the picture.
Thank you all (including Jason) for your help. Based on everyone's comment above, I corrected my code to properly load my image like this:
ImageSource imgSrc = ImageSource.FromResource("MyApp.pic2.png", typeof(ImageResourceExtension).GetTypeInfo().Assembly);
ImageViewerc.Source = imgSrc;
The image must be accessed like this: AppName.ImageFileName.ext (I was missing the AppName
Also I should note that the character case between the actual file name in Solution Explorer and the code-behind MUST MATCH or image won't load.
How can I post images on Instagram similar to SLComposeViewController using c# in a Xamarin.iOS application.
I dont think you can share extra text like in SLComposeViewController with Instagram or Facebook.
Have a look here
Might be best with a UIActivityViewController and add the image to activityItems like in this answer https://stackoverflow.com/a/32783758/1107580
There are two ways at the moment how can you share pictures from your app to Instagram:
Save the picture to your Camera gallery. Open Instagram app using URL #"instagram://camera". It opens Instagram app directly whit pictures sorted by the date of creation and yours one will be the first.
Open action sheet using UIDocumentInteractionController. After user selects Import in Instagram, the Instagram's share flow starting with the cropping will pop out.
Here is the code in Xamarin for the second option:
UIImage imageToUse = _your_ui_image_instance;
NSString documentDirectory = (new NSString(Environment.GetFolderPath(Environment.SpecialFolder.Personal)));
string saveImagePath = documentDirectory.AppendPathComponent(new NSString(#"Image.ig"));
NSData imageData = imageToUse.AsPNG();
imageData.Save(saveImagePath, true);
NSUrl imageURL = NSUrl.FromFilename(saveImagePath);
DocumentController = new UIDocumentInteractionController();
DocumentController.Url = imageURL;
DocumentController.Uti = "com.instagram.photo";
DocumentController.PresentOpenInMenu(new RectangleF(1, 1, 1, 1), View, true);
Remember to declare DocumentController as a class' field instead of a local property (error will be arisen once PresentOpenInMenu will be executed for losing the UIDocumentInteractionController too early).
You can alternatively show much fewer apps in the action sheet using uti com.instagram.exclusivegram and extension .igo.
I a working on a simple window phone application. In which I have two filed Name and Images.
I want to save this item and want to view all saved data.
Now My query How to select images to save? and How to save images and also get images to view.
I also used PhotoChooserTask but How to save selected image and how to get saved images?
I know about how to save image file in Isolated storage. But how to save selected images and get all data?
Thanks,
Hitesh.
Thanks for your reply. I knew about photoChooserTask. I also save my image file in isolated storage. But I dont know what is the images path to save images path in database and how to display all those images in datagrid. I have a table which have fields like ID, Name and Image path. I dont know what to save in imagepath filed if I saved image in isolated storage and how to display all data in datagrid.I used following code to save data into database. IN below code please correct the image path if I was wrong.
CategoryVO newCategory = new CategoryVO()
{
Name = txtCategoryName.Text,
ImagePath = txtCategoryName.Text.Trim() + ".jpg"
};
Expdb.Category.InsertOnSubmit(newCategory);
Expdb.SubmitChanges();
Using the PhotoChooserTask you can actually launch the photo chooser application and handle the selected image.
If you want to integrate this in your application, create the instance of the PhotoChooserTask and call the Show() method. If you want to handle the user’s selection, register the Completed event which will give you handle of the chosen photo.
var photoChooserTask = new PhotoChooserTask();
photoChooserTask.Completed += PhotoChooserTaskCompleted;
photoChooserTask.Show();
In the completed event implementation, you can get the chosen image as PhotoResult and set the image to your Image control or can use it in other places.
void PhotoChooserTaskCompleted(object sender, PhotoResult e)
{
switch (e.TaskResult)
{
case TaskResult.OK:
imageChooser.Source = new BitmapImage(new Uri(e.OriginalFileName));
break;
}
}
Source: http://www.codeproject.com/Articles/350126/How-to-use-the-PhotoChooserTask-to-Launch-the-Medi
Is it possible to use System.Drawing.Image in an RDLC Image Control?
All I have been reading were 3 methods:
database
embeded resource
external file
Thank you thank you.
EDIT:
Following up from this .NET or C# library for CGM (Computer Graphics Metafile) format? I now got the image in System.Drawing.Image format and want to display it as part of the report (as an image) --- that's what I want to do.
Not sure if this is what you are looking for, but if you have an image in code and you want to show it in the report, create a wrapper object that has a property that returns the image as a byte array and give then an instance of this wrapper-class with the valid image to the report as a ReportDataSource.
Something like:
ReportDataSource logoDataSource = new ReportDataSource();
logoDataSource.Name = "LogoDS";
logoDataSource.Value = new List<LogoWrapper>() { yourLogoWrapper };
localReport.DataSources.Add(logoDS);
In the report you then you can the image as it were from the database
=First(Fields!LogoByteArrayProperty.Value, "LogoDS")
The wrapper looks something like:
class LogoWrapper{
...
public byte[] LogoByteArrayProperty{
get{
// Return here the image data
}
}
}
I use this quite often. It has the advantage that I don't have to add the image to the db or add it as a resource of every report. And furthermore, the app can say which image should be used.
Please note, the given image format must be known from the rdlc-engine.
The last question would be, how to convert a system.drawing.image to a byte array. I work with WPF and therefore, I dont known. But I'm sure google will respond to this question very reliable.
You Can use the 'Database' Source Option along with Parameters to Dynamically set Image Source from Byte Arrays.
Code Behind:
var param2 = new ReportParameter()
{
Name = "CompanyLogo",
Values = { Convert.ToBase64String(*ByteArrayImageObject*) }
};
ReportViewer1.LocalReport.SetParameters(param2);
rdlc File:
1- Add Text Parameters 'CompanyLogo' and 'MIMEType'
2- Set the Value Property of the Image to =System.Convert.FromBase64String(Parameters!CompanyLogo.Value)
3- Set MIME Type Property to
=Parameters!MIMEType.Value
4- Use 'Database' As Source
How can I render a PNG image (as a memory stream) onto a .NET ReportViewer report surface
i am not quite sure what do you want to do with this but in general it is not possible.Image Control is just a image holder in the RDLC files.These 3 options specify the location from where the image control takes the image which to display from- database, embeded resource or external file. If you give me more info on what do you want to achieve i can give you some kind of solution.
Best Regards,
Iordan
Hi WP7 mobile passionate developers!
I'm trying to use the default provided Bing Map control from Windows Phone controls.
Specifically I'm trying to use a custom TileSource to provide a custom made tiled map that will be stored in the project as a folder (Content files) or in isolate storage.
Down I present the custom class I try to use with map tiles/images stored in "map" folder in ZXY storage format as content files.
public class CustomTileSource : Microsoft.Phone.Controls.Maps.TileSource
{
private string uriFormat = #"map/{0}/{1}/{2}.png";
public string UriFormat
{
get { return uriFormat; }
set { uriFormat = value; }
}
public override Uri GetUri(int x, int y, int zoomLevel)
{
var url = string.Format(UriFormat, zoomLevel, x, y);
return new Uri(url, UriKind.Relative);
}
}
Trying to use this is not working and custom tiles are not shown although no error is thrown.
Does anyone tried to use windows phone map control this way?
If that's not the right approach which one is? Any workaround?
Thank you in advance!
Claudiu
Have you set the Build Action on your image(s) to Content?
The Exception is:
This operation is not supported on a relative URI.
at System.Uri.get_AbsoluteUri()
at System.Windows.Media.MultiScaleTileSource.GetTileLayerUrl(IntPtr nativeTarget, Int32 tileLevel, Int32 tileX, Int32 tileY, Int32 uTileImageIndex, IntPtr& fullTileUri, UInt32& fullTileUriLength)
How to get an image from IsolatedStorage, Ressource or MediaLibrary with UriKind.Absolute i not already found out
...maybe you know?
This seems to be quite a FAQ problem - Map Tile Caching for Offline Viewing - shame there isn't an FAQ solution :/
Did you try constructing an absolute file url using the app id as described in this question? Map Tile Caching for Offline Viewing
I tried,
Did you try constructing an absolute file url using the app id as described in this question? Map Tile Caching for Offline Viewing
Map component is not showing me images, but simple
Image.Source = new BitmapImage(new Uri("file:///Applications/Install/0277CC52-888B-4593-A28D-4CFF818E81E7/Install/maps/-1040122162.jpg", UriKind.Absolute));
Is showing image...
You can find a solution in the blog http://invokeit.wordpress.com/2012/06/30/bing-mapcontrol-offline-tiles-solution-wpdev-wp7dev/
In general, you just need
Override GetUri function in TileSource class: return null to let MapLayerTile ignore this tile, and save the tile information to some background worker
In the background worker, loading the tile from anywhere, either isolation storage or network, and then manually add it to a MapLayer control.