public Bitmap CreateBoardImageLarge() { #region 创建整版图 System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); int nWidth = PCB.m_pPCB.m_uSizeX * 1000 / PCB.m_pPCB.m_uResolutionX / Board_Scale; int nHeight = PCB.m_pPCB.m_uSizeY * 1000 / PCB.m_pPCB.m_uResolutionY / Board_Scale; Point pt = new Point(0, 0); Color rgb; PixelFormat format = PixelFormat.Format8bppIndexed; Bitmap m_bmpTemp = new Bitmap(nWidth, nHeight, format); clsPointBitmap _lockbmp = new clsPointBitmap(m_bmpTemp); _lockbmp.lockBits(); for (int j = 0; j < _lockbmp.Height; j++) { for (int i = 0; i < _lockbmp.Width; i++) { if (PCB.m_pPCB.m_iCoordinateType == ConstData.LeftDown) { pt.X = i * Board_Scale * PCB.m_pPCB.m_uResolutionX / 1000; pt.Y = -j * Board_Scale * PCB.m_pPCB.m_uResolutionY / 1000 + PCB.m_pPCB.m_uSizeY; } else if (PCB.m_pPCB.m_iCoordinateType == ConstData.LeftUp) { pt.X = i * Board_Scale * PCB.m_pPCB.m_uResolutionX / 1000; pt.Y = j * Board_Scale * PCB.m_pPCB.m_uResolutionY / 1000; } else if (PCB.m_pPCB.m_iCoordinateType == ConstData.RightDown) { pt.X = -i * Board_Scale * PCB.m_pPCB.m_uResolutionX / 1000 + PCB.m_pPCB.m_uSizeX; pt.Y = -j * Board_Scale * PCB.m_pPCB.m_uResolutionY / 1000 + PCB.m_pPCB.m_uSizeY; } else { pt.X = -i * Board_Scale * PCB.m_pPCB.m_uResolutionX / 1000 + PCB.m_pPCB.m_uSizeX; pt.Y = j * Board_Scale * PCB.m_pPCB.m_uResolutionY / 1000; } pt.Offset(PCB.m_pPCB.m_ptOriginOffset); try { if (GetPixelAreaImage(pt, out rgb)) { _lockbmp.setPixel(i, j, rgb); } else { _lockbmp.setPixel(i, j, Color.FromArgb(100, 100, 100)); } } catch (Exception exc) { //Wells.WellsFramework.WellsMetroMessageBox.Show(null, exc.Message); } } } _lockbmp.unlockBits(); UnlockAreaImage(); if (!m_bIsColor) { m_bmpTemp.Palette = PCB.m_pPCB.palette; } sw.Stop(); //Wells.FrmType.frm_Log.Log("拼接耗时:" + sw.ElapsedMilliseconds.ToString() + " ms", 0, 0); return(m_bmpTemp); #endregion }
public bool CreateBoardImage()//速度太快,连续进入该函数会造成图片数据锁定冲突 { #region 创建视图区图像 if (1 == System.Threading.Interlocked.Read(ref LockedSign.l2ShowIsCreatingImage)) { return(false); } System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); if (m_rcPCBImageArea.Width > 0 && m_rcPCBImageArea.Height > 0) { System.Threading.Interlocked.Exchange(ref LockedSign.l2ShowIsCreatingImage, 1); Point pt = new Point(0, 0); Color rgb; PixelFormat format = PixelFormat.Format8bppIndexed; m_bmpArea = new Bitmap(m_rcPCBImageArea.Width, m_rcPCBImageArea.Height, format); clsPointBitmap _lockbmp = new clsPointBitmap(m_bmpArea); _lockbmp.lockBits(); for (int j = 0; j < _lockbmp.Height; j++) { for (int i = 0; i < _lockbmp.Width; i++) { pt.X = i; pt.Y = j; pt.Offset(m_rcPCBImageArea.X, m_rcPCBImageArea.Y); pt = VpToLp(pt); try { if (GetPixelAreaImage(pt, out rgb)) { _lockbmp.setPixel(i, j, rgb); } else { _lockbmp.setPixel(i, j, Color.FromArgb(100, 100, 100)); } } catch (Exception exc) { //Wells.WellsFramework.WellsMetroMessageBox.Show(null, exc.Message); } } } _lockbmp.unlockBits(); UnlockAreaImage(); if (!m_bIsColor) { m_bmpArea.Palette = PCB.m_pPCB.palette; } System.Threading.Interlocked.Exchange(ref LockedSign.l2ShowIsCreatingImage, 0); } sw.Stop(); //Wells.FrmType.frm_Log.Log("拼接耗时:" + sw.ElapsedMilliseconds.ToString() + " ms", 0, 0); return(true); #endregion }