Webbrowser windows phone don't show an image - windows-phone-7

In my windows phone application, i'm using a webbrowser to render a HTML like this
private void webBrowserHTML_Loaded(object sender, RoutedEventArgs e)
{
WebBrowser web = sender as WebBrowser;
string description = web.DataContext.ToString();
web.NavigateToString(description);
}
My problem is i have html code that show an image in the variable description:
<img width=\"220\" class=\"logo\" alt=\"3950\" src=\"bandeau3950.png\" />
I put the image in the same folder with my code, but the image is not shown in the application.
Any solution please?

Solution 1
Use Base64 image uri format so that image is defined as part of html. You can use online conversion tools, like http://webcodertools.com/imagetobase64converter
Solution 2
Copy all required images to isolated storage folder. It can be done during app start up.
http://msdn.microsoft.com/en-us/library/ff431811%28VS.92%29.aspx
When html string is received save it to the same isolated storage as index.html
Do Navigate(new Uri("folder/index.html", UriKind.Relative))
In this case browser will be able to show images since your page and images in the same isolated storage folder.

Related

Uploading images to Windows Server and making them available publicly

I am trying to upload images in my windows server VM "hosted on-premise" and make these images available publicly like www.example.com/imageFolder/cat.png.
This VM has IIS enabled (I am not sure if IIS is related here) and it is assigned a URL and available publicly.
Aside from any programming languages or frameworks, I just want to know if storing the image in the server and making it available via a link is possible? If so, how can I achieve it?
To clarify further:
I believe what I want is very simple and tedious.
Consider the following workflow:
Run an API that has end points to receive images on the server.
Store the messages in the server.
Return the link that points to the picture.
I want to know the procedure from the windows server side like
Do I need to set certain properties on the folder where I will store the images?
Do I need to add a site to show the images back to the user?
I am a developer and I am new to the Windows Server & IIS so I may not have all the fundamentals.
I made a sample by using ASP.NET MVC5. You can follow this article to upload image in MVC5 application.
Upload Images on Server Folder Using ASP.NET MVC
Then, I do some changes so that it can display the url of images..
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
Uri requestUri = HttpContext.Request.Url;
string baseUrl = requestUri.Scheme + Uri.SchemeDelimiter + requestUri.Host + (requestUri.IsDefaultPort ? "" : ":" + requestUri.Port);
if (ModelState.IsValid)
{
try
{
if (file != null)
{
string path = Path.Combine(Server.MapPath("~/Images"), Path.GetFileName(file.FileName));
file.SaveAs(path);
}
string link = baseUrl + "/Images/" + file.FileName;
ViewBag.FileStatus = "File uploaded successfully.";
//Return the url of image
ViewBag.FileLink = link;
}
catch (Exception e)
{
ViewBag.FileStatus = "Error while file uploading. Error message is "+e.Message;
}
}
return View("Index");
}
Index.cshtml add this to show url.
<div class="col-md-offset-2 col-md-10 text-success">
#ViewBag.FileLink
</div>
Don't forget to add a folder named Images to store images. After publishing, you also need to add it in published folder, otherwise error message will show that cannot find folder.
It works well.

Image saved by the app doesn't show up in the gallery

I trying to create a whatsapp status saver in flutter. I trying to save the whatsapp status. I created a folder statuses in /storage/emulated/0/statuses/ and The process of copying goes well. But that Image is not shown in the gallery app.
So I even Tried storing it in DCIM/Camera still it doesn't show up there. But when the copy the same image using file explorer then that image shows up in gallery app. I think something is wrong with the image properties.
The code used to save is here.
saveFile(filePath) async {
String newFilename;
File originalFile = File(filePath);
Directory _directory = await getExternalStorageDirectory();
if (!Directory("/storage/emulated/0/statuses/").existsSync()) {
Directory("/storage/emulated/0/statuses/")
.createSync(recursive: false);
}
String curDate = DateTime.now().toString();
newFilename = "/storage/emulated/0/statuses/VIDEO-$curDate.jpg";
await originalFile.copy(newFilename).then((value) {
print("Saved: " + newFilename);
});
}
When you change a media, you should tell the device to re-scan. This image saver plugin will notify the Android OS about the media that is saved.
If you don't want the plugin, you can use platform channels to write native code yourself.
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
This issue is discussed here and here.

Image doesn’t load consistently from Azure blob storage

I am having an erratic problem using Azure blob storage where my images do not load consistently. The problem is that sometimes when I load a web page, the browser will not show the image, but if I refresh it will load correctly.
When the image doesn't load, the browser shows the default image placeholder. Here is an example:
If I check the hyperlink for the image placeholder, I find that it is the same as the when the image loads successfully, except the Shared Access Signature is different.
Sometimes the same image will fail to load for one link but load successfully for another link even in the same page and same page load. The only difference in the URL is the Shared Access Signature.
Here is my code to build the URL with the shared signature
// Get reference to blob (file) that is to be downloaded
blob = blobContainer.GetBlobReference(blobURL.ToString());
// Get shared access signature to download file from azure blob (valid upto "active duration" minutes) from now
signature = blob.GetSharedAccessSignature(new SharedAccessPolicy()
{
SharedAccessStartTime = null,
SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(60),
Permissions = SharedAccessPermissions.Read
});
// Append signature query string to blob / file that is to be downloaded
downloadURL = string.Format("{0}{1}", blob.Uri.AbsoluteUri, signature);
This is the final HTML image link on the web page, i.e. if I show source on the web page in the browser:
<img alt="Profile Picture" src="https://mystorageaccount2.blob.core.windows.net/abcdefg1-hi23-40b5-86de-a20b568f5626/1601/1234d664d1b74ce1aebf4403e5b74af7.jpg?se=2015-10-31T11%3A38%3A39Z&sr=b&sp=r&sig=SaiUToJg%5Ab3zcdef8EeOq84urHf6HQqS%2BAFt1dEQMNI%3D">
Has anyone else seen this problem? Any recommendations on what I might be doing wrong?
I suspect this could be related to the expiry period which you have set on your image blob's shared access signature (SAS). Is there any good reason where you need to set the SAS to 1 minute when you have set it's permission to read-only?

How to get video thumbnail of a video file in windows phone 8?

I want to get thumbnail of a video file which uri or path is given. I have searched for api in windows phone developer site bt with no success. If anybody have does this please help me.
There is a method GetThumbnailAsync in class StorageFile which intended to retrieve thumbnail of image and video files. So despite the fact that MSDN states that this method throws exception and not supported for Windows Phone 8, actually this method works when invoked with parameter ThumbnailMode = ListView. But I seems that using this method requires ID_CAP_MEDIALIB_PHOTO_FULL.
var files = await KnownFolders.CameraRoll.GetFilesAsync(); // Throw UnauthorizedAccessException without ID_CAP_MEDIALIB_PHOTO_FULL
var storageFile = files.First();
var thumbnail = await storageFile.GetThumbnailAsync(ThumbnailMode.ListView);
Video Thumbnail code in c# windows phone
First we use capturesource.completed then after we create the thumbnail and use that thumbnail
and we use capturesource.Imageasync()
And this is the only way to generate the thumbnail image from video file.

How to access resources in Java Struts 1 app

In a Struts 1 Web App I can access images from a .jsp by
<img src="../../images/myImageName.png"/>
Am I also able to reference that image from a .java class in my source directory?
I am using iText and can fetch an image from a url
String imageUrl = "http://jenkov.com/images/" +
"20081123-20081123-3E1W7902-small-portrait.jpg";
Image image2 = Image.getInstance(new URL(imageUrl));
but if I try and fetch one from
Image image = Image.getInstance("../../images/myImageName.png"/);
It always looks in the bin folder of my server. How can I get the relativePath back to my image?
If the image is in the web app content directory then you need the app context relative path:
String relativeWebPath = "images/myImageName.png";
String absoluteDiskPath = getServletContext().getRealPath(relativeWebPath);
Would I do that? Not unless there's a good reason; I'd prefer either a path off the app context altogether (and the image could be streamed by the app, or set as a symlink, etc) or a classpath-based resource.

Resources