c++ BITMAPINFOHEADER biBitCount equivalent in C#
c++ BITMAPINFOHEADER biBitCount equivalent in C#
我正在尝试将c++代码转换为c#的每个人。该代码正在压缩位图图像。我的c++代码使用BITMAPINFOHEADER
要读取位图图像的biBitCount,我如何在c#(win-app)中获得图像的位数?。这是c++代码
char *pTemp; //image data will store here
BITMAPINFOHEADER *pbminfo;
pbminfo = (BITMAPINFOHEADER *)pTemp;
if ( pbminfo->biBitCount != 1 ) // Convert 24 bit -> 1 bit
{
//some process will be done here
}
您确实可以在Visual C++/CLI中编写一个包装器类,但您想做的一切都可以完全实现,只需在您的端使用C#。
可以使用图像的PixelFormat
属性。它有多种可能的价值。
像素格式定义与数据的一个像素相关联的存储器的位数。该格式还定义了数据的单个像素内的颜色分量的顺序。
PixelFormat48bppRGB、PixelFormat64bppARGB和PixelFormat64 bppPARGB每个颜色分量(通道)使用16位。GDI+版本1.0和1.1可以读取每个通道16位的图像,但这些图像被转换为每个通道8位的格式,用于处理、显示和保存。每个16位颜色通道都可以保存0到2^13范围内的值。
某些像素格式包含预乘的颜色值。预乘表示颜色值已经乘以alpha值。
var image = new Bitmap(@"C:tempme.png");
if (image != null) {
Console.Write("Format: {0}", image.PixelFormat.ToString("G"));
}
在我的情况下,结果将是:Format32bppArgb
。
您可以尝试以下操作:
using System.Drawing;
public class TestThis
{
public void Test()
{
Image myImage = Image.FromFile("Myfile.png");
int bitDepth = Image.GetPixelFormatSize(myImage.PixelFormat);
if( bitDepth != 1)
{
// Do domething
}
}
}
相关文章:
- netcat command in c++
- Difference in displaying cv2 Mat
- C++ MFC Libraries in Travis CI
- 如何在OpenSSL中从configuration.h.in获取configuration.h
- 创建具有 new in 函数和"this is nullptr"异常的对象
- IN, OUT, INOUT Parameters
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- Equivalent of OpenCv c++ api Vec2f,norm, acos in emgucv csha
- TrackPopupMenu equivalent in OS X
- MPI-Parallel HDF5: H5Pset_fapl_mpio equivalent in C++
- WIN32_FIND_DATA equivalent in Linux C++
- itertools.tee equivalent in Boost::Range?
- c++ BITMAPINFOHEADER biBitCount equivalent in C#
- RSA C++ equivalent in C#
- Vector2 equivalent in c++?
- Java varargs equivalent in C++
- NSNotificationCenter equivalent in C++
- DateTime equivalent in C
- MATLAB equivalent in c++
- Java HashSet equivalent in C++