In my Windows Phone 8.1 App i take a photo with the camera and save this in the camera roll and save the image path in a temporary object:
var picture = library.SavePictureToCameraRoll(fileName, e.ImageStream);
geophoto.ImagePath = picture.GetPath();
In another page of my app i want to load this photo from the camera roll and set the saved path as the source of an Image object:
Uri uri = new Uri(App.Current.Geophoto.ImagePath, UriKind.Absolute);
ImageSource imgSource = new BitmapImage(uri);
this.ShutterImage.Source = imgSource;
The saved path of the image is e.g. "file:///C:/Data/Users/Public/Pictures/Camera Roll/201506191442443805.jpg"
In runtime the image goes blank when i try to set a new source. Is there something wrong with the path or with the code?
I figured out that i have no direct access to camera roll through the path. So i solved my problem with the following code:
private BitmapImage GetThumbnailFromCameraRoll(string path)
{
MediaLibrary mediaLibrary = new MediaLibrary();
var pictures = mediaLibrary.Pictures;
foreach (var picture in pictures)
{
var camerarollPath = picture.GetPath();
if (camerarollPath == path)
{
BitmapImage image = new BitmapImage();
image.SetSource(picture.GetThumbnail());
return image;
}
}
return null;
}
Related
I'm trying to use ConvertToInlineShape().
But it is not successful,because it is a GroupShapes, its type is msoGroup.
How do I turn it into image and save as?
foreach (Microsoft.Office.Interop.Word.Shape s in WordDoc.Shapes)
{
if (s.Type.ToString() == "msoGroup")
{
//First try:
s.ConvertToInlineShape();
//Second try
s.Select();
WordApp.ActiveWindow.Selection.CopyAsPicture();
Image image = Clipboard.GetImage();
Bitmap bitmap = new Bitmap(image);
bitmap.Save("d:\\test" + i + ".jpg");
//image in null
}
}
My application for Windows Phone 8.1.
I need to find a way to check image aviability in assets resources in my application.
At first, I had following solution:
var package = Windows.ApplicationModel.Package.Current.InstalledLocation;
var folder = await package.GetFolderAsync("Assets\\Makes");
var files = await folder.GetFilesAsync();
var result = files.FirstOrDefault(p => p.Name == imageName);
if (result != null)
{
Uri imageUri = new Uri("ms-appx:///Assets/Makes/" + imageName);
Image img = new Image();
BitmapImage bi = new BitmapImage(imageUri);
img.Source = bi;
btn.Content = img;
}
else
{
TextBlock label = new TextBlock();
label.Text = text;
btn.Content = label;
}
It works. But, unfortunately, very very slow.
Anyway, next part of code working even in case if asset is not existing:
Uri imageUri = new Uri("ms-appx:///Assets/Makes/" + imageName);
BitmapImage bi = new BitmapImage(imageUri);
In case if file not existing, the image is empty, but not null.
Is there are any good way, to check, if image created empty from resource?
Or a really fast way to check existing of packaged resource file?
Thank you
I'm trying to set image for my tile in the background agent for my application:
ShellTile t = ShellTile.ActiveTiles.First();
if (t != null)
{
var filePath = Path.Combine("Tiles", "test1.jpg");
StandardTileData tile = new StandardTileData();
tile.Title = "Title text here";
tile.BackgroundImage = new Uri(#"isostore:\" + filePath, UriKind.Absolute);
t.Update(tile);
}
but then on t.Update(tile) it throws NotSupportedException :-( Isnt the path ("isostore:\") correct?
new Uri(#"isostore:" + filePath, UriKind.Absolute);
Without the backslash.
I have a script to take screenshot and save that image and to show that image in a plane.
But not getting that texture.
private string path;
void Start () {
path = Application.persistentDataPath;
}
void captureScreeshot(){
Application.CaptureScreenshot(path + "/Screenshot.png");
alert.text = "saved";
StartCoroutine(saveScreenshot());
onetimeBool = false;
}
IEnumerator saveScreenshot(){
WWW imgfile = new WWW("file://" + path+ "/Screenshot.png");
yield return imgfile;
if(imgfile.error==null){
img = new Texture2D(200, 200, TextureFormat.RGB24, false);
imgfile.LoadImageIntoTexture(img);
alert.text = "got image";
GameObject.Find("plane").renderer.material.mainTexture = img;
}else{
print(imgfile.error);
}
}
Images gets saved.
But I cannot open (load) image in system and android.
Getting error in system :
Couldn't open file /Users/ether/AppData/LocalLow/Company/Project/Screenshot.png
How to get it ???
This is because your path is wrong, you should use: application.dataPath, instead of Application.persistentDataPath.
imagesHello -
I want to display a picture from a local folder in a picturebox, however if that picture fails to load, I woud like to download the image from a website and display it. I have no idea how to do this, but what I have is this:
try
{
pictureBox1.Image = System.Drawing.Image.FromFile("images\\" + filename + "_0001.gif");
XmlIn1.Close();
}
catch
{
string downloadPath = "http://www.website.com/images/" + filename + "_0001.gif";
pictureBox1.Image = System.Drawing.Image.FromFile(downloadPath);
XmlIn1.Close();
}
Why not use the ImageLocation property?
pictureBox1.ImageLocation = "http://skins.gmodules.com/ig/images/logos/approved/beveled_white.png";
Above code will display Google Logo from Web.
try something like
WebClient wc = new WebClient();
MemoryStream ms = new MemoryStream(wc.DownloadData(<imgURL>));
pictureBox1.Image = Image.FromStream(ms);