这是我的问题.请跟我说一点解释:
我正在读取tiff图像到缓冲区; 我的tiff的每个像素由一个ushort(16位数据,非负数)表示.
我的图像大小是64*64 = 4096.当我的tiff加载到缓冲区时,缓冲区长度因此是8192(两倍于4096).我想这是因为在我的缓冲区中,计算机使用2个字节来存储单个像素值.
我想得到任何特定像素的值,在这种情况下,我应该将每2个字节组合为1个ushort吗?
例如:00000000 11111111 - > 0000000011111111?
这是我的代码:
public static void LoadTIFF(string fileName, int pxlIdx, ref int pxlValue)
{
using (Tiff image = Tiff.Open(fileName, "r"))
{
if (image == null)
return;
FieldValue[] value = image.GetField(TiffTag.IMAGEWIDTH);
int width = value[0].ToInt();
byte[] buffer = new byte[image.StripSize()];
for (int strip = 0; strip < image.NumberOfStrips(); strip++)
image.ReadEncodedStrip(strip, buffer, 0, -1);
// do conversion here:
//ushort bufferHex = BitConverter.ToUInt16(buffer, 0);
image.Close();
}
}
Run Code Online (Sandbox Code Playgroud)
如何读取byte []缓冲区以确保我可以获得16位的ushort像素值?
谢谢
我在使用COM包装器调用.NET dll(mclNET.dll)时遇到问题.这是我没有源代码的第三部分dll.基本上我想在我的纯本机C++应用程序中使用这个mclNET.dll,所以我正在开发一个C#包装器.MCLWrapper.dll,这使得在方法mclNET.dll可见.这是我做的:
在MCLWrapper.dll中,我添加了mclNET.dll作为参考,然后定义接口以使mclNET.dll方法可见.这是我的一些代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using mclNET;
namespace MCLWrapper
{
public interface MCLControl
{
void MCLConnect(string SerialNumber);
void MCLSet_Switch(string SwitchName, int Val);
void MCLDisconnect();
};
public class MCLControlClass:MCLControl
{
private USB_RF_SwitchBox _sb = new USB_RF_SwitchBox();
public void MCLConnect(string SerialNumber)
{
_sb.Connect(ref SerialNumber);
}
public void MCLSet_Switch(string SwitchName, int Val)
{
_sb.Set_Switch(ref SwitchName, ref Val);
}
public void MCLDisconnect()
{
_sb.Disconnect(); …
Run Code Online (Sandbox Code Playgroud)这是我用来检测 txt 文件中一行中的字符串的代码:
int main()
{
std::ifstream file( "C:\\log.txt" );
std::string line;
while(!file.eof())
{
while( std::getline( file, line ) )
{
int found = -1;
if((found = line.find("GetSA"))>-1)
std::cout<<"We found GetSA."<<std::endl;
else if ((found = line.find("GetVol"))>-1)
std::cout<<"We found GetVol."<<std::endl;
else if ((found = line.find("GetSphereSAandVol"))>-1)
std::cout<<"We found GetSphereSAandVol."<<std::endl;
else
std::cout<<"We found nothing!"<<std::endl;
}
}
std::cin.get();
}
Run Code Online (Sandbox Code Playgroud)
这是我的日志文件:
GetSA (3.000000)
GetVol (3.000000)
GetSphereSAandVol (3.000000)
GetVol (3.000000)
GetSphereSAandVol (3.000000)
GetSA (3.00000)
Run Code Online (Sandbox Code Playgroud)
错误是,程序不会去找“GetSphereSAandVol”,因为它停在“GetSA”处。显然,程序认为“GetSphereSAandVol”包含“GetSA”,因此会执行:
if(found = line.find("GetSA"))
std::cout<<"We found GetSA."<<std::endl;
Run Code Online (Sandbox Code Playgroud)
这不完全是我想要的,因为我期望程序执行:
else if (found = …
Run Code Online (Sandbox Code Playgroud) 我想知道在C#中监视变量的最佳方法是什么.这不是用于调试.我基本上希望它自己的程序在运行期间一直监视它的一个变量.例如.我想看看_a是否小于0; 如果是,则程序停止.
_a = _b - _c; // (_b >= _c)
Run Code Online (Sandbox Code Playgroud)
所以_a的范围在[0 N]之内,其中N是一些正int; 我觉得最好是启动一个监视_a值的线程.一旦它,那么我应该回应.但我不知道如何实现它.有人有什么建议吗?一小段代码示例将受到高度赞赏.
像这样的东西:
class someclass
{
public:
someclass();
~someclass();
long Set(int x, int y);
private:
int _x;
int _y;
};
long Set(int x, int y)
{
_x = x;
_y = y;
}
Run Code Online (Sandbox Code Playgroud)
但是如果你只是写这样的东西,那么在Set()函数中就无法识别_x.那么如何使用自己的方法设置类的私有属性呢?非常感谢.
看起来像一个非常愚蠢的问题:这是如何声明数组指针:
double * y = new double[26];
Run Code Online (Sandbox Code Playgroud)
在这个宣言之后,我看到了程序运行的时间,这就是我所看到的:
name value
y[224] 8.691694942331e-310#DEN
y[225] CXX0030: Error: Expression cannot be evaluated
Run Code Online (Sandbox Code Playgroud)
所以我想知道为什么用26长度声明的双数组有224个元素?谢谢.
编辑:但我尝试了这个代码,它经历了!
int nPt = 26;
double * y = new double[nPt];
y[224] = 0;
Run Code Online (Sandbox Code Playgroud)
如果没有y [224],它的值是如何分配的?