这是程序:
public void takefromsaved(IntPtr pData)
{
unsafe
{
byte* pFirstAdd = (byte*)pData;
byte* pLine = pFirstAdd;
int numb = 0;
int maxnumb = actual_w * actual_h;
picturedata=new int[maxnumb];
double frame;
while (numb < maxnumb)
{
frame = *(pLine + 3 * numb) * 0.299 + *(pLine + 3 * numb + 1) * 0.587 + *(pLine + 3 * numb + 2) * 0.114;
picturedata[numb] = (int)frame;
numb++;
using (StreamWriter objFiledata = new StreamWriter(@"e:\DataSaved.doc"))
{
objFiledata.Write(Convert.ToString(frame));
}
}
}
public void SnapPicAndSave()
{
Rectangle rect = new Rectangle(0, 0, width, height);
Bitmap dstBitmap = CreateGrayscaleImage(width, height);//这个函数在后面有定义
BitmapData dstBmData = dstBitmap.LockBits(rect,
ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
System.IntPtr dstPtr = dstBmData.Scan0;
int dst_bytes = dstBmData.Stride * height;
byte[] dstValues = new byte[dst_bytes];
System.Runtime.InteropServices.Marshal.Copy(dstPtr, dstValues, 0, dst_bytes);
int numb = 0;
string strAlbumName;
for (int i = height - 1; i >= 0; i--)
for (int j = 0; j < width; j++)
{
dstValues[i * dstBmData.Stride + j] = (byte)m_takegray.picturedata[numb];
strAlbumName = Convert.ToString(m_takegray.picturedata[numb]);
numb++;
}
System.Runtime.InteropServices.Marshal.Copy(dstValues, 0, dstPtr, dst_bytes);
dstBitmap.UnlockBits(dstBmData);
pictureshowBox.Image = dstBitmap;
}
慕桂英4014372
青春有我
慕莱坞森
相关分类