MFC对话框中用IPicture类加载了一幅图片,现在想对图片进行 *** 作,想获得指向该图像第一个像素的指针,怎么

MFC对话框中用IPicture类加载了一幅图片,现在想对图片进行 *** 作,想获得指向该图像第一个像素的指针,怎么,第1张

以pPicture 取得你这个的高与宽

建一个同样大小的设备兼容位图,然后pPicture->Render 其中设备描述符句柄HDC使用这个

设备兼容位图的HDC作为参数,这样你的Picture就渲染到了这个设备兼容位图上,然后就是常规 *** 作了。如果你对设备兼容位图的 *** 作不清楚,就去看Win32程序设计这本书,百度文档上肯定有

看位图那章,很多例子的。

原因

借助numpy读取之后,转为opencv 的格式

opencv imread和imdecode 最后一个参数flag的取值如下

IMREAD_ANYCOLOR : 4

IMREAD_ANYDEPTH : 2

IMREAD_COLOR : 1

IMREAD_GRAYSCALE : 0

IMREAD_IGNORE_ORIENTATION : 128

IMREAD_LOAD_GDAL : 8

IMREAD_REDUCED_COLOR_2 : 17

IMREAD_REDUCED_COLOR_4 : 33

IMREAD_REDUCED_COLOR_8 : 65

IMREAD_REDUCED_GRAYSCALE_2 : 16

IMREAD_REDUCED_GRAYSCALE_4 : 32

IMREAD_REDUCED_GRAYSCALE_8 : 64

IMREAD_UNCHANGED : -1

IMREAD_UNCHANGED :不进行转化,比如保存为了16位的,读取出来仍然为16位。

IMREAD_GRAYSCALE :进行转化为灰度图,比如保存为了16位的,读取出来为8位,类型为CV_8UC1。

IMREAD_COLOR :进行转化为三通道图像。

IMREAD_ANYDEPTH :如果图像深度为16位则读出为16位,32位则读出为32位,其余的转化为8位。

IMREAD_ANYCOLOR :

IMREAD_LOAD_GDAL :使用GDAL驱动读取文件,GDAL(Geospatial Data Abstraction Library)是一个在X/MIT许可协议下的开源栅格空间数据转换库。它利用抽象数据模型来表达所支持的各种文件格式。它还有一系列命令行工具来进行数据转换和处理。

使用PIL把从gif转为一般

你好,除了这两行后面还应该还有信息的。

如果能打印出的信息的话,这个读入就没有问题。

下面是一些没有问题的提示例子。

What seems OK:

$ tiff2rgba 001tif 001rgbatiff

produces a picture that seems OK viewed with gwenview

$ tiffdither rietkleur003tif rikldit003tif

TIFFReadDirectory: Warning, Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel Defining non-color channels as ExtraSamples

tiffdither: Not a b&w image

OK, it is a color image, decent message to me

$ tiffdither gray1tif gray1dittif

produces a heavily dithered image Seems OK

$ tiffgt rietkleur004tif

displays the picture decently

$ tiffinfo rietkleur004tif

TIFFReadDirectory: Warning, Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel Defining non-color channels as ExtraSamples

TIFF Directory at offset 0x1a51b08 (27597576)

Image Width: 2144 Image Length: 3218

Bits/Sample: 8

Compression Scheme: None

Photometric Interpretation: RGB color

Samples/Pixel: 4

Planar Configuration: single image plane

Seems OK

$ tiffsplit rietkleur004tif

TIFFReadDirectory: Warning, Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel Defining non-color channels as ExtraSamples

There is nothing really to split, but it generates a decent xaaatif file, copy of the original picture OK for me

]$ tiffmedian rietkleur007tif riklmed007tif

TIFFReadDirectory: Warning, Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel Defining non-color channels as ExtraSamples

produces an akward color picture with only a few week but quite different colors I guess that's what I asked for

256色的位图占用1个字节 就是8位二进制能表示的范围等于256,估计RGB分别是323,3位二进制表示红色 两位表示绿色 在3位表示蓝色 24位真彩分别是8位表示红 8位表示绿 8位表示蓝 24位表示一个像素。8位能表示的范围是256,3个8位也就是能表示的颜色数量位256256256,就是所谓的1670万色彩

用 gdal库。

库参考和下载在这:>

下面这个文件瞎写的,你可以修改下。。需要加装库,头文件和lib

//tifh

enum

{

TOPX = 0,

CELLX,

XXXX,

TOPY,

XXXXX,

CELLY,

GeoTfInfoArrCount

};

 template<typename type, int nBand =1>

 class CTifFileOp

 {

 public:

 CTifFileOp(string FilePath=string(""));

virtual ~CTifFileOp();

double get_nodata_value()

{

return m_pDataset->GetRasterBand(nBand)->GetNoDataValue();

}

int GetGeoTransform(double gt)const;

int ChangeFile(string strPath);

void ReadTiffDataset(type  DataGet, int begRow = 0, int begCol = 0, int numRows = 1, int numCols = 1)const;

void WriteTiffDataset(type  DataGet, int begRow = 0, int begCol = 0, int numRows = 1, int numCols = 1);

void ReadTiffDataset(vector<type> & DataGet, int begRow = 0, int begCol = 0, int numRows = 1, int numCols = 1)const

{

DataGetclear();

DataGetresize(numColsnumRows);

ReadTiffDataset(&DataGetbegin(), begRow, begCol, numRows, numCols);

}

size_t GetColNum()

{

openDs();

return m_pDataset->GetRasterXSize();

}

size_t GetRowNum()

{

openDs();

return m_pDataset->GetRasterYSize();

}

//获取波段数

int GetRasterCount()

{

openDs();

return m_pDataset->GetRasterCount();

}

//获取坐标系信息

const char  GetProjectionRef()

{

openDs();

return m_pDataset->GetProjectionRef();

}

//获取数据类型

GDALDataType GetDataType(int iRaster = nBand)

{

openDs();

return m_pDataset->GetRasterBand(iRaster)->GetRasterDataType();

}

void GetAllData(vector<type> & DataGet)

{

//   double geoInfo[GeoTfInfoArrCount] = { 0 };

//   GetGeoTransform(geoInfo);

openDs();

ReadTiffDataset(DataGet, 0, 0, GetRowNum(), GetColNum());

}

 private:

 string m_strFile;

 GDALDataset m_pDataset = nullptr;

 bool m_bWrite = false;

 private:

 void openDs(GDALAccess openMode = GA_ReadOnly);

 bool CanWrite()const

 {

 return m_bWrite;

 }

};

 

 template<typename type, int nBand>

 int CTifFileOp<type, nBand>::GetGeoTransform(double gt) const

 {

// openDs();

 m_pDataset->GetGeoTransform(gt);

 return 0;

 }

 

 template<typename type, int nBand>

 CTifFileOp<type, nBand>::CTifFileOp(string FilePath)

 :m_strFile(FilePath), m_pDataset(nullptr)

 {

openDs();

 }

 template<typename type, int nBand>

 CTifFileOp<type, nBand>::~CTifFileOp()

 {

if (m_pDataset)

{

GDALClose(m_pDataset);

m_pDataset = nullptr;

//是这样关闭 数据集 么?

}

 }

 template<typename type, int nBand>

 void CTifFileOp<type, nBand>::openDs(GDALAccess openMode)

{

 if (m_pDataset)//当不为nullptr,认为是打开的

 {

 return;

 }

GDALAllRegister();

const char pszFormat = "GTiff";

GDALDriver poDriver;

poDriver = GetGDALDriverManager()->GetDriverByName(pszFormat);

if (poDriver == nullptr){

return;

}

if (!m_strFileempty())

{

m_pDataset = ((GDALDataset )GDALOpen(m_strFilec_str(), openMode));

//  if (m_pDataset != NULL)

//  {

//  int ibandCounts = m_pDataset->GetRasterCount();

//  ibandCounts |= (long(1)<<0);

//  }

if (GA_Update == openMode)

{

m_bWrite = true;

}

else

m_bWrite = false;

}

// OGRCleanupAll();

}

template<typename type, int nBand>

int CTifFileOp<type, nBand>::ChangeFile(string strPath)

{

m_strFile = strPath;

if (m_pDataset)

{

GDALClose(m_pDataset);

m_pDataset = nullptr;

//是这样关闭 数据集 么?

}

openDs();

return 0;

}

template<typename type, int nBand>

void CTifFileOp<type, nBand>::ReadTiffDataset(type  DataGet, int begRow, int begCol, int numRows, int numCols)const

{

if (!DataGet || !m_pDataset)

{

return;

}

if (begRow < 0 || begCol < 0 || numRows <= 0 || numCols <= 0)

{

return;

}

GDALDataType datatype = m_pDataset->GetRasterBand(nBand)->GetRasterDataType();

//不知道下面读数据的这个类型参数有什么意义

m_pDataset->RasterIO(GF_Read,begCol,begRow,numCols,numRows,DataGet,numCols,numRows,datatype,1,0,0,0,0);

}

template<typename type,int nBand>

void CTifFileOp<type, nBand>::WriteTiffDataset(type  DataGet, int begRow, int begCol, int numRows, int numCols)

{

if (!DataGet || !m_pDataset)

{

return;

}

if (begRow < 0 || begCol < 0 || numRows <= 0 || numCols <= 0)

{

return;

}

if (!CanWrite())

{

GDALClose(m_pDataset);

m_pDataset = nullptr;

openDs(GA_Update);

}

GDALDataType datatype = m_pDataset->GetRasterBand(nBand)->GetRasterDataType();

//不知道下面读数据的这个类型参数有什么意义

m_pDataset->RasterIO(GF_Write, begCol, begRow, numCols, numRows, DataGet, numCols, numRows, datatype, 1, 0, 0, 0, 0);

}

以上就是关于MFC对话框中用IPicture类加载了一幅图片,现在想对图片进行 *** 作,想获得指向该图像第一个像素的指针,怎么全部的内容,包括:MFC对话框中用IPicture类加载了一幅图片,现在想对图片进行 *** 作,想获得指向该图像第一个像素的指针,怎么、2022-05-01 python opencv 读取图片返回None、python gdal.Open(file) Warning1:TIFFReadDirectory:Sum of Photometric type-related color channels等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9810727.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-02
下一篇 2023-05-02

发表评论

登录后才能评论

评论列表(0条)

保存