c# - How can i add optional directory for bmp.screenshotsave -
i need please. want implement ability choose folder before saving screenshots. working code have created:
bmpscreenshot.save("c:\\test\\pictures\\scr_(" + pict_no + ").jpeg", imageformat.jpeg); pict_no++;
it autoscreenshoter increments number of screenshot. folder constant. want create selection of folder before capturing auto screenshot. used this:
public partial class form1 : form { public form1() { initializecomponent(); } public void tick(object stateinfo) { string s; s = textbox3.text+ "\\scr_(" + pict_no + ").jpeg"; // set bitmap object size of screen bmpscreenshot = new bitmap(screen.primaryscreen.bounds.width, screen.primaryscreen.bounds.height, pixelformat.format32bppargb); // create graphics object bitmap gfxscreenshot = graphics.fromimage(bmpscreenshot); // take screenshot upper left corner right bottom corner gfxscreenshot.copyfromscreen(screen.primaryscreen.bounds.x, screen.primaryscreen.bounds.y, 0, 0, screen.primaryscreen.bounds.size, copypixeloperation.sourcecopy); // save screenshot specified path user has chosen bmpscreenshot.save(s, imageformat.jpeg); pict_no++; } private void button1_click(object sender, eventargs e) { messagebox.show("printscreenování právě začalo bude probíhat po " +textbox1.text+ " sekundách.\npřeji příjemný den :d"); cas(); } private void textbox1_textchanged(object sender, eventargs e) { int aninteger; aninteger = convert.toint32(textbox1.text); aninteger = int.parse(textbox1.text); } public void cas() { int aninteger; aninteger = convert.toint32(textbox1.text); aninteger = int.parse(textbox1.text); timercallback callback = new timercallback(tick); // create timer tick system.threading.timer statetimer = new system.threading.timer(callback, null, 0, aninteger*1000); // loop here forever (; ; ) { int eninteger; eninteger = convert.toint32(textbox2.text); eninteger = int.parse(textbox2.text); if (pict_no == eninteger) environment.failfast("konec programu."); } } public void choosefolder() { if (folderbrowserdialog1.showdialog() == dialogresult.ok) { textbox3.text = folderbrowserdialog1.selectedpath; } } public static bitmap bmpscreenshot { get; set; } public static graphics gfxscreenshot { get; set; } public static int pict_no { get; set; } private void textbox2_textchanged(object sender, eventargs e) { } private void textbox3_textchanged(object sender, eventargs e) { } private void button2_click(object sender, eventargs e) { choosefolder(); } }
i don't know why doesn't work.
you can invoke
methods in main thread can access gui tick
event.
in tick event:
this.invoke(new methodinvoker(delegate { this.proceed(); }), null);
then can put want in proceed()
method.
private void proceed() { string s; s = textbox3.text+ "\\scr_(" + pict_no + ").jpeg"; // set bitmap object size of screen bmpscreenshot = new bitmap(screen.primaryscreen.bounds.width, screen.primaryscreen.bounds.height, pixelformat.format32bppargb); // create graphics object bitmap gfxscreenshot = graphics.fromimage(bmpscreenshot); // take screenshot upper left corner right bottom corner gfxscreenshot.copyfromscreen(screen.primaryscreen.bounds.x, screen.primaryscreen.bounds.y, 0, 0, screen.primaryscreen.bounds.size, copypixeloperation.sourcecopy); // save screenshot specified path user has chosen bmpscreenshot.save(s, imageformat.jpeg); pict_no++; }
Comments
Post a Comment