PDA

View Full Version : عکسبرداری از صفحه



Mahtab_Tarsa
یک شنبه 10 شهریور 1392, 23:21 عصر
سلام خدمت دوستان عزیز
یه کمکی میخواستم در مورد این چند خط کد که چطور میشه طوری تغییرش دا که بعد از عکسبرداری و ذخیره با همون شمارنده که به ترتیب از صفر شروع میشه با شماره و بعد از آن با تاریخ و زمان جاری سیستم ذخیره بشه یعنی اول شماره عکس و بعد خط تیره تاریخ و زمان به این صورت در دایرکتوری ذخیره بشه من با چند مدل تست کردم ارور داد و اجرا نشد
bmpScreenShot = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb)
gfxScreenshot = Graphics.FromImage(bmpScreenShot)
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen. Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy)
PictureBox1.Image = bmpScreenShot
bmpScreenShot.Save(System.IO.Path.GetDirectoryName (Application.ExecutablePath) & "\pic\" & i & ".jpg", ImageFormat.Jpeg)

amir200h
یک شنبه 10 شهریور 1392, 23:28 عصر
bmpScreenShot = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb)
gfxScreenshot = Graphics.FromImage(bmpScreenShot)
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen. Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy)
PictureBox1.Image = bmpScreenShot
bmpScreenShot.Save(System.IO.Path.GetDirectoryName (Application.ExecutablePath) & "\pic\" & i & "+ DateTime.Now.ToShortDateString()+DateTime.Now.ToSh ortTimeString()".jpg", ImageFormat.Jpeg)

Mahtab_Tarsa
دوشنبه 11 شهریور 1392, 08:20 صبح
bmpScreenShot = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb)
gfxScreenshot = Graphics.FromImage(bmpScreenShot)
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen. Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy)
PictureBox1.Image = bmpScreenShot
bmpScreenShot.Save(System.IO.Path.GetDirectoryName (Application.ExecutablePath) & "\pic\" & i & "+ DateTime.Now.ToShortDateString()+DateTime.Now.ToSh ortTimeString()".jpg", ImageFormat.Jpeg)

سلام مهندس گرامی قابل اجرا نیست ارور میده

hamid_0341
سه شنبه 12 شهریور 1392, 06:40 صبح
از Using system.IO استفاده کن بیبین درست میشه

Mahtab_Tarsa
جمعه 15 شهریور 1392, 21:17 عصر
از Using system.IO استفاده کن بیبین درست میشه
میشه منظورتونو واضح تر بفرمائید.

mohsenasm
یک شنبه 17 شهریور 1392, 12:13 عصر
با سلام
این رو هم چک کنین
باید قبل از namespace از اینها:


using System;
using System.IO;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
و در جایی مثل رویداد کلیک روی دکمه از اینها استفاده کنید:

string s;
int i =1;
Bitmap bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(bmpScreenshot);
g.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size);
s = System.IO.Path.GetDirectoryName(Application.Execut ablePath) + char.ConvertFromUtf32(92) + "pic" + char.ConvertFromUtf32(92) + i.ToString() + "_" + DateTime.Now.ToShortDateString().Replace("/" , "#" ) + "_" + DateTime.Now.ToShortTimeString().Replace(":" , "~" ) + ".jpg" ;
bmpScreenshot.Save( s , ImageFormat.Jpeg ) ;
//i++;
//g.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size);
//s = System.IO.Path.GetDirectoryName(Application.Execut ablePath) + char.ConvertFromUtf32(92) + "pic" + char.ConvertFromUtf32(92) + i.ToString() + "_" + DateTime.Now.ToShortDateString().Replace("/" , "#" ) + "_" + DateTime.Now.ToShortTimeString().Replace(":" , "~" ) + ".jpg" ;
//bmpScreenshot.Save( s , ImageFormat.Jpeg ) ;
توضیح این که نباید از کاراکتر های غیر مجاز : و / در نام فایل استفاده کرد همچنین به جای استفاده مستقیم از \ از کد اسکی 92 استفاده شده است.
به جای jpg از bmp و png و gif نیز می توان استفاده کرد.