Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将C中的位图转换为C++; 我认为对于使用C++中位图的人来说,这是一个简单的问题。我有一个C代码中的工作代码——如何在C++中做类似的事情?感谢您的代码(帮助):-) 公共位图可视化() { PixelFormat fmt=System.Drawing.Imaging.PixelFormat.Format24bppRgb; 位图结果=新位图(宽度、高度、fmt); BitmapData data=result.LockBits(新矩形(0,0,宽度,高度),ImageLockMode.ReadOnly,fmt); 不安全的 { 字节*ptr; 对于(int y=0;y跨步).ToPointer()); 对于(int x=0;x解锁位(数据); 返回结果; } public Bitmap Visualize () { PixelFormat fmt = System.Drawing.Imaging.PixelFormat.Format24bppRgb; Bitmap result = new Bitmap( Width, Height, fmt ); BitmapData data = result.LockBits( new Rectangle( 0, 0, Width, Height ), ImageLockMode.ReadOnly, fmt ); unsafe { byte* ptr; for ( int y = 0; y < Height; y++ ) { ptr = (byte*)data.Scan0 + y * data.Stride; for ( int x = 0; x < Width; x++ ) { float num = 0.44; byte c = (byte)(255.0f * num); ptr[0] = ptr[1] = ptr[2] = c; ptr += 3; } } } result.UnlockBits( data ); return result; } Bitmap^ Visualize () { PixelFormat fmt = System::Drawing::Imaging::PixelFormat::Format24bppRgb; Bitmap^ result = gcnew Bitmap( Width, Height, fmt ); BitmapData^ data = result->LockBits( Rectangle( 0, 0, Width, Height ), ImageLockMode::ReadOnly, fmt ); for ( int y = 0; y < Height; y++ ) { unsigned char* ptr = reinterpret_cast<unsigned char*>((data->Scan0 + y * data->Stride).ToPointer()); for ( int x = 0; x < Width; x++ ) { float num = 0.44f; unsigned char c = static_cast<unsigned char>(255.0f * num); ptr[0] = ptr[1] = ptr[2] = c; ptr += 3; } } result->UnlockBits( data ); return result; }_C++_Bitmap_Unsafe - Fatal编程技术网

将C中的位图转换为C++; 我认为对于使用C++中位图的人来说,这是一个简单的问题。我有一个C代码中的工作代码——如何在C++中做类似的事情?感谢您的代码(帮助):-) 公共位图可视化() { PixelFormat fmt=System.Drawing.Imaging.PixelFormat.Format24bppRgb; 位图结果=新位图(宽度、高度、fmt); BitmapData data=result.LockBits(新矩形(0,0,宽度,高度),ImageLockMode.ReadOnly,fmt); 不安全的 { 字节*ptr; 对于(int y=0;y跨步).ToPointer()); 对于(int x=0;x解锁位(数据); 返回结果; } public Bitmap Visualize () { PixelFormat fmt = System.Drawing.Imaging.PixelFormat.Format24bppRgb; Bitmap result = new Bitmap( Width, Height, fmt ); BitmapData data = result.LockBits( new Rectangle( 0, 0, Width, Height ), ImageLockMode.ReadOnly, fmt ); unsafe { byte* ptr; for ( int y = 0; y < Height; y++ ) { ptr = (byte*)data.Scan0 + y * data.Stride; for ( int x = 0; x < Width; x++ ) { float num = 0.44; byte c = (byte)(255.0f * num); ptr[0] = ptr[1] = ptr[2] = c; ptr += 3; } } } result.UnlockBits( data ); return result; } Bitmap^ Visualize () { PixelFormat fmt = System::Drawing::Imaging::PixelFormat::Format24bppRgb; Bitmap^ result = gcnew Bitmap( Width, Height, fmt ); BitmapData^ data = result->LockBits( Rectangle( 0, 0, Width, Height ), ImageLockMode::ReadOnly, fmt ); for ( int y = 0; y < Height; y++ ) { unsigned char* ptr = reinterpret_cast<unsigned char*>((data->Scan0 + y * data->Stride).ToPointer()); for ( int x = 0; x < Width; x++ ) { float num = 0.44f; unsigned char c = static_cast<unsigned char>(255.0f * num); ptr[0] = ptr[1] = ptr[2] = c; ptr += 3; } } result->UnlockBits( data ); return result; }

将C中的位图转换为C++; 我认为对于使用C++中位图的人来说,这是一个简单的问题。我有一个C代码中的工作代码——如何在C++中做类似的事情?感谢您的代码(帮助):-) 公共位图可视化() { PixelFormat fmt=System.Drawing.Imaging.PixelFormat.Format24bppRgb; 位图结果=新位图(宽度、高度、fmt); BitmapData data=result.LockBits(新矩形(0,0,宽度,高度),ImageLockMode.ReadOnly,fmt); 不安全的 { 字节*ptr; 对于(int y=0;y跨步).ToPointer()); 对于(int x=0;x解锁位(数据); 返回结果; } public Bitmap Visualize () { PixelFormat fmt = System.Drawing.Imaging.PixelFormat.Format24bppRgb; Bitmap result = new Bitmap( Width, Height, fmt ); BitmapData data = result.LockBits( new Rectangle( 0, 0, Width, Height ), ImageLockMode.ReadOnly, fmt ); unsafe { byte* ptr; for ( int y = 0; y < Height; y++ ) { ptr = (byte*)data.Scan0 + y * data.Stride; for ( int x = 0; x < Width; x++ ) { float num = 0.44; byte c = (byte)(255.0f * num); ptr[0] = ptr[1] = ptr[2] = c; ptr += 3; } } } result.UnlockBits( data ); return result; } Bitmap^ Visualize () { PixelFormat fmt = System::Drawing::Imaging::PixelFormat::Format24bppRgb; Bitmap^ result = gcnew Bitmap( Width, Height, fmt ); BitmapData^ data = result->LockBits( Rectangle( 0, 0, Width, Height ), ImageLockMode::ReadOnly, fmt ); for ( int y = 0; y < Height; y++ ) { unsigned char* ptr = reinterpret_cast<unsigned char*>((data->Scan0 + y * data->Stride).ToPointer()); for ( int x = 0; x < Width; x++ ) { float num = 0.44f; unsigned char c = static_cast<unsigned char>(255.0f * num); ptr[0] = ptr[1] = ptr[2] = c; ptr += 3; } } result->UnlockBits( data ); return result; },c++,bitmap,unsafe,C++,Bitmap,Unsafe,您可以使用库执行非常类似的循环C++不包含任何有关图像或处理图像的内容。有许多库可用于此目的,并且每个库对数据的操作方式可能不同 在最基本的层面上,图像由一堆字节组成。如果您可以将数据(即,不是标题或其他元数据)提取到无符号字符[](或给定图像格式的其他适当类型)中,那么您可以像在C#示例中一样迭代每个像素。原始翻译到C++/CLI,我没有运行该示例,因此它可能包含一些打字错误。无论如何,在C++中得到相同的结果有不同的方法(因为你可以使用标准的CRT API)。 Bitmap^可视化() {

您可以使用库执行非常类似的循环

C++不包含任何有关图像或处理图像的内容。有许多库可用于此目的,并且每个库对数据的操作方式可能不同


在最基本的层面上,图像由一堆字节组成。如果您可以将数据(即,不是标题或其他元数据)提取到
无符号字符[]
(或给定图像格式的其他适当类型)中,那么您可以像在C#示例中一样迭代每个像素。

原始翻译到C++/CLI,我没有运行该示例,因此它可能包含一些打字错误。无论如何,在C++中得到相同的结果有不同的方法(因为你可以使用标准的CRT API)。
Bitmap^可视化()
{
PixelFormat fmt=System::Drawing::Imaging::PixelFormat::Format24bppRgb;
位图^result=gc新位图(宽度、高度、fmt);
BitmapData^data=result->LockBits(矩形(0,0,宽度,高度),ImageLockMode::ReadOnly,fmt);
对于(int y=0;y扫描0+y*数据->跨步).ToPointer());
对于(int x=0;x解锁位(数据);
返回结果;
}
public Bitmap Visualize ()
{


  PixelFormat fmt = System.Drawing.Imaging.PixelFormat.Format24bppRgb;
  Bitmap result = new Bitmap( Width, Height, fmt );

  BitmapData data = result.LockBits( new Rectangle( 0, 0, Width, Height ), ImageLockMode.ReadOnly, fmt );
  unsafe
  {
    byte* ptr;

    for ( int y = 0; y < Height; y++ )
    {
      ptr = (byte*)data.Scan0 + y * data.Stride;

      for ( int x = 0; x < Width; x++ )
      {
          float num = 0.44;
          byte c = (byte)(255.0f * num);
          ptr[0] = ptr[1] = ptr[2] = c;


          ptr += 3;
      }
    }
  }
  result.UnlockBits( data );

  return result;

}
Bitmap^ Visualize ()
{
  PixelFormat fmt = System::Drawing::Imaging::PixelFormat::Format24bppRgb;
  Bitmap^ result = gcnew Bitmap( Width, Height, fmt );

  BitmapData^ data = result->LockBits( Rectangle( 0, 0, Width, Height ), ImageLockMode::ReadOnly, fmt );
  for ( int y = 0; y < Height; y++ )
  {
    unsigned char* ptr = reinterpret_cast<unsigned char*>((data->Scan0 + y * data->Stride).ToPointer());

    for ( int x = 0; x < Width; x++ )
    {
        float num = 0.44f;
        unsigned char c = static_cast<unsigned char>(255.0f * num);
        ptr[0] = ptr[1] = ptr[2] = c;

        ptr += 3;
    }
  }

  result->UnlockBits( data );

  return result;

}