• 大小: 17.24MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-07-07
  • 语言: C#
  • 标签: GDAL  C#  VS2015  

资源简介

在VS2015的开发环境中,基于GDAL包和C#语言,实现栅格影响的读取和显示,包括灰度影像和彩色影像的读取和显示。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OSGeo.GDAL;

namespace ReadRaster_Gray
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btn_open_Click(object sender EventArgs e)
        {
            initial();
            //文件路径
            string fileName = ““;
            OpenFileDialog openFile = new OpenFileDialog();
            openFile.Filter = “所有文件|*.*|Tiff文件|*.tif|Erdas img文件|*.img|Bmp文件|*.bmp|jpeg文件|*.jpg“;
            if (openFile.ShowDialog() == DialogResult.OK)
            {
                fileName = openFile.FileName;
            }
            else
            {
                MessageBox.Show(“影像路径不能为空““注意“
                    MessageBoxButtons.OKCancelMessageBoxIcon.Information);
                return;
            }
            textBox1.Text = fileName;
            //创建Dataset
            Gdal.AllRegister();
            Dataset ds = null;
            try
            {
                ds = Gdal.Open(fileName Access.GA_ReadOnly);
            }
            catch (Exception ex)
            {
                MessageBox.Show(“打开影像失败“+ex.Message);
            }
            if (ds == null)
            {
                MessageBox.Show(“影像无效“);
                return;
            }
           
            //创建包络矩形
            Rectangle rec = new Rectangle();
            rec.Width = this.pictureBox1.Width;
            rec.Height = this.pictureBox1.Height;
            //调用ReadImage方法获取图像并显示
            Bitmap map = ReadImage(ds rec);
            pictureBox1.Image = map;
        }
        //读取图像数据
        public Bitmap ReadImage(Dataset ds Rectangle rec)
        {

            #region 获取图像信息
            int imageWidth = ds.RasterXSize;
            int imageHeight = ds.RasterYSize;
            float imgRatio = imageWidth / (float)imageHeight;

            //图像颜色模式
            int model;
            model = ds.RasterCount;
            double[] dd = new double[4];
            ds.GetGeoTransform(dd);
            string prj = ds.GetProjection();
            string str = string.Format(“波段数目:{0}\n行数:{1};列数:{2}\n坐标参考:{3}{4}{5}{6}\n“ ds.RasterCount ds.RasterXSize ds.RasterYSize dd[0] dd[1] dd[2] dd[3]);
            str += prj + “\n“;
            for (int i = 1; i <= ds.RasterCount; ++i)
            {
                OSGeo.GDAL.Band band = ds.GetRasterBand(i);
                str += “波段“ + i + “:“ + band.DataType.ToString();

            }
            infoText.Text = str;
            #endregion
            #region 对图像进行缩放
            //依据矩形尺寸设置buffer的尺寸
            int boxWidth = rec.Width;
            int boxHeight = rec.Height;
            float boxRatio = boxWidth / (float)bo

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     59904  2019-07-01 09:11  ReadRaster_Gray\.vs\ReadRaster_Gray\v14\.suo

     文件        189  2019-04-19 09:11  ReadRaster_Gray\ReadRaster_Gray\App.config

     文件    2285056  2018-06-10 05:15  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\cairo.dll

     文件    1005568  2017-09-03 22:13  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\cfitsio.dll

     文件     111104  2017-09-03 22:21  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\expat.dll

     文件      55808  2017-09-03 22:44  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\freexl.dll

     文件     117248  2017-09-03 22:25  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\fribidi.dll

     文件   16811008  2019-01-24 06:23  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\gdal204.dll

     文件      20480  2019-01-24 06:27  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\gdalconst_csharp.dll

     文件      17408  2019-01-24 06:27  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\gdalconst_wrap.dll

     文件      98304  2019-01-24 06:27  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\gdal_csharp.dll

     文件      81920  2019-01-24 06:27  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\gdal_wrap.dll

     文件    1033728  2017-09-03 16:31  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\geos.dll

     文件     228864  2017-09-03 16:31  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\geos_c.dll

     文件    2120704  2017-09-03 23:18  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\hdf5.dll

     文件     248832  2017-09-03 23:19  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\hdf5_cpp.dll

     文件      97280  2017-09-03 23:18  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\hdf5_hl.dll

     文件      10752  2017-09-03 23:18  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\hdf5_hl_cpp.dll

     文件     544256  2017-09-03 23:24  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\hdfdll.dll

     文件     900096  2017-09-03 17:48  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\iconv.dll

     文件     288256  2017-09-03 18:25  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\libcurl.dll

     文件    1154560  2017-09-03 18:14  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\libeay32.dll

     文件    1185792  2017-09-04 01:47  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\libecwj2.dll

     文件      41472  2017-09-03 22:16  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\libfcgi.dll

     文件     366592  2017-09-03 23:22  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\libkea.dll

     文件    3909632  2017-09-04 02:59  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\libmysql.dll

     文件     124928  2018-06-10 05:10  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\libpq.dll

     文件     749056  2017-09-03 22:33  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\libtiff.dll

     文件    1021440  2018-06-10 05:14  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\libxml2.dll

     文件    3872256  2017-12-22 08:03  ReadRaster_Gray\ReadRaster_Gray\bin\Debug\lti_dsdk_9.5.dll

............此处省略68个文件信息

评论

共有 条评论