这是程序: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;}
3 回答
慕桂英4014372
TA贡献1871条经验 获得超13个赞
using (StreamWriter objFiledata = new StreamWriter(@"e:\DataSaved.doc"))
{
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++;
objFiledata.Write(Convert.ToString(frame));
}
}
建议你这样把while放里面去试试。
青春有我
TA贡献1784条经验 获得超8个赞
像这种问题,一般就是对文件记性操作的时候,由于没有close就会产生这种错误,你看看你别的代码里有没有操作文件的代码,例如打开,创建之类的,有的话要注意close,否则就会出现这情况
- 3 回答
- 0 关注
- 118 浏览
添加回答
举报
0/150
提交
取消