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.
Related
Sorry for the mess of a title.
Ive got the following C# script handling an Async Button press:
private async void CalcButton_ClickAsync(object sender, RoutedEventArgs e)
{
await Windows.System.Launcher.LaunchUriAsync(new Uri("calculator:"));
}
Issue i have is that the calculator is loading up the exact same size as the main program window. I was wondering if there is a way to over-ride the sizing of the launched windows, i want the calculator to open up as small as possible really.
Come to think of it, i think every popup windows is doing this (save/open file dialogues) any thoughts/suggestions would be amazing
You can request the desired remaining view. Keep in mind that it is specifying the remaining view of the app that is launching the calculator... not the size of the calculator app.
link here
private async void LaunchCalculator(object sender, RoutedEventArgs e)
{
var options = new Windows.System.LauncherOptions();
options.DesiredRemainingView = Windows.UI.ViewManagement.ViewSizePreference.UseMore;
await Windows.System.Launcher.LaunchUriAsync(new Uri("calculator:"), options);
}
I am building a Windows Phone 8 version of an app that I already have for Windows Phone 7.1, which works perfectly.
Inside the Application_Deactivated event (in App.xaml.cs) I attempt to update the secondary tile of my app, if pinned to the start screen. Because it is a custom tile, I build it in code using a grid and by adding elements to it. So in the final step, I have something like (layoutRoot is of type Grid) :
layoutRoot.Measure(new Size(336, 336));
layoutRoot.Arrange(new Rect(0, 0, 336, 336));
layoutRoot.UpdateLayout();
WriteableBitmap bitmap = new WriteableBitmap(336, 336);
bitmap.Render(layoutRoot, null);
bitmap.Invalidate();
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (Stream fileStream = storage.CreateFile("/Shared/ShellContent/BackBackgroundImage.png"))
{
bitmap.SaveJpeg(fileStream, 336, 336, 0, 100);
}
}
So then I can update the Tile very easily. The problem is that when the app is running and I tap the "Windows" button, the app is successfully suspended and the Tile updated, but when I hit "back" to make it active again, a default "loading" text is shown on screen and nothing will happen. However, I have noticed that by commenting out the line bitmap.Render(layoutRoot, null);, the app is re-activated successfully and it works fine, despite the fact that the Tile does not get updated upon suspension, as expected.
In the WP7.1 version of the app, this never happens, although the method for updating the Tile is the same. I really cannot figure out what is going on. Any comment/suggestion/advice will be appreciated.
Edit. Aplication_Deactivated code:
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
UpdateLiveTile(); //Generate Tile content (as shown above) and update the Tile if it is pinned
ExportData(); //Writes data in a file
StartPeriodicAgent(); //Starts the periodic background agent that updates the live tile
}
I think that you should consider moving this code to OnNavigatedFrom event handler of the page(s). There can be side effects, because bitmap.Render require UI thread to render your xaml code.
Workaround:
RootFrame.Navigating += RootFrame_Navigating;
void RootFrame_Navigating(object sender, NavigatingCancelEventArgs e)
{
if(e.Uri.OriginalString=="app://external/")
{
// update the custom tiles here and the resume error is gone..
}
}
Source: http://social.technet.microsoft.com/wiki/contents/articles/22256.windows-phone-8-writeablebitmap-and-app-resume.aspx
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.
My Silverlight application has multiple XAML pages. For example, one displays a clock, one displays a timer. I have buttons to switch back and forth like so:
private void switchRight(object sender, RoutedEventArgs e)
{
this.Content = new Clock();
}
private void switchLeft(object sender, RoutedEventArgs e)
{
this.Content = new Timer();
}
I am trying to use the NavigationService to switch back and forth so I can have other pages running in the background rather than creating a new instance each time.
I am trying
NavigationService.Navigate(new uri("/Timer.xaml", UriKind.Relative));
but it doesn't seem to do anything and I can't find any good examples to help.
Here is a link
http://blogs.msdn.com/b/dphill/archive/2009/04/28/silverlight-navigation-part-3.aspx ,
Beside, I think you can use Threading for background processes.i.e.when you start a timer no need to show any xaml.
But for page instances you need to manage it very carefully otherwise stackoverflow :)
Depending on business rules its hard to decide navigation as being in a web browser.
We created our own Wizard (with rules). You may create your own NavigationManager. For validation I can offer http://fluentvalidation.codeplex.com/
I'm currently writing an application in ASP.NET/C#, where the user needs to be able to generate PDF's of invoice summary's through the web based admin system.
The customer did not want to use an open source solution such as iTextSharp (stupid, I know) and instead purchased Adobe Acrobat/Reader (not sure which) which come with a virtual PDF printer. So we'll be interfacing with this printer on the server to generate the PDF's.
That's working well - we can easily generate PDF's and display them to the user. However, the way the content is written to the document to be printed (using the Graphics class of the PrintPageEventArgs event) is a bit foreign to me right now. Writing the text and header information is a piece of cake, but what's the easiest way of writing the contents of the GridView to the doucment?
Here's some example code of the sort of thing I'm using:
protected void Page_Load(object sender, EventArgs e)
{
PrintDocument NewDoc = new PrintDocument();
NewDoc.PrinterSettings.PrinterName = "PrinterName";
NewDoc.PrintPage += new PrintPageEventHandler(NewDoc_PrintPage);
NewDoc.Print();
}
void NewDoc_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawString("Test Header", new Font("Verdana", 18), Brushes.Black, 220, 120);
}
Ended up having to essentially draw the grid myself. Pretty hacky but it works.