当前位置:网站首页>Copy image bitmap by C # memory method
Copy image bitmap by C # memory method
2022-06-23 07:59:00 【pcjiushizhu】
/**
* Memory method to copy pictures
* */
private void copyBitmap(Bitmap bmpSrc, Bitmap bmpDest)
{
int w = bmpSrc.Width, h = bmpSrc.Height;
PixelFormat format = bmpSrc.PixelFormat;
// Lock the bitmap's bits. Lock bitmap
Rectangle rect = new Rectangle(0, 0, w, h);
BitmapData bmpDataSrc =
bmpSrc.LockBits(rect, ImageLockMode.ReadOnly,
format);
// Get the address of the first line. Get the first line address
IntPtr ptrSrc = bmpDataSrc.Scan0;
BitmapData bmpDataDest =
bmpDest.LockBits(rect, ImageLockMode.WriteOnly,
format);
IntPtr ptrDest = bmpDataDest.Scan0;
// Declare an array to hold the bytes of the bitmap. Define an array to hold bitmaps
int bytes = Math.Abs(bmpDataSrc.Stride) * h;
byte[] rgbValues = new byte[bytes];
// Copy the RGB values into the array. Copy RGB Value to array
System.Runtime.InteropServices.Marshal.Copy(ptrSrc, rgbValues, 0, bytes);
// Copy to new diagram
System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptrDest, bytes);
// Unlock the bits. Unlock
bmpSrc.UnlockBits(bmpDataSrc);
bmpDest.UnlockBits(bmpDataDest);
}
// Pay attention to bmpSRC.Dispose();
边栏推荐
猜你喜欢
随机推荐
C# scrollView 向上滚动还是向下滚动
Create an orderly sequence table and perform the following operations: 1 Insert element x into the table and keep it in order; 2. find the element with the value of X, and delete it if found; 3. outpu
Distributed ID generation
如何在conda虚拟环境开启jupyter-notebook
快速排序 + 冒泡排序 + 插入排序 + 選擇排序
Unity to wechat applet games
openvino系列 18. 通过OpenVINO和OpenCV实现实时的物体识别(RTSP,USB视频读取以及视频文件读取)
Socket programming -- select model
配置ASMX无法访问
SQL注入常用到的绕过方式-ctf
1278_ FreeRTOS_ Understand the delayed task with the prvaddcurrenttasktodelayedlist interface
vtk. JS left mouse button sliding to change window level and window width
QT reading XML files using qdomdocument
Hcip Road
1278_FreeRTOS_借助prvAddCurrentTaskToDelayedList接口理解delayed task
Quickly delete the node in the code_ modules
Talk about routing design in service governance
带你玩tiktok就这么简单
YGG Spain subdao Ola GG officially established
Socket programming (multi process)







