private void SetRepresentationType(IRaster raster, rstRepresentationType rasterRepresentationType) { IRasterBandCollection rasterBandCollection = (raster as IRaster2).RasterDataset as IRasterBandCollection; for (int i = 0; i < rasterBandCollection.Count; i++) { rasterBandCollection.Item(i).RepresentationType = rasterRepresentationType; } }
public bool SaveAs(bool bSetRepresentationType = false, rstRepresentationType representationType = rstRepresentationType.DT_ATHEMATIC, bool bUseMessagebox = true) { object editValue = this.m_checkedCmbBand.EditValue; bool result; if (editValue == null) { XtraMessageBox.Show("请设置输出波段!", "提示信息", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Asterisk); result = false; } else if (string.IsNullOrEmpty(this.m_sOutputPath)) { XtraMessageBox.Show("请选择文件输出路径!", "提示信息", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Asterisk); result = false; } else { FileInfo fileInfo = new FileInfo(this.m_sOutputPath); if (fileInfo.Exists) { if (XtraMessageBox.Show("此文件已存在,是否覆盖?", "提示信息", System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Asterisk) != System.Windows.Forms.DialogResult.OK) { result = false; return(result); } fileInfo.Delete(); } IRaster raster = this.m_raster; string[] array = editValue.ToString().Split(new char[] { ',' }); if (array.Length != this.m_bandList.Count) { IRaster raster2 = ((this.m_raster as IRaster2).RasterDataset as IRasterDataset3).CreateRaster(); IRasterProps rasterProps = raster2 as IRasterProps; rasterProps.Width = (this.m_raster as IRasterProps).Width; rasterProps.Height = (this.m_raster as IRasterProps).Height; IRasterBandCollection rasterBandCollection = raster2 as IRasterBandCollection; IRasterBandCollection rasterBandCollection2 = (this.m_raster as IRaster2).RasterDataset as IRasterBandCollection; for (int i = 0; i < rasterBandCollection2.Count; i++) { IRasterBand rasterBand = rasterBandCollection2.Item(i); string[] array2 = array; for (int j = 0; j < array2.Length; j++) { string text = array2[j]; if (text.Trim() == rasterBand.Bandname) { rasterBandCollection.AppendBand(rasterBand); break; } } } raster = raster2; } this.SetResamplingMethod(raster, this.m_cmbResamplingType); this.SetPixelType(raster, this.m_cmbPixelType); if (bSetRepresentationType) { this.SetRepresentationType(raster, representationType); } frmWaitDialog frmWait = new frmWaitDialog("正在输出......", "提示信息"); IWorkspace workspace = null; string text2 = "输出成功!"; //Logger logger = new Logger(); try { frmWait.Owner = this.m_frm; frmWait.TopMost = false; string text3 = this.m_cmbOutputType.Text; ISaveAs2 saveAs = raster as ISaveAs2; if (!saveAs.CanSaveAs(text3)) { XtraMessageBox.Show("不支持指定像素类型或文件格式的输出!", "提示信息", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Asterisk); result = false; } else { IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass(); workspace = workspaceFactory.OpenFromFile(Path.GetDirectoryName(this.m_sOutputPath), 0); IDataset o = saveAs.SaveAs(Path.GetFileName(this.m_sOutputPath), workspace, text3); if (o != null) { Marshal.ReleaseComObject(o); } result = true; } } catch (Exception ex) { text2 = "输出失败!"; result = false; } finally { if (workspace != null) { Marshal.ReleaseComObject(workspace); } frmWait.Close(); if (bUseMessagebox) { XtraMessageBox.Show(text2, "提示信息", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Asterisk); } } } return(result); }