Background image is changed to default on wp7 - c#

In my windows phone 7 application, i have created a button to change the default background image and the users can have their own custom skins on the app. It worked perfectly. But when the users exits the app and relaunches it again the application's background image is changed to default. But what i needed is, the application should have the last image that is chosen by the user even is launched no. of times. Can anyone help me with this? Thanks in advance for your hard work!
private void BackgroundBrowserIcon_MouseEnter(object sender, MouseEventArgs e)
{
var PhotoChooser = new PhotoChooserTask();
PhotoChooser.Completed += new EventHandler<PhotoResult>(PhotoChooser_Completed);
PhotoChooser.Show();
}
void PhotoChooser_Completed(object sender, PhotoResult e)
{
{
if (e.TaskResult == TaskResult.OK)
{
System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
bmp.SetSource(e.ChosenPhoto);
var app = Application.Current as App;
if (app == null)
return;
var imageBrush = new ImageBrush { ImageSource = bmp, Opacity = 1.0d };
this.LayoutRoot.Background = imageBrush;
app.backchanged = true;
app.appbrush = imageBrush;
}
}
}

Are you using IsolatedStorageSettings to store the last chosen photo, and then loading it on app launch?
Update:
Check out this post, as it explains how to code exactly what you are looking to accomplish: http://www.windowsphonegeek.com/tips/All-about-WP7-Isolated-Storage---Read-and-Save-Captured-Image

Check out this article to learn how to store IsolatedStorageSettings.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
namespace F5debugWp7IsolatedStorage
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void button3_Click(object sender, RoutedEventArgs e)
{
IsolatedStorageSettings ISSetting = IsolatedStorageSettings.ApplicationSettings;
if (!ISSetting.Contains("DataKey"))
{
ISSetting.Add("DataKey", txtSaveData.Text);
}
else
{
ISSetting["DataKey"] = txtSaveData.Text;
}
ISSetting.Save();
}
}
}

Related

Are there any flags i need to provide to CefSharp to work with document elements?

I converted a window of mine to use CefSharp in order to render some PDF file. One of the features the old component supported (WebBrowser of WPF, which unfortunately depends on IE, which does not work in this case) is accessing javascript elements through code in order to be aware of when the PDF has been scrolled to the bottom. Unfortunately this does not appear to work with CefSharp with the following code. Perhaps i am missing some initializer flag for this to work?
Currently in my Logs All i get is ScrollProgress|0|0|734
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using CefSharp;
using NLog;
using Application = System.Windows.Application;
using MessageBox = System.Windows.MessageBox;
using WebBrowser = System.Windows.Forms.WebBrowser;
namespace MyNamespace
{
public partial class PdfConfirmWindow : Window
{
private static readonly ILogger Log = LogManager.GetLogger(nameof(PdfConfirmWindow));
public PdfConfirmWindow()
{
InitializeComponent();
}
private void WindowLoaded(object sender, RoutedEventArgs e)
{
ChromiumWebBrowser.LoadingStateChanged += ChromiumWebBrowserOnLoadingStateChanged;
UpdateBrowserContent();
}
private void ChromiumWebBrowserOnLoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
{
if (!e.IsLoading)
{
Log.Debug("Loading completed");
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
// (window.innerHeight + window.scrollY) >= document.body.offsetHeight
// e.scrollHeight - e.scrollTop === e.clientHeight
// CefSharp.PostMessage('EndOfDocumentReached');
const string script = #"
(function(){
var intervalHandler;
function onScrollCallback() {
var e = document.body;
var values = ['ScrollProgress'];
values.push(document.body.clientHeight);
values.push(window.scrollY);
values.push(window.innerHeight);
CefSharp.PostMessage(values.join('|'));
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight){
//clearInterval(intervalHandler);
}
}
setTimeout(function(){
var intervalHandler = setInterval(function(){
onScrollCallback();
}, 100);
}, 500);
})();
";
ChromiumWebBrowser.Focus();
ChromiumWebBrowser.WebBrowser.JavascriptMessageReceived += WebBrowserOnJavascriptMessageReceived;
ChromiumWebBrowser.WebBrowser.ExecuteScriptAsync(script);
}));
}
}
private async void WebBrowserOnJavascriptMessageReceived(object sender, JavascriptMessageReceivedEventArgs e)
{
await UIHelper.Thread;
// ChromiumWebBrowser.WebBrowser.JavascriptMessageReceived -= WebBrowserOnJavascriptMessageReceived;
if (e.Message?.ToString().Equals("EndOfDocumentReached", StringComparison.OrdinalIgnoreCase) == true)
{
SetReachedStatus(true);
}
if (e.Message?.ToString().StartsWith("ScrollProgress", StringComparison.OrdinalIgnoreCase) == true)
{
Log.Debug(e.Message?.ToString());
}
}
}

Adding Page Numbering in a Word document C# starting from given Page number

It's been 8 hours since i'm stuck here. I want ask user to input a page number and starting from the given page it should add page numbering till the .docx file.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using Word = Microsoft.Office.Interop.Word;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private string fileName;
public Form1()
{
InitializeComponent();
}
private void minimize_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
private void Close_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Word Documents|*.docx";
dlg.ShowDialog();
fileName = dlg.FileName;
textBox1.Text = fileName;
textBox1.Enabled = true;
}
private void button2_Click(object sender, EventArgs e)
{
}
}
}
On button2_click i want to update the file by using data from a textBox2, can anybody complete it?
I won't complete it, but I will point you in the right direction. You have to have a reference to Microsoft Word. What you are trying to do is typically referred to as automation or more specifically Microsoft Word Automation.
You can google that and find examples or try this location for starting point.
https://learn.microsoft.com/en-us/previous-versions/office/troubleshoot/office-developer/automate-word-create-file-using-visual-c

How to detect canny edge and integral projection on a real time webcam using c# aforge?

"I have been trying to detect canny edge on an image and it has been successful, but I don't know how to detect its edge if I want it real time, here is my code, it has no error but the canny window can't be processed
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//using KomCit;
using System.Drawing.Imaging;
using System.IO;
using System.Timers;
using AForge;
using AForge.Imaging.Filters;
using AForge.Video.DirectShow;
using System.Threading;
namespace canny_video
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private FilterInfoCollection CaptureDevice;
private VideoCaptureDevice FinalFrame;
void FinalFrame_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
{
CameraBox.Image = (Bitmap)eventArgs.Frame.Clone();
}
private static Image resizeImage(Image imgToResize, Size size)
{
return (Image)(new Bitmap(imgToResize, size));
}
private void Form1_Load(object sender, EventArgs e)
{
//timer1.Enabled = true;
CaptureDevice = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo Device in CaptureDevice)
{
listDevice.Items.Add(Device.Name);
}
listDevice.SelectedIndex = 0;
FinalFrame = new VideoCaptureDevice();
}
private void start_Click(object sender, EventArgs e)
{
FinalFrame = new VideoCaptureDevice(CaptureDevice[listDevice.SelectedIndex].MonikerString);
FinalFrame.NewFrame += new AForge.Video.NewFrameEventHandler(FinalFrame_NewFrame);
FinalFrame.Start();
//CannyBox.Image = (Bitmap)CameraBox.Image.Clone(); //capture image bitmap
//Bitmap gambar = new Bitmap(CameraBox.Image);
Bitmap gambar = new Bitmap(CameraBox.Image);
Grayscale gray = new Grayscale(0.2125, 0.7154, 0.0721);
CannyEdgeDetector cany = new CannyEdgeDetector(0, 70);
Bitmap hasil = cany.Apply(gray.Apply(gambar));
// BlobsFiltering blob = new BlobsFiltering(0, 0, 20, 20);
//Bitmap hasil = blob.Apply(gray.Apply(gambar));
//CannyBox.Width = gambar.Width;
//CannyBox.Height = gambar.Height;
CannyBox.Image = hasil;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (FinalFrame.IsRunning == true)
{
FinalFrame.Stop();
}
}
}
}
"
My problem above is solved, thank you :)
but I have another problem on integral projection, I didn't know how to do it though.
please help, thank you in advance
Some comments:
Your two private variables are very confusingly named. Your CaptureDevice is a collection of all the capture devices on the computer, while your FinalFrame is a capture device.
You do not look for canny edges on the bitmap upon reception.
The NewFrame event handler runs in the streaming thread, so you should use a .BeginInvoke in there to make it usable by the UI thread.
What you may do:
Inside _NewFrame handler, use BeginInvoke to transfer the cloned image to a ProcessCameraImage method (that will hence run on the UI thread).
Apply canny edge detection within this method.
Then assign the result to your picture box.
Note: I don't know how CPU heavy canny edge detection is. If it's costly, doing it on the UI thread may block user interaction. In that case you could do it within the streaming thread and only transfer the processed image for display. But depending on the time it takes, this may force the camera to lower its framerate.
thank you for your answer, it has been solved just now, I've modified it and it somehow solved
here is the code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AForge;
using AForge.Imaging;
using AForge.Imaging.Filters;
using AForge.Video;
using AForge.Video.DirectShow;
using System.Drawing.Imaging; //Save P2
using System.IO; //Save P2
namespace AForgeCamera
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Bitmap video;
private FilterInfoCollection CaptureDevice;
private VideoCaptureDevice FinalFrame;
int mode;
private void Form1_Load(object sender, EventArgs e)
{
CaptureDevice = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo Device in CaptureDevice)
{
comboBox1.Items.Add(Device.Name);
}
comboBox1.SelectedIndex = 0;
FinalFrame = new VideoCaptureDevice();
}
private void button1_Click(object sender, EventArgs e) //Tombol Start
{
FinalFrame = new VideoCaptureDevice(CaptureDevice[comboBox1.SelectedIndex].MonikerString);
FinalFrame.NewFrame += new NewFrameEventHandler(FinalFrame_NewFrame);
FinalFrame.Start();
}
void FinalFrame_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
video = (Bitmap)eventArgs.Frame.Clone();
Bitmap video2 = (Bitmap)eventArgs.Frame.Clone();
if (mode==1)
{
Grayscale gray = new Grayscale(0.2125, 0.7154, 0.0721);
Bitmap video3 = gray.Apply(video2);
CannyEdgeDetector canny = new CannyEdgeDetector(0, 70);
canny.ApplyInPlace(video3);
pictureBox2.Image = video3;
}
pictureBox1.Image = video;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (FinalFrame.IsRunning == true)
{
FinalFrame.Stop();
}
}
private void btnTrackingObject_Click(object sender, EventArgs e)
{
mode = 1;
}
}
}
but now I am working on the next problem, I try to detect the location of the object using integral projection, is it possible to use aforge to do it?

C# Using Youtube API - How do I check the last time a particular user uploaded a video to Youtube?

I know how to upload a video to Youtube using Youtube API within C#
But I'd like to use the Youtube API to return a date when a particular user last uploaded a video.
My code for uploading a video using C# is below, but I really don't know how to do the above???
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Google.GData.Client;
using Google.YouTube;
using Google.GData.Extensions.MediaRss;
using Google.GData.YouTube;
using Google.GData.Extensions.Location;
namespace UploadLimit
{
public partial class Form1 : Form
{
string key = "somegarbage";
string appName = "SlowUpload";
string username = "blarg";
string password = "blarg";
public Form1()
{
InitializeComponent();
}
private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
DialogResult result = dialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
txtFile.Text = dialog.FileName;
}
private void btnUpload_Click(object sender, EventArgs e)
{
YouTubeRequestSettings settings = new YouTubeRequestSettings(appName, key, username, password);
YouTubeRequest request = new YouTubeRequest(settings);
Video newVideo = new Video();
newVideo.Title = "My Test Movie";
newVideo.Tags.Add(new MediaCategory("Autos", YouTubeNameTable.CategorySchema));
newVideo.Keywords = "cars, funny";
newVideo.Description = "My description";
newVideo.YouTubeEntry.Private = false;
newVideo.Tags.Add(new MediaCategory("mydevtag, anotherdevtag",
YouTubeNameTable.DeveloperTagSchema));
newVideo.YouTubeEntry.Location = new GeoRssWhere(37, -122);
// alternatively, you could just specify a descriptive string
// newVideo.YouTubeEntry.setYouTubeExtension("location", "Mountain View, CA");
newVideo.YouTubeEntry.MediaSource = new MediaFileSource(txtFile.Text, "video/quicktime");
Video createdVideo = request.Upload(newVideo);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace UploadLimit
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
You can get all the user's videos and get the latest date:
var videos = new YouTubeRequest().GetVideoFeed(userId).Entries
DateTime lastUploadDate = videos.Max(video => video.YouTubeEntry.Published)
To get the actual video's title:
var lastVideo = videos.Where(video => video.YouTubeEntry.Published == lastUploadDate).First();
var name = lastVideo.Title

Access Violation runtime error when getting WebBrowser .Url property

Getting an "Access Violation" runtime error when trying to get a WebBrowser's .Url property in an Outlook Add-In I'm writing. Need some help on how to get past this please. Research indicates I may need to set "FullTrust" permissionset, have tried that with no success.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Security;
using System.Security.Permissions;
namespace MyAddin1
{
public partial class authForm : Form
{
public string currentUrl;
public authForm()
{
InitializeComponent();
}
private void formLoaded(object sender, EventArgs e)
{
WebBrowser browser = new WebBrowser();
browser.Location = new System.Drawing.Point(0, 0);
browser.Width = 870;
browser.Height = 510;
browser.Navigate("https://www.yammer.com/dialog/oauth?client_id=<redacted>&response_type=token");
browser.Show();
//runtime error occurs on following line
currentUrl = browser.Url.ToString();
browser.Url = new Uri("http://www.yahoo.com");
browser.Navigated += new WebBrowserNavigatedEventHandler(checkForToken);
this.Controls.Add(browser);
}
private void checkForToken(object sender, EventArgs e)
{
MessageBox.Show(currentUrl);
}
}
}
browser.Url is initially null, Change your code as below.
if (browser.Url != null)
{
currentUrl = browser.Url.ToString();
}

Categories