Open image from PictureBox in windows photo viewer using ImageLocation - c#

I am trying to open an image from the PictureBox using ImageLocaton Property, because I want in the future to store the images on an online Database.
I've tried this code but says that pictureBox1.ImageLocation.ToString() is null:
private void pictureBox1_Click(object sender, EventArgs e)
{
Process.Start(pictureBox1.ImageLocation.ToString());
}
I also have seen it in the properties tab, but why?

You just need to set the ImageLocation of the pictureBox to set its Image (not get it that is obviously null if not set):
pictureBox1.ImageLocation = someurl;

Related

How to display/read bitmap in ASP.net web application C#?

protected void btnSTart_Click(object sender, EventArgs e)
{
cam = new
VideoCaptureDevice(webcam[DropDownList1.SelectedIndex].MonikerString);
cam.NewFrame += new NewFrameEventHandler(cam_NewFrame);
cam.Start();
}
private void cam_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap bit = (Bitmap)eventArgs.Frame.Clone();
//pictureBox1.image = bitmap;
//This last line of code was used in C# window console
}
I am using aforge to do a video through my laptop's webcam. The webcam is working fine, but I just can't seem to find a way to display the bitmap. Do I have to use the asp Image or some other control do it and how do I use that control to do so? Any help would be appreciated.
In an ASP.NET application, the C# is executed on the server. This means that you need a way of getting the image back to the client. This can be done in a few ways (for example, cache the resulting image and provide an endpoint to the client to be able to download it).
Here is an article on getting dynamically generated images to the client. Not sure about which version of ASP.NET you are using, but the concepts will be fairly similar.

Changing Image to another Image in Resources folder (VisualStudio 2015 / c#)

I'm trying to change the Background Pic of a Button to another Pic that I saved in the Resources Folder. Currently The Code is the following (FinalDStagePickBANNED.png being the Pic I want it to change to):
private void FinalD_Click(object sender, EventArgs e)
{
BanFDButton.Image = (Image)Properties.Resources.ResourceManager.GetObject(FinalDStagePickBANNED.png);
}
The Thing is, that it apparently finds no Pics in the Resources-Folder, although there are like 10 pics.
Solved: The solution to the problem was to put the FinalDStagePickBANNED into quatation-signs, and to remove hte .png ending.

Button Click will not navigate to a new WPF page

I cannot figure out why my button click is not navigating to a new page. I have tried writing this code several ways, but none of them work. EnlargedScreenCap is a WPF page and is in the same directory as the window in which I want to load it.
private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
NavigationService nav = NavigationService.GetNavigationService(this);
ImageSource image = sender as ImageSource;
EnlargedScreenCap esc = new EnlargedScreenCap();
esc.SetImage(image);
nav.Navigate(esc);
}
Written like this I get a null reference exception because NavigationService is not getting initialized.
private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
ImageSource image = sender as ImageSource;
EnlargedScreenCap esc = new EnlargedScreenCap();
esc.SetImage(image);
NavigationService nav = NavigationService.GetNavigationService(this);
nav.Navigate(new Uri("//EnlargedScreenCap.xaml"), UriKind.RelativeOrAbsolute);
}
When written like the above code, I get an invalid URI error, although nav is still null.
I tried searching around and this problem has been brought up many times, but no one seems to have a decent explanation or at least one that I have been able to successfully apply.
Could someone point me in the right direction?
I do not think you should be creating the NavigationService the way you are doing. Also if you want to enable navigation all this should be done in a Frame
<Frame x:Name="_mainFrame" />
Then you could do something like
_mainFrame.NavigationService.Navigate(new Uri("EnlargedScreenCap.xaml", UriKind.Relative));
Without the double slashes in front.
Checkout this article.
http://paulstovell.com/blog/wpf-navigation
Hope it helps

How to change the background of a button programatically?

I need to change the BackgroundImage of a button on click of another button (In Windows Forms in C#). But I can't find out how to do it!!
I searched on the internet and found many examples and all of them use ImageBrush, ImageSource etc.... but these don't work on my application, it shows me errors every time I Use them.
I read on the internet that I have to add this namespace:
using Windows.UI.Xaml.Media.Imaging;
But it shows me an error on the begging which says to add this System before Windwons and when I add it:
using System.Windows.UI.Xaml.Media.Imaging;
it shows me than the error at UI .... I can't figure it out how to solve this!!
Please help me guys!
To Change Background Image of a button there are two ways i know.
Add the Image to the resources folder of your project and use.
private void button2_Click(object sender, EventArgs e)
{
button1.BackgroundImage = Properties.Resources.ImageName;
}
Use Image.FromFile();
private void button2_Click(object sender, EventArgs e)
{
button1.BackgroundImage = Image.FromFile(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "//Card1.png");
}
You are trying to use solutions for WPF in Winforms. This will not work.
The class you need is System.Drawing.Image (or System.Drawing.Bitmap, which inherits from Image).
Bitmap b = new Bitmap(#"C:\myBitmap.jpg");
myButton.Image = b;
Be sure to call Dispose on your Bitmap if and when it is no longer in use.

how i can insert an image in web browser control in c# with out open image ui?

I have a web browser control in C# that it's design mode is on. I use it to make a (WYSIWYG) HTML editor. I want to insert a photo on this without UI, when user wants to insert image I show to him/her a window that shows on it some known name for user. Then with search (s)he find her/his photo and add it to control.
this is my open image form:
Photos are in database and user only know them with names. I upload all of them in a folder and show above list to user and user selects a picture. I want to add image by it's location in hard disk and allow user to set its alignment .
How I can do this ?
Adding a new element to a document is very logical. The first step is to create the node (element) you wish to append, the next is to find where you wish to append it within the document, and the final step is to actually do the appending.
I write an Example for you:
private void Form1_Load_1(object sender, EventArgs e)
{
webBrowser1.DocumentText = "<html><body></img></body></html>";
}
private void insert_image_btn_Click(object sender, EventArgs e)
{
HtmlElement userimage = webBrowser1.Document.CreateElement("img");
userimage.SetAttribute("src", "image location");
userimage.Id = "imageid";
webBrowser1.Document.Body.AppendChild(userimage);
}
private void btn_set_aliign_Click(object sender, EventArgs e)
{
webBrowser1.Document.GetElementById("imageid").SetAttribute("float", "right");
}

Categories