Beispiel #1
0
        private static int SaveToSmallPict(string sSmallPictFileName, Gen2_Struct ThisGen2, ref string sErrString)
        {
            int iResult = MyData.iErr_UnknowErr;

            sErrString = "";
            try
            {
                // if File exist,delete it.
                if (File.Exists(sSmallPictFileName))
                {
                    File.Delete(sSmallPictFileName);
                }

                // Create Big Picture
                mod_ShowPict PB = new mod_ShowPict();
                PB.pGen2          = ThisGen2;
                PB.DisplayMode    = MyData.DisplayMode_Yello;
                PB.PictBrightness = 0;
                PB.PictContract   = 0;

                PictureBox pbox = new PictureBox();
                pbox.Width  = 700;
                pbox.Height = 700;
                PB.Gen2ToData();
                PB.Gen2ToPict();

                // 缩小保存
                Image    img    = PB.BM;
                int      width  = 60;
                Image    newImg = new Bitmap(width, img.Height * width / img.Width);
                Graphics g      = Graphics.FromImage(newImg);
                g.DrawImage(img, 0, 0, width, img.Height * width / img.Width);
                newImg.Save(sSmallPictFileName);
                iResult    = MyData.iErr_Succ;
                sErrString = "";
            }
            catch (Exception ex)
            {
                iResult    = MyData.iErr_Exception;
                sErrString = "生成索引图时出现意外错误:" + ex.Message;
            }

            return(iResult);
        }
Beispiel #2
0
        public bool ReadAllFramDataFromFile(ref byte[] AllFrameInfo, ref byte[] AllRaw, ref double[,] BeltData, double Angle0, UserControl_ReadFileBar RBar, ref string sErrString)
        {
            bool bResult = false;

            sErrString = "";
            double dBarStep = RBar.iBarValue;

            if (ggData.m_szFileName == "")   // 还没关联gg文件
            {
                sErrString = "尚未打开相关文件。";
                return(bResult);
            }

            if (ggData.numberof_frames <= 0)
            {
                AllRaw   = null;       // 没有数据
                BeltData = null;
                return(bResult);
            }

            dBarStep      += 5.0;
            RBar.iBarValue = (int)(dBarStep);
            MyTools.DoEvents();

            double Angle = 2 * PI_360 * Angle0 / 360;

            BeltData = null;
            IntPtr buffer = Marshal.AllocHGlobal(1);

            try
            {
                int iFrameInfoSize = Marshal.SizeOf(typeof(ggFrame_struct));

                AllFrameInfo = new byte[ggData.numberof_frames * iFrameInfoSize];
                mod_ReadGen2.Gen2_Struct Gen2Current = new mod_ReadGen2.Gen2_Struct();
                //Gen2Array = new mod_ReadGen2.Gen2_Struct[ggData.numberof_frames];
                mod_ShowPict PB = new mod_ShowPict();

                byte[] FirstLine  = new byte[ggData.numberof_frames * ggData.numberofpointofline * 2];
                byte[] SecondLine = new byte[ggData.numberof_frames * ggData.numberofpointofline * 2];

                int iFirstLine = 0, iSeconLine = 0;   // 取出第几线
                iFirstLine = (int)((ggData.numberofline / (PI_360 * 2)) * (Angle + ggData.Angle2));
                if (iFirstLine > ggData.numberofline)
                {
                    iFirstLine -= ggData.numberofline;
                }

                iSeconLine = iFirstLine + ggData.numberofline / 2;
                if (iSeconLine > ggData.numberofline)
                {
                    iSeconLine -= ggData.numberofline;
                }

                for (int i = 0; i < ggData.numberof_frames; i++)
                {
                    if (ggFileMoveToFrame("Goto", i, ref sErrString))
                    {
                        // 计算从第几帧取数据

                        if (ReadRawFrameDataFromFile(ref ggData.m_ggframe_info, ref ggData.m_lprawdata, ref ggData.m_lpimagedata, ref sErrString))
                        {
                            if (i == 0)
                            {
                                ggData.m_sizeofrawdata = ggData.m_ggframe_info.rawdatasize;
                                AllRaw = new byte[ggData.numberof_frames * ggData.m_sizeofrawdata];
                            }

                            Marshal.FreeHGlobal(buffer);                          // 释放以前分配的空间
                            buffer = Marshal.AllocHGlobal(iFrameInfoSize);        // 重新分配
                            Marshal.StructureToPtr((ggFrame_struct)ggData.m_ggframe_info, buffer, false);
                            Marshal.Copy(buffer, AllFrameInfo, i * iFrameInfoSize, iFrameInfoSize);

                            Array.Copy(ggData.m_lprawdata, 0, AllRaw, i * ggData.m_sizeofrawdata, ggData.m_sizeofrawdata);
                            //Gen2Current = new mod_ReadGen2.Gen2_Struct();
                            //if (mod_ReadGen2.ReadGen2FromGGClass(this, ref Gen2Current, ref sErrString) != MyData.iErr_Succ)
                            //{
                            //    MyTools.ShowMsg("读取数据失败!", "从gg类读数据失败 = " + sErrString);
                            //    goto Eend;
                            //}
                            //PB.pGen2 = Gen2Current;
                            //PB.Gen2ToData();                        // 转变成 PictData
                            //Gen2Array[i] = PB.pGen2;

                            Array.Copy(ggData.m_lprawdata, iFirstLine * ggData.numberofpointofline * 2, FirstLine, i * ggData.numberofpointofline * 2, ggData.numberofpointofline * 2);       // To First Line
                            Array.Copy(ggData.m_lprawdata, iSeconLine * ggData.numberofpointofline * 2, SecondLine, i * ggData.numberofpointofline * 2, ggData.numberofpointofline * 2);      // To First Line

                            dBarStep      += (double)(85.0 / ggData.numberof_frames);
                            RBar.iBarValue = (int)(dBarStep);
                            MyTools.DoEvents();
                        }
                        else
                        {
                            sErrString = "移动到第" + i.ToString() + "帧时出错";
                            goto Eend;
                        }
                    }
                    else
                    {
                        sErrString = "移动到第" + i.ToString() + "帧时出错";
                        goto Eend;
                    }
                }

                BeltData = new double[ggData.numberof_frames * 2, ggData.numberofpointofline];
                ushort uSi = 0;
                ushort uMax = 0, uMin = 0;

                for (int i = 0; i < ggData.numberof_frames; i++)
                {
                    for (int j = 0; j < ggData.numberofpointofline; j++)
                    {
                        uSi            = BitConverter.ToUInt16(FirstLine, i * ggData.numberofpointofline * 2 + j * 2);
                        BeltData[i, j] = (double)uSi;
                        if (uMin > uSi)
                        {
                            uMin = uSi;
                        }

                        if (uMax < uSi)
                        {
                            uMax = uSi;
                        }

                        uSi = BitConverter.ToUInt16(SecondLine, i * ggData.numberofpointofline * 2 + j * 2);
                        BeltData[ggData.numberof_frames + i, j] = (double)uSi;
                        if (uMin > uSi)
                        {
                            uMin = uSi;
                        }

                        if (uMax < uSi)
                        {
                            uMax = uSi;
                        }
                    }
                }

                for (int i = 0; i < ggData.numberof_frames; i++)
                {
                    for (int j = 0; j < ggData.numberofpointofline; j++)
                    {
                        //BeltData[i, j] = (BeltData[i, j] / 65535.0) * (uMax - uMin) + uMin;
                        //BeltData[ggData.numberof_frames + i, j] = (BeltData[ggData.numberof_frames + i, j] / 65535.0) * (uMax - uMin) + uMin;

                        BeltData[i, j] = BeltData[i, j] * 255 / 65535.0;
                        BeltData[ggData.numberof_frames + i, j] = BeltData[ggData.numberof_frames + i, j] * 255 / 65535.0;
                    }
                }

                bResult    = true;
                sErrString = "";
            }
            catch (OutOfMemoryException)
            {
                sErrString = "内存不足";
            }
            catch (Exception ex)
            {
                sErrString = ex.Message;
            }
            finally
            {
                Marshal.FreeHGlobal(buffer);
            }

Eend:
            return(bResult);
        }