memorystream写入字节数组有问题

 FileStream fs = new FileStream("f://电子书//图片//1.jpg", FileMode.Open, FileAccess.Read);
        byte[] MyBinData = new byte[fs.Length];
        fs.Read(MyBinData, 0, System.Convert.ToInt32(fs.Length));

        mage.content.Write(MyBinData, 0, System.Convert.ToInt32(fs.Length));

        byte[] MyBinData1 = new byte[fs.Length];
        mage.content.Read(MyBinData1, 0, (int)fs.Length);

        FileStream fw = new FileStream("d://3.jpg",FileMode.Create);
        fw.Write(MyBinData1, 0, System.Convert.ToInt32(MyBinData1.Length));
        fw.Close();

 

                       filelen = m_Reader.GetInt32(6);
                        byte[] content1 = new byte[filelen];
                        m_Reader.GetBytes(5, 0, content1, 0, System.Convert.ToInt32(filelen));
                        content = content1; 

阅读更多
换一批

memorystream写入内存提示内存不足

10-10

private Bitmap CreateBitmap(byte[] originalImageData, int originalWidth, int originalHeight)rn rn //指定8位格式,即256色.oldrn //指定32位格式rn Bitmap resultBitmap = new Bitmap(originalWidth, originalHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb);rn tryrn rn //将该位图存入内存中rn MemoryStream curImageStream = new MemoryStream();rn resultBitmap.Save(curImageStream, System.Drawing.Imaging.ImageFormat.Bmp);rn curImageStream.Flush();rnrn //由于位图数据需要DWORD对齐(4byte倍数),计算需要补位的个数rn //int curPadNum = ((originalWidth * 8 + 31) / 32 * 4) - originalWidth;rn int curPadNum = ((originalWidth * 24 + 31) / 32 * 4) - originalWidth;rnrn //最终生成的位图数据大小rn //int bitmapDataSize = ((originalWidth * 8 + 31) / 32 * 4) * originalHeight;rn int bitmapDataSize = ((originalWidth * 24 + 31) / 32 * 4) * originalHeight;rn //bitmapDataSize = originalWidth * originalHeight;rn //数据部分相对文件开始偏移,具体可以参考位图文件格式rn int dataOffset = ReadData(curImageStream, 10, 4);rnrnrn //改变调色板,因为默认的调色板是32位彩色的,需要修改为256色的调色板rn int paletteStart = 54;rn int paletteEnd = dataOffset;rn //int color = 0;rnrn //RPG24,不需要调色板rn //for (int i = paletteStart; i < paletteEnd; i += 4)rn //rn // byte[] tempColor = new byte[4];rn // tempColor[0] = (byte)color;rn // tempColor[1] = (byte)color;rn // tempColor[2] = (byte)color;rn // tempColor[3] = (byte)0;rn // color++;rnrn // curImageStream.Position = i;rn // curImageStream.Write(tempColor, 0, 4);rn //rn curImageStream.Position = paletteStart;rnrn //最终生成的位图数据,以及大小,高度没有变,宽度需要调整rn byte[] destImageData = new byte[bitmapDataSize];rn int destWidth = originalWidth + curPadNum;rnrn //生成最终的位图数据,注意的是,位图数据 从左到右,从下到上,所以需要颠倒rn for (int originalRowIndex = originalHeight - 1; originalRowIndex >= 0; originalRowIndex--)rn rn int destRowIndex = originalHeight - originalRowIndex - 1;rnrn for (int dataIndex = 0; dataIndex < originalWidth * 3; dataIndex += 3)rn rn //同时还要注意,新的位图数据的宽度已经变化destWidth,否则会产生错位rn destImageData[destRowIndex * destWidth + dataIndex] = originalImageData[originalRowIndex * originalWidth * 3 + dataIndex];rn destImageData[destRowIndex * destWidth + dataIndex + 1] = originalImageData[originalRowIndex * originalWidth * 3 + dataIndex + 1];rn destImageData[destRowIndex * destWidth + dataIndex + 2] = originalImageData[originalRowIndex * originalWidth * 3 + dataIndex + 2];rn rn rnrnrn //将流的Position移到数据段 rn curImageStream.Position = dataOffset;rnrn //将新位图数据写入内存中rn curImageStream.Write(destImageData, 0, bitmapDataSize);rnrn curImageStream.Flush();rnrn //将内存中的位图写入Bitmap对象rn resultBitmap = new Bitmap(curImageStream);rnrn return resultBitmap;rn rn catch (System.Exception ex)rn rn XMLWriter.AddErrorRecord("Collections:CreateBitmap", ex);rn return resultBitmap;rn rnrn rnrnrn关联这个函数函数rnpublic void SetParameters(IntPtr pbuffData)rn rn if (pbuffData == null)rn rn return;rn rn tryrn rn System.Runtime.InteropServices.Marshal.Copy(pbuffData, bmpData_ori, 0, bmpData_ori.Length);rnrn Yuv2ToRgb(bmpData_ori, bBmp, m_Width, m_Height);rn bmCam = CreateBitmap(bBmp, m_Width, m_Height);rn bmShow = KiRotate(bmCam, 90, Color.Transparent);rn //if (CheckUserStat())rn //rn // ClearPic();rn // return;rn //rn picVido.Image = bmShow;rnrn // 采集部分rn if (bIsCam && nCamNum < m_MaxCam)rn rn faceBMPFile = new Bitmap(128, 128, System.Drawing.Imaging.PixelFormat.Format24bppRgb);rn faceImage = new Emgu.CV.Image(bmCam);rn smallFaecImage[nCamNum] = new Emgu.CV.Image(faceBMPFile);rn int isFace = HJFace.FaceLocated(faceImage.Ptr, smallFaecImage[nCamNum].Ptr, pfeaturetemp[nCamNum], nCamWay - 1, 0);rn //int isFace = HJFace.FaceLocated(faceImage.Ptr, smallFaecImage[nCamNum].Ptr, pfeaturetemp[nCamNum], nCamWay - 1);rnrn // 是人脸rn if (isFace == 0)rn rn faceBMPFile = IplImagePointerToBitmap(smallFaecImage[nCamNum].Ptr);rn ((PictureBox)picFaecArr.GetValue(nCamNum)).Image = faceBMPFile;rn m_imageArr[nCamNum] = bmShow;rn nCamNum++;rn rn // 暂停采集rn if (nCamNum == 10 && m_MaxCam == 10)rn rn bIsCam = false;rn //MessageBox.Show("已经采集10张照片,暂停采集", "提示");rn rn m_bImage = false;rn Form1 frm = new Form1();rn frm.ShowDialog();rn frm.Focus();rn if(btnStart.Text == "暂停采集")rn rn btnStart.Enabled = true;rn btnStart.Text = "继续采集";rn rn if(btnStartRec.Text == "暂停采集")rn rn btnStartRec.Enabled = true;rn btnStartRec.Text = "继续采集";rn rn rn // 完成采集rn if (nCamNum == 20)rn rn bIsCam = false;rn m_bImage = true;rn //if (CheckUserStat())rn // return;rnrn HJSpeakEngine hjse = new HJSpeakEngine();rn hjse.PlayNeoSPEECH("采集完毕");rn //if (CheckUserStat())rn // return;rnrn //MessageBox.Show("已经采集20张照片,点击人脸照片选择10张模版", "提示");rnrn rn Form1 frm = new Form1();rn frm.ShowDialog();rn frm.Focus();rnrn m_bIsCheck = true;rn btnReCam.Enabled = true;rn rn rn rn catch (System.Exception ex)rn rn XMLWriter.AddErrorRecord("Collections:SetParameters", ex);rn rn rn rn开始存没问题,后来就会提示内存不足

没有更多推荐了,返回首页