Hi i try to use some code in my project , a error rise to syntax and i dont know what is it . error come from the tag started with "unsafe" .
What is unsafe and Where and Why Should Use It ? tnx friends...
the code is here :
public Bitmap Cursor(ref int cursorX, ref int cursorY)
{
int screenWidth = 1;
int screenHeight = 1;
lock (_newBitmap)
{
try
{
screenWidth = _newBitmap.Width;
screenHeight = _newBitmap.Height;
}
catch (Exception)
{
...
}
}
if (screenWidth == 1 && screenHeight == 1)
{
return null;
}
Bitmap img = CaptureScreen.CaptureCursor(ref cursorX, ref cursorY);
if (img != null && cursorX < screenWidth && cursorY < screenHeight)
{
int width = img.Width;
int height = img.Height;
BitmapData imgData = img.LockBits(
new Rectangle(0, 0, width, height),
ImageLockMode.ReadOnly, img.PixelFormat);
const int numBytesPerPixel = 4;
int stride = imgData.Stride;
IntPtr scan0 = imgData.Scan0;
unsafe // ERROR IN THIS LINE
// IF i move unsafe to method header (unsafe public .... ) i get some another errors
{
byte* pByte = (byte*)(void*)scan0;
for (int h = 0; h < height; h++)
{
for (int w = 0; w < width; w++)
{
int offset = h * stride + w * numBytesPerPixel + 3;
if (*(pByte + offset) == 0)
{
*(pByte + offset) = 60;
}
}
}
}
img.UnlockBits(imgData);
return img;
}
return null;
}