這是程序: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 關注
- 180 瀏覽
添加回答
舉報
0/150
提交
取消