阅读:2115回复:2
求AE IStyleGalleryClass接口的例子
<P>最近在做图层的渲染功能,环境:AE9.2+VS05,现在想将图层的样式以图片对话框的格式浏览出来,以供用户选择,之前我已经实现了利用样式名称进行选择的功能,但是为了更加方便用户,现在必须进行样式图片浏览,在实现的过程中遇到了一个接口,如题 IStyleGalleryClass 接口,我不会实现,不知道各位是否有人对该有熟悉的?有的话请发个例子,在下不胜感激!!昨天已经查了一下午毫无建树!!</P>
<P>在线等!! </P> |
|
1楼#
发布于:2007-07-09 09:08
不知道有没有VC的代码啊
|
|
2楼#
发布于:2007-07-06 16:00
<P>我找到一些类似的代码,没有用到IStyleGalleryClass,用的是IStyleGalleryItem,IEnumStyleGalleryItem和IStyleGallery接口,实现的功能是遍历ServerStyle文件中的所有Symbol,并以位图的形式显示在listview中,楼主可以参考一下。<BR><BR><BR></P>
<P>Private m_pSymType As String<BR> Private m_pFeaLayer As IFeatureLayer2<BR> Private m_pStyleGalleryItem As IStyleGalleryItem<BR> Private m_pEnumStyleGallery As IEnumStyleGalleryItem<BR> Private m_pStyleGallery As IStyleGallery<BR> Private m_pDisplay As Boolean</P> <P>Public Sub LoadSymbol(ByVal plistView As ListView, ByVal pImageList As ImageList)<BR> If m_pStyleGallery Is Nothing Then<BR> m_pStyleGallery = New ServerStyleGallery<BR> End If</P> <P> Dim pSymbol As ISymbol<BR> Dim bmp As System.Drawing.Bitmap<BR> Dim ImgIndex As Integer<BR> Dim pServerStylePath As String<BR> ImgIndex = -1<BR> plistView.LargeImageList = pImageList</P> <P> '定义Style文件<BR> Dim pStylStor As IStyleGalleryStorage<BR> pStylStor = m_pStyleGallery<BR> pServerStylePath = pStylStor.DefaultStylePath ; "ESRI.ServerStyle"<BR> pStylStor.TargetFile = pServerStylePath<BR> <BR> m_pEnumStyleGallery = m_pStyleGallery.Items(p_pSYSymbolType, pServerStylePath, "Default")</P> <P><BR> m_pEnumStyleGallery.Reset()<BR> m_pStyleGalleryItem = m_pEnumStyleGallery.Next</P> <P> '遍历Style文件<BR> '把Style文件里的每个Symbol绘制成位图添加到ListView中<BR> While Not m_pStyleGalleryItem Is Nothing<BR> pSymbol = m_pStyleGalleryItem.Item<BR> If TypeOf pSymbol Is IMarkerFillSymbol Then<BR> 'MsgBox("henhao")<BR> End If<BR> bmp = CreateBitmap(pSymbol, 44)<BR> pImageList.Images.Add(bmp)<BR> ImgIndex = ImgIndex + 1<BR> Dim pListViewItem As ListViewItem<BR> pListViewItem = New ListViewItem(m_pStyleGalleryItem.Name.ToString, ImgIndex)</P> <P> '设置Tag属性,建立Symbol和位图的联系<BR> 'pListViewItem.Tag = pSymbol<BR> If TypeOf pSymbol Is IMarkerSymbol Then<BR> Dim pMarkersymbol As IMarkerSymbol<BR> pMarkersymbol = pSymbol<BR> pListViewItem.Tag = pMarkersymbol<BR> End If<BR> If TypeOf pSymbol Is ILineSymbol Then<BR> Dim pLineSymbol As ILineSymbol<BR> pLineSymbol = pSymbol<BR> pListViewItem.Tag = pLineSymbol<BR> End If<BR> If TypeOf pSymbol Is IFillSymbol Then<BR> Dim pFillSymbol As IFillSymbol<BR> pFillSymbol = pSymbol<BR> pListViewItem.Tag = pFillSymbol<BR> End If<BR> plistView.Items.Add(pListViewItem)<BR> m_pStyleGalleryItem = m_pEnumStyleGallery.Next<BR> End While</P> <P> If plistView.Items.Count <> 0 Then<BR> m_pDisplay = True<BR> Else<BR> MsgBox("该ServerStyle文件中没有需要的符号\n,请选择其他文件", MsgBoxStyle.Information, "提示")<BR> m_pDisplay = False<BR> End If<BR> '释放COM对象<BR> System.Runtime.InteropServices.Marshal.ReleaseComObject(m_pEnumStyleGallery)</P> <P> End Sub</P> <P>Function CreateBitmap(ByVal pSymbol As ISymbol, ByVal BMPSize As Integer) As System.Drawing.Bitmap<BR> Dim Bmp As System.Drawing.Bitmap<BR> Dim Dpi As Double<BR> Dim pEnvelope As IEnvelope<BR> Dim pDeviceRect As tagRECT<BR> Dim pDisplayTransformation As IDisplayTransformation<BR> Dim pFromPoint As IPoint<BR> Dim pToPoint As IPoint<BR> Dim pGeometry As IGeometry<BR> If Bmp Is Nothing Then<BR> Bmp = New System.Drawing.Bitmap(BMPSize, BMPSize)<BR> End If</P> <P> '把图片格式定义为位图<BR> Dim gImage As System.Drawing.Graphics<BR> gImage = System.Drawing.Graphics.FromImage(Bmp)<BR> gImage.Clear(System.Drawing.Color.Transparent)<BR> Dpi = gImage.DpiX<BR> pEnvelope = New Envelope<BR> pEnvelope.PutCoords(0, 0, Bmp.Width, Bmp.Height)</P> <P> '设置位图的边界<BR> pDeviceRect.bottom = 0<BR> pDeviceRect.left = 0<BR> pDeviceRect.top = Bmp.Height<BR> pDeviceRect.right = Bmp.Width</P> <P> '设置位图的设备环境<BR> pDisplayTransformation = New DisplayTransformation</P> <P> pDisplayTransformation.VisibleBounds = pEnvelope<BR> pDisplayTransformation.Bounds = pEnvelope ' 边界<BR> pDisplayTransformation.DeviceFrame = pDeviceRect '设备坐标的可见范围<BR> pDisplayTransformation.Resolution = Dpi '每一个英寸有多少个像素点</P> <P> pFromPoint = New Point<BR> pToPoint = New Point</P> <P> pGeometry = Nothing</P> <P> '判断Symbol的类型,根据类型定义Symbol在位图中的大小和位置,注意屏幕坐标X为正值,Y坐标为负值<BR> Select Case p_pSYSymbolType<BR> Case "Marker Symbols"<BR> pFromPoint.PutCoords(0.5 * Bmp.Width, -0.5 * Bmp.Height)<BR> pGeometry = pFromPoint</P> <P> Case "Line Symbols"<BR> pFromPoint.PutCoords(0, -0.5 * Bmp.Height)<BR> pToPoint.PutCoords(Bmp.Width, -0.5 * Bmp.Height)<BR> Dim pPolyline As IPolyline<BR> pPolyline = New Polyline<BR> pPolyline.FromPoint = pFromPoint<BR> pPolyline.ToPoint = pToPoint<BR> pGeometry = pPolyline</P> <P> Case "Fill Symbols"<BR> Dim pEnvel As IEnvelope2<BR> pEnvel = New Envelope<BR> pEnvel.PutCoords(0, -0.8 * Bmp.Height, 0.8 * Bmp.Width, 0)<BR> pEnvel.Expand(-1, -1, False)<BR> Dim pSegColl As ISegmentCollection<BR> pSegColl = New Polygon<BR> pSegColl.SetRectangle(pEnvel)</P> <P> pGeometry = pSegColl<BR> End Select</P> <P> '设置Symbol的属性,根据Symbol画位图<BR> Dim hdc As System.IntPtr<BR> hdc = New System.IntPtr<BR> hdc = gImage.GetHdc()<BR> Dim pSymbolBmp As ISymbol<BR> 'Dim tmpSymbol As IFillProperties</P> <P> pSymbolBmp = pSymbol</P> <P> pSymbolBmp.SetupDC(hdc.ToInt32, pDisplayTransformation)<BR> pSymbolBmp.Draw(pGeometry)<BR> pSymbolBmp.ResetDC()<BR> gImage.ReleaseHdc(hdc)<BR> gImage.Dispose()<BR> CreateBitmap = Bmp</P> <P> End Function</P> |
|
|