PDA

View Full Version : کار با BitBlt از توابع API



3Dmajid
یک شنبه 24 فروردین 1393, 13:49 عصر
سلام دوستان.
من دارم در زمینه ی توابع api تحقیق میکنم.
اگه کسی در مورد تابع bitblt آطلاعاتی داره ممنون میشم در اختیارم بزاره.
این تابع از زیر مجموعه های gdi32.dll هست.
خودم تقریبا فهمیدم چی کار میکنه ولی بلد نیستم ازش استفاده کنم.
اگه ممکنه یه مثالی چیزی برام بزنید که چه جوری میتونم از تابع ش استفاده کنم.
ممنون میشم کمک کنید.:لبخند::قلب:

hamid_hr
یک شنبه 24 فروردین 1393, 14:03 عصر
http://www.java2s.com/Code/CSharp/Windows/BitBlt.htm

3Dmajid
یک شنبه 24 فروردین 1393, 14:23 عصر
نفهمیدم چی شد ... این که مثال نیس کداش کار نمیکنه :قلب:

behzadkhan
یک شنبه 24 فروردین 1393, 15:20 عصر
با سلام

از http://stackoverflow.com/questions/16920622/c-sharp-gdi32-bitblt-seems-to-do-nothing پیدا کردم:

====================================


private const int SRCCOPY = 0xCC0020;


[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern int BitBlt(
IntPtr hdcDest, // handle to destination DC (device context)
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
int dwRop // raster operation code
);


[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);


[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
public static extern IntPtr SelectObject(IntPtr hdc, IntPtr obj);


[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
public static extern void DeleteObject(IntPtr obj);


private void button1_Click(object sender, EventArgs e)
{
Bitmap sourceBitmap = new Bitmap(64, 64, PixelFormat.Format32bppRgb);
Graphics sourceGraphics = Graphics.FromImage(sourceBitmap);


Bitmap destBitmap = new Bitmap(64, 64, PixelFormat.Format32bppRgb);
Graphics destGraphics = Graphics.FromImage(destBitmap);


sourceGraphics.FillRectangle(new SolidBrush(Color.Red), new Rectangle(0, 0, 30, 30));
sourceGraphics.FillRectangle(new SolidBrush(Color.Green), new Rectangle(30, 30, 30, 30));


destGraphics.FillRectangle(new SolidBrush(Color.Blue), new Rectangle(0, 0, 30, 30));
destGraphics.FillRectangle(new SolidBrush(Color.Yellow), new Rectangle(30, 30, 30, 30));


IntPtr destDC = destGraphics.GetHdc();
IntPtr destCDC = CreateCompatibleDC(destDC);
IntPtr destHB = destBitmap.GetHbitmap();
IntPtr oldDest = SelectObject(destCDC, destHB);


IntPtr sourceDC = sourceGraphics.GetHdc();
IntPtr sourceCDC = CreateCompatibleDC(sourceDC);
IntPtr sourceHB = sourceBitmap.GetHbitmap();
IntPtr oldSource = SelectObject(sourceCDC, sourceHB);


int success = BitBlt(
destDC, 0, 0, 64, 64, sourceCDC, 0, 0, SRCCOPY
);


SelectObject(destCDC, oldDest);
SelectObject(sourceCDC, oldSource);


DeleteObject(destCDC);
DeleteObject(sourceCDC);


DeleteObject(destHB);
DeleteObject(sourceHB);


destGraphics.ReleaseHdc();
sourceGraphics.ReleaseHdc();


pictureBox1.Image = sourceBitmap;
pictureBox2.Image = destBitmap;
}





تست هم شد.

با تشکر

3Dmajid
شنبه 30 فروردین 1393, 18:57 عصر
داداش دمت گرم ... ولی این یه نمه پیچیده س و از توابع دیگه ای غیر از bitblt هم استفاده کرده.
مثالی نداری که فقط از bitblt استفاده کنه ؟
زیاد سر در نیوردم ازش.

forodo
شنبه 30 فروردین 1393, 23:06 عصر
سلام
کار این تابع چی هست؟