C # Implementation of mobile phone photos and save watermark Photos _c# Tutorial

Source: Internet
Author: User

Image acquisition needs to call the camera on the line to take photos, online check the data, you need to refer to the following 3 DLLs.

Look at the running interface.

The interface is relatively low, mainly functional implementation.

private void Camera_load (object sender, EventArgs e) {this.btnSave.Enabled = false; try {bordersize = getbordersize (thi
s);
CaptionHeight = GetCaptionHeight (this);
Initstudent ("", "", "");
This.comboBox_SizeMode.Text = "Fill (maintain proportion)";
Filterinfocollection infos = new Filterinfocollection (filtercategory.videoinputdevice); if (infos!= null) && (infos. Count > 0)) {} else {MessageBox.Show ("no video Device");
Loadvedio ();
This.splitContainer1.Panel2MinSize = 280;
This.splitContainer1.SplitterDistance = this.splitcontainer1.width-this.splitcontainer1.panel2minsize + 1;
MF = new Borderform (); Mf.
Show (this); Mf. left = (this. Left + THIS.SPLITCONTAINER1.PANEL1.WIDTH-MF.
Width)/2; Mf. top = (this. Top + THIS.SPLITCONTAINER1.PANEL1.HEIGHT-MF.
Height)/2; Marleft = MF. Left-this.
Left; Martop = MF. Top-this.
Top;
Rectangle rtpic = This.pictureBox_Camera.RectangleToScreen (This.pictureBox_Camera.ClientRectangle); Rectangle RTMF = This.mf.RectangleToScreen (this.mf.ClientRectaNgle); if (rtpic = null | | rtmf = NULL | | | rtpic.width = = 0 | | rtmf.width = = 0) {return;} MF.
left = ((Rtmf.width + rtmf.left) + (Rtpic.width + rtpic.left))/2; Mf.
top = ((Rtmf.height + rtmf.top) + (Rtpic.height + rtpic.top))/2; Mf.
SizeChanged + = new EventHandler (mf_sizechanged); Mf.
LocationChanged + = new EventHandler (mf_locationchanged);
Picturebox_camera_sizechanged (sender, E); Start Burst//this.
Shootonetime = 0;
This.timer1.Start (); The catch (Exception ex) {MessageBox.Show (ex).
Message, "Error", MessageBoxButtons.OK, Messageboxicon.error); }
}
//load camera device private void Loadvedio () {filterinfocollection infos = new Filterinfocollec
tion (filtercategory.videoinputdevice); if (infos!= null) && (infos. Count > 0)) {int index = 0; foreach (filterinfo info in infos) {this.cmbCaptureDevice.Items.Add (new deviceinfo INFO.N Ame, info.
Monikerstring, index, filtercategory.videoinputdevice));
index++;
} this.cmbCaptureDevice.SelectedIndex = 0; }
}
<summary>///photo///</summary> private void Shoot () {try {if (this.pictureBox_Camera.Image!= null &am  p;& (int) this.numericUpDown1.Value > 0 && (int) this.numericUpDown2.Value > 0) {Bitmap resultimage = new
Bitmap ((int) this.numericUpDown1.Value, (int) this.numericUpDown2.Value);
Graphics g = graphics.fromimage (resultimage); G.copyfromscreen (new Point (this.mf.location.x + 1, THIS.MF.LOCATION.Y + 1), new Point (6, 6 + (isWin7? 2:0)), New Size (R
EsultImage.Size.Width, ResultImage.Size.Height-(6 + (isWin7.2:0))); if (!string.
IsNullOrEmpty (XH)) {string str = "";
if (this.xh!= "") {str = THIS.XH;} else if (this. Sfzh!= "") {str = this.
Sfzh; else if (this. KSH!= "") {str = this.
KSH;
} if (this.checkBox2.Checked) {str = XM + "" + str;} int txtwidth = (int) (G.measurestring (str, new Font ("Arial", 9)).
Width * 1.1);
Rectangle rec = new Rectangle ((resultimage.width-txtwidth)/2, resultimage.height-16, TxtWidth, 15); G.fillrectangle (BRUSHES.WHite, REC);
StringFormat SF = new StringFormat (); sf.
LineAlignment = Stringalignment.center; sf.
Alignment = Stringalignment.center; Rec.
height++;
g.DrawString (str, New Font ("Song Body", 9), Brushes.black, REC, SF); } this.picturebox_tx.
Image = Resultimage; else {This.picturebox_tx.
Image = null; } catch (Exception ex) {MessageBox.Show (ex). Message, "", MessageBoxButtons.OK, Messageboxicon.error);}
Select the camera device private void cmbcapturedevice_selectedindexchanged (object sender, EventArgs e) {if (
This.cmbCaptureDevice.SelectedItem!= null) {this.cmbDeviceCapability.Items.Clear (); Videocapturedevice device = new Videocapturedevice ((deviceinfo) this.cmbCaptureDevice.SelectedItem).
monikerstring); for (int i = 0; i < device. Videocapabilities.length; i++) {videocapabilities capabilities = device.
Videocapabilities[i]; Devicecapabilityinfo item = new Devicecapabilityinfo (capabilities.
Framesize);
THIS.CMBDEVICECAPABILITY.ITEMS.ADD (item);
} deviceinfo SelectedItem = (deviceinfo) This.cmbCaptureDevice.SelectedItem; if (this.captureaforge!= null) {this.captureAForge.NewFrame = new Newframeeventhandler (this.captureaforge_newframe)
;
This.captureAForge.SnapshotFrame-= new Newframeeventhandler (this.captureaforge_snapshotframe);
if (this.captureAForge.IsRunning) {this.captureAForge.SignalToStop ();} this.captureAForge.WaitForStop ();
This.captureaforge = null; } this.captureaforge = new VidEocapturedevice (selecteditem.monikerstring);
This.captureAForge.ProvideSnapshots = true;
This.captureAForge.NewFrame + = new Newframeeventhandler (this.captureaforge_newframe);
This.captureAForge.SnapshotFrame + = new Newframeeventhandler (this.captureaforge_snapshotframe);
if (This.cmbDeviceCapability.Items.Count > 0) {this.cmbDeviceCapability.SelectedIndex = 0;}} }
//select Resolution private void Cmbdevicecapability_selectedindexchanged (object sender, EventArgs e) {string[] Strarray = This.cmbDeviceCapability.Text.Trim ().
Split (new char[] {' x '}); int width = Int.
Parse (Strarray[0]); int height = Int.
Parse (strarray[1]);
if (this.captureaforge!= null) {if (this.captureAForge.IsRunning) {this.captureAForge.SignalToStop ();}
This.captureAForge.WaitForStop ();
This.captureAForge.DesiredFrameSize = new Size (width, height);
This.captureAForge.DesiredSnapshotSize = new Size (width, height);
this.captureAForge.DesiredFrameRate = 1000;
This.captureAForge.Start (); }
}
/Set data source size private void combobox_sizemode_selectedindexchanged (object sender, EventArgs e) {switch (this.comboBox_SizeMode.Text) {case "default (original Size)": This.pictureBox_Camera.SizeMode =
Pictureboxsizemode.normal;
Break
Case "centered (original size)": This.pictureBox_Camera.SizeMode = pictureboxsizemode.centerimage;
Break
Case "padding (stretched image)": This.pictureBox_Camera.SizeMode = pictureboxsizemode.stretchimage;
Break
Case "fill (Maintain proportion)": This.pictureBox_Camera.SizeMode = pictureboxsizemode.zoom;
Break }
}
Save photo private void Buttonsave_click (object sender, EventArgs e) {try {string filename = Path.Combine (application.start Uppath, "Stuimages", "newstuimages", This.xh + ".
JPG "); if (!this.checkbox1.checked && file.exists (filename)) {If MessageBox.Show ("The student already has a photo file, is it overwritten?", "", Messageboxbuttons.okcancel, messageboxicon.warning) = = DialogResult.OK) {//stored to local THIS.PICTUREBOX_TX.
Image.Save (filename); Ondatachanged (This, new Dataeventargs (string. Format ("Avatar Collection (overlay), student number: {0}, Name: {1}, candidate number: {2}, ID number: {3}", This.xh, this. XM, this. KSH, this.
SFZH)));
This.txtKSH.Focus ();
This.txtKSH.SelectAll ();
else {return;}} else {This.picturebox_tx.
Image.Save (filename); Ondatachanged (This, new Dataeventargs (string. Format ("Avatar Collection, student number: {0}, Name: {1}, examinee number: {2}, ID number: {3}", This.xh, this. XM, this. KSH, this.
SFZH)));
This.txtKSH.Focus ();
This.txtKSH.SelectAll ();
} this.timer1.Start (); The catch {} finally {//enable the following line, click Save after the Avatar will immediately start refreshing//this.timer1.start (); this.btnSave.Enabled = false;}}

Save a photo to automatically overwrite the same name or add a watermark effect to the photo.

You can drag a rectangular box to choose a picture when you operate

The above is a small set of C # to introduce the implementation of mobile phone photos and save watermark Photos, I hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.