Get part of image from AForge.Net videosourceplayer - c#

Can anybody help me with this problem, please?
I put VideoSourcePlayer control from AForge.Net, a picturebox and a button on my form. When clicking I want to show only a region from current frame to picturebox. I can show the whole frame using this code:
Bitmap bitmap = (Bitmap)videoSourcePlayer1.GetCurrentVideoFrame().Clone();
pictureBox1.Image = bitmap;

Bitmap bitmap = this.VideoSourcePlayer.GetCurrentVideoFrame();

Related

Drawing a Panels Handle to a Bitmap

I have a WPF-Application which hosts a WinformsPanel
<WindowsFormsHost>
<windowsForms:Panel
x:Name="PlayerHost">
</windowsForms:Panel>
<WindowsFormsHost>
I then use this Panel to display a video. I'm using Mpv.NET lib to do this.
The video player is initialized properly:
//panel.Handle is the windowsForms:Panel named PlayerHost
player = new MpvPlayer(panel.Handle, Common.IO.FindLib.FindMpvLib(binaryPath));
player.Load(videoFilePath);
Now, if I try to draw the panels content, the resulting image remains blank. The code to draw the image is as follows:
using (var bmp = new Bitmap(panel.ClientSize.Width, panel.ClientSize.Height))
{
panel.DrawToBitmap(bmp, panel.ClientRectangle);
bmp.Save(#"Some:\path.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
}
To make it clear: The video gets displayed. I can see the video content. And I start drawing to an image when the media is properly loaded. I even offloaded the drawing command to a button click. So while the video was running I tried to take a "frame capture" so to say. But the image remains blank.
How can I capture the panels content? Has it something to do with the native Handle being provided to the video player? Thanks in advance.
You can save the panels content to a bitmap with the following code:
using (Bitmap b = new Bitmap(panel.Width, panel.Height))
{
panel.DrawToBitmap(b, new Rectangle(0, 0, b.Width, b.Height));
b.Save("test.png");
}

Resizing components in an image when image was resizing in c#

I have an Image in that I need to place some textboxes and checkboxes in the Image but when I try to resize the image in a picturebox, how to resize all the components that was placed in the Image ?
For this I used Windows Form
1.adding picturebox and placing the components in that picturebox
Sample code I used was :
Metafile EMF = (System.Drawing.Imaging.Metafile)System.Drawing.Imaging.Metafile.FromFile("Sample.EMF");
this.pictureBox1.Image = EMF;
pictureBox1.Controls.Add(textBox1);
this.textBox1.Parent = this.imageBox;
textBox1.BringToFront();
With this code I was able to fix the components' position in the image but when the image was resized , how can I resize all the components that are placed in the image.

How to save picturebox's paint function drawings only on bitmap in c#?

I'm drawing shapes on the PictureBox control using Paint event of it.
May I know how to save drawn shapes only on a bitmap without the picture box image(current).
I don't want to save the PictureBox image.
I have created the bitmap from the image(White background image) for saving a drawing on it.
I want to save it on created bitmap image(4).
Image WhiteBackGroundImage=Image.FromFile("path");//fetching white back ground image.
Bitmap pic=new Bitmap(WhiteBackGroundImage);//creating bitmap
pictureBoxImage.DrawToBitmap(pic,pictureBoxImage.ClientRectangle);
pic.Save("path", ImageFormat.Png);

Rotateflip image adding to image?

I have an image in a picture box, and when I do this in my code:
pictureBox1.Image.RotateFlip(RotateFlipType.Rotate180FlipX);
The image has a black box on the right side of the picture box?
Hard to repro. For one, the PictureBox control has no idea that the image was changed, it won't even repaint it. At least do it like this so it knows:
var img = pictureBox1.Image;
img.RotateFlip(RotateFlipType.Rotate180FlipX);
pictureBox1.Image = img;

C# code to save the zoomed image on picturebox control in windows mobile App

I capture a image from windows mobile camera and save it on
picturebox control..now to zoom the picture i am increasing
its size by Onpaint event.The image is getting zoomed but
i am not able to save the zoomed image(ie.., the increased
image size)...
Please let me know
Presumably you have a Bitmap being displayed in the PictureBox? If so, then do this:
Bitmap bmp = (Bitmap)myPictureBox.Image;
bmp.Save("\My Documents\My Pictures\image.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

Categories

Resources