PDA

View Full Version : سوال: معادل دستور setpixel سی در سی شارپ



fdaliry
دوشنبه 11 خرداد 1388, 15:17 عصر
سلام دوستان
میخاستم بیبنم معادل دستوری که ی پیکسل خاص را روشن میکنه در سی شارپ چیه
اصلا میشه رو فرم ی پیکسل خاص را روشن کرد یا نه

kiosksoft
دوشنبه 11 خرداد 1388, 18:23 عصر
دوست عزیز

منظورتون همین کد هست :




using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
[DllImport( "user32.dll" )]
static extern IntPtr GetDC( IntPtr hWnd );
[DllImport( "user32.dll" )]
static extern int ReleaseDC( IntPtr hWnd, IntPtr hDC );
[DllImport( "gdi32.dll" )]
static extern int GetPixel( IntPtr hDC, int x, int y );
[DllImport( "gdi32.dll" )]
static extern int SetPixel( IntPtr hDC, int x, int y, int color );
static public Color GetPixel( Control control, int x, int y )
{
Color color = Color.Empty;
if (control != null)
{
IntPtr hDC = GetDC( control.Handle );
int colorRef = GetPixel( hDC, x, y );
color = Color.FromArgb(
(int)(colorRef & 0x000000FF),
(int)(colorRef & 0x0000FF00) >> 8,
(int)(colorRef & 0x00FF0000) >> 16 );
ReleaseDC( control.Handle, hDC );
}
return color;
}
static public void SetPixel( Control control, int x, int y, Color color )
{
if (control != null)
{
IntPtr hDC = GetDC( control.Handle );
int argb = color.ToArgb();
int colorRef =
(int)((argb & 0x00FF0000) >> 16) |
(int)(argb & 0x0000FF00) |
(int)((argb & 0x000000FF) << 16);
SetPixel( hDC, x, y, colorRef );
ReleaseDC( control.Handle, hDC );
}
}

fdaliry
دوشنبه 11 خرداد 1388, 20:01 عصر
حقیقتش من از کد بالا هیچی سر در نیاوردم
الگوریتم DDA و ترسیم دایره و چند الگوریتم دیگه را به زبان سی دارم
میخام به سی شارپ تبدبیل کنم ولی نمیدونم بجای دستور setpixel که تو سی هست از چه دستوری در سی شارپ استفاده کنم
ممنون از لطف شما

Sajjad.Aghapour
سه شنبه 12 خرداد 1388, 13:53 عصر
یه خورده تو فضای نام System.Drawing بگردید خیلی چیزا پیدا می کنید.....


Bitmap bmp=new Bitmap(10,10);

bmp.SetPixel()
bmp.GetPixel()

Graphics g=anyControl.CreateGraphics();
g.DrawEllips()
.
.
.


از همون gdi هم که دوستمون کدش رو دادن می تونید استفاده کنید.....

fdaliry
یک شنبه 17 خرداد 1388, 13:03 عصر
ممنون از جوابتون


من کد زیر را برای ترسیم ی خط تو فرم نوشتم ولی اجرا نمیشه



نمیدونم ایرادش کجاست







int k;
int x = 60;
int y = 20;
for(k=0;k<40;k++)
{
Bitmap bmp=new Bitmap(x,y);
bmp.SetPixel();
bmp.GetPixel();
x++;
}

Sajjad.Aghapour
یک شنبه 17 خرداد 1388, 14:37 عصر
این دو روش برای رسم خط در فرم....


Graphics g = this.CreateGraphics();
g.DrawLine(Pens.Black, 10, 10, 500, 500);

2.


int y = 10;
Bitmap bmp = new Bitmap(600,600);
for (int x = 10; x < 500; x++)
{
bmp.SetPixel(x, y, Color.Black);
y++;
}
this.BackgroundImage = bmp;

fdaliry
یک شنبه 17 خرداد 1388, 16:22 عصر
این دو روش برای رسم خط در فرم....


Graphics g = this.CreateGraphics();
g.DrawLine(Pens.Black, 10, 10, 500, 500);
2.


int y = 10;
Bitmap bmp = new Bitmap(600,600);
for (int x = 10; x < 500; x++)
{
bmp.SetPixel(x, y, Color.Black);
y++;
}
this.BackgroundImage = bmp;



زنده باد
درست کار میکنه
ممنون