我的尺寸为98 x 102的图像。光盘尺寸为11 270字节。 我需要从这个图像中获取没有服务信息的字节数组。 我试着做下一个:
MySystemInfo Msi;
puts(Msi.getOsInfo());
char* MySystemInfo::getOsInfo()
{
OSVERSIONINFOEX osver;
BOOL bOsVersionInfoEx;
HKEY hKey;
LONG lRet;
char* RtTmpOsInfo= (char *) malloc(sizeof(char)*70);
char* s1=(char *) malloc(sizeof(char)*20);
char* s2=(char *) malloc(sizeof(char)*50);
// Try calling GetVersionEx() using the OSVERSIONINFOEX structure.
// If that fails, try using the OSVERSIONINFO structure.
ZeroMemory(&osver, sizeof(OSVERSIONINFOEX));
osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
if(!(bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *) &osver)))
{
osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if(!GetVersionEx((OSVERSIONINFO *) &osver))
return "";
}
switch (osver.dwPlatformId)
{
//Test for the Windows NT product family.
case VER_PLATFORM_WIN32_NT:
if(osver.dwMajorVersion <4> BUFSIZE) return "";
sprintf( s1,"v%d.%d "+ osver.dwMajorVersion, osver.dwMinorVersion);
// Test for the specific product family.
if(osver.dwMinorVersion==0){
if(osver.dwMajorVersion == 5) sprintf(s2,"Microsoft Windows 2000\n");
else if(osver.dwMajorVersion == 6) sprintf(s2,"Microsoft Windows Vista\n");
}
else if(osver.dwMinorVersion==1){
if(osver.dwMajorVersion == 5) sprintf(s2,"Microsoft Windows XP\n");
else if(osver.dwMajorVersion == 6) sprintf(s2,"Microsoft Windows 7\n");
}
else if(osver.dwMinorVersion==2){
if(osver.dwMajorVersion == 5) sprintf(s2,"Microsoft Windows Server 2003 family\n");
}
else sprintf(s2,"unknown OS\n");
break;
}
strcat(RtTmpOsInfo,s1);
strcat(RtTmpOsInfo,s2);
//lRet/* = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\WindowsNT\\CurrentVersion\\Hotfix\\Q246009", 0, KEY_QUERY_VALUE, &hKey);
// printf("Service Pack 1 (Build %d)\n", osver.dwBuildNumber & 0xFFFF);*/
return RtTmpOsInfo;
}
通过这种方式我得到带有图像头的数组,因为get数组的长度是11 270。
标题大小是否正确= 11270 - (98 * 102)? 因为这个结果是1274。
我正在尝试在控制台应用中执行此操作。
如果不正确,我该怎么做?
答案 0 :(得分:1)
我假设您需要从此位图获取RGB数据。您可以通过锁定/解锁位图中的数据来获取对原始数据的访问权限。来自MSDN https://msdn.microsoft.com/en-us/library/5ey6h79d(v=vs.110).aspx的示例代码:
// Create bitmap.
Bitmap bmp = new Bitmap("c:\\photo.jpg");
// Lock the bitmap's bits.
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
System.Drawing.Imaging.BitmapData bmpData =
bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
bmp.PixelFormat);
// Get the address of the first line.
IntPtr ptr = bmpData.Scan0;
// Declare an array to hold the bytes of the bitmap.
int bytes = Math.Abs(bmpData.Stride) * bmp.Height;
byte[] rgbValues = new byte[bytes];
// Copy the RGB values into the array.
System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
// Set every third value to 255. A 24bpp bitmap will look red.
for (int counter = 2; counter < rgbValues.Length; counter += 3)
rgbValues[counter] = 255;
// Copy the RGB values back to the bitmap
System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes);
// Unlock the bits.
bmp.UnlockBits(bmpData);