shytonak
سه شنبه 06 مرداد 1388, 14:45 عصر
سلام دوستان من می خواستم برنامه بیاد تصور مانیتور رو سیاه و سفید کنه و تا ئقتی که برنامه نخواسته تصویر درست نشه.
Reza_Yarahmadi
سه شنبه 06 مرداد 1388, 19:18 عصر
سیاه و سفید کردن عکس با کد نویسی
توسط متد زیر می توانید هر عکسی را به حالت سیاه و سفید یا همون grayScale در بیارین
public Image GrayScaleImage(Graphics graph, Image img, int left, int top)
{
ColorMatrix colorMix = new ColorMatrix();
colorMix.Matrix00 = 1 / 3f;
colorMix.Matrix01 = 1 / 3f;
colorMix.Matrix02 = 1 / 3f;
colorMix.Matrix10 = 1 / 3f;
colorMix.Matrix11 = 1 / 3f;
colorMix.Matrix12 = 1 / 3f;
colorMix.Matrix20 = 1 / 3f;
colorMix.Matrix21 = 1 / 3f;
colorMix.Matrix22 = 1 / 3f;
ImageAttributes imgAttrib = new ImageAttributes();
imgAttrib.SetColorMatrix(colorMix);
graph.DrawImage(img, new Rectangle(left, top, img.Width,
img.Height), 0, 0, img.Width, img.Height,
GraphicsUnit.Pixel, imgAttrib);
Bitmap bmp = new Bitmap(img);
return bmp;
}
عملکر متد خیلی واضحه.
شما میتونید اول از صفحه عکس بگیرید و بعد توسط این متد عکستون رو سیاه و سفید کنید.
کد عکس گرفتن از صفحه:
private Image CaptureScreen()
{
Bitmap screen = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height);
using (Graphics g = Graphics.FromImage(screen))
{
g.CopyFromScreen(0, 0, 0, 0, screen.Size);
}
return screen;
}
اگر هم قصد دارد این عکس به عنوان BackGround بذارید میتونید از کد زیر استفاده کنید:
using System.Runtime.InteropServices;
using System.Drawing;
using Microsoft.Win32;
public class Wallpaper
{
const int SPI_SETDESKWALLPAPER = 20;
const int SPIF_UPDATEINIFILE = 0x01;
const int SPIF_SENDWININICHANGE = 0x02;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int SystemParametersInfo(
int uAction, int uParam, string lpvParam, int fuWinIni);
public enum Style : int
{
Tiled, Centered, Stretched
}
public void SetWallpaper(string path, Style style)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(
"Control Panel\\Desktop", true);
switch( style )
{
case Style.Stretched :
key.SetValue(@"WallpaperStyle", "2") ;
key.SetValue(@"TileWallpaper", "0") ;
break;
case Style.Centered :
key.SetValue(@"WallpaperStyle", "1") ;
key.SetValue(@"TileWallpaper", "0") ;
break;
case Style.Tiled :
key.SetValue(@"WallpaperStyle", "1") ;
key.SetValue(@"TileWallpaper", "1") ;
break;
}
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, path,
SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
}
}
نحوه ی استفاده :
private void setButton_Click(object sender, EventArgs e)
{
Wallpaper w = new Wallpaper();
w.SetWallpaper(fileName,
(Wallpaper.Style)Enum.Parse(typeof(Wallpaper.Style ), "Tiled"));
}
امیدوارم به دردتون خورده باشه.
(تمام کدها رو از همین سایت گرفتم!)
shytonak
سه شنبه 06 مرداد 1388, 20:37 عصر
دوست من ، من می خوام مانیتور سیاه سفید نشون بده.
vBulletin® v4.2.5, Copyright ©2000-1403, Jelsoft Enterprises Ltd.