gpt4 book ai didi

c++ - 如何将 int 数组转换为位图对象?

转载 作者:太空宇宙 更新时间:2023-11-04 11:24:10 26 4
gpt4 key购买 nike

我有一个 int 数组,它是道路尽头的位图。我想暂时将数组转换为位图,以便在以最终形式呈现到屏幕之前对边缘进行一些平滑处理。我这里有平滑位图的代码:

//.h file code:

using namespace Emgu::CV;
using namespace Emgu::CV::Structure;

namespace Microsoft
{
namespace Samples
{
namespace Kinect
{
namespace BodyIndexBasics
{
/// <summary>
/// Class responsible for extracting out the contours of an image.
/// </summary>
class FindContours
{
/// <summary>
/// Method used to process the image and set the output result images.
/// </summary>
/// <param name="colorImage">Source color image.</param>
/// <param name="thresholdValue">Value used for thresholding.</param>
/// <param name="processedGray">Resulting gray image.</param>
/// <param name="processedColor">Resulting color image.</param>
public:
void IdentifyContours(Bitmap *colorImage, int thresholdValue, bool invert, Bitmap *&processedGray, Bitmap *&processedColor);
};
}
}
}
}

//.cpp file code:

using namespace Emgu::CV;
using namespace Emgu::CV::Structure;
namespace Microsoft
{
namespace Samples
{
namespace Kinect
{
namespace BodyIndexBasics
{

void FindContours::IdentifyContours(Bitmap *colorImage, int thresholdValue, bool invert, Bitmap *&processedGray, Bitmap *&processedColor)
{

BlurBitmapEffect *myBlurEffect = new BlurBitmapEffect();

Image<Gray*, unsigned char> *grayImage = new Image<Gray*, unsigned char>(colorImage);
Image<Bgr*, unsigned char> *color = new Image<Bgr*, unsigned char>(new Bitmap(colorImage->Width, colorImage->Height));



grayImage = grayImage->ThresholdBinary(new Gray(thresholdValue), new Gray(255));
if (invert)
{
grayImage->_Not();
}



MemStorage *storage = new MemStorage();
try
{
for (Contour<Point> contours = grayImage->FindContours(Emgu::CV::CvEnum::CHAIN_APPROX_METHOD::CV_CHAIN_APPROX_SIMPLE, Emgu::CV::CvEnum::RETR_TYPE::CV_RETR_TREE, storage); contours != nullptr; contours = contours->HNext)
{
Contour<Point> *currentContour = contours->ApproxPoly(contours->Perimeter * 0.015, storage);
if (currentContour->BoundingRectangle->Width > 20)
{
CvInvoke::cvDrawContours(color, contours, new MCvScalar(255), new MCvScalar(255), -1, 5, Emgu::CV::CvEnum::LINE_TYPE::EIGHT_CONNECTED, Point(0, 0));
}
}
}

finally
{
if (storage != nullptr)
{
storage.Dispose();
}
}



processedColor = color->ToBitmap();
processedGray = grayImage->ToBitmap();

}
}
}
}
}

我需要的是某种将 int 数组转换为位图的方法,以便我可以在渲染之前对其进行平滑处理。

//This is the int array that I want to convert temp
int* pOutputData = nullptr;
byte* pOutputDataByte = nullptr;
hr = spOutputBufferByteAccess->Buffer(&pOutputDataByte);
if (FAILED(hr))
{
return false;
}

pOutputData = (int*)pOutputDataByte;

DepthSpacePoint* pDepthPoints = m_depthPoints->Data;
byte* pBodyIndexFrameArray = bodyIndexframeArray->Data;

ZeroMemory(pOutputData, outputDataBuffer->Capacity);

int* pOutputData 是我想要转换的,以便我可以平滑它。

这有可能吗?

最佳答案

取决于您如何定义“位图”。位图是 GDI+ 位图吗?这是你创建的类(class)吗?它是一个带有字节映射的文件吗?

如果是 GDI+ Bitmap 那么:http://msdn.microsoft.com/en-us/library/windows/desktop/ms536312(v=vs.85).aspx构造函数将正常工作,如下所示(或 http://msdn.microsoft.com/en-us/library/windows/desktop/ms536288(v=vs.85).aspx ):

#include <gdiplus.h>

Gdiplus::Bitmap* CreateBitmap(void* data, unsigned int width, unsigned int height)
{
BITMAPINFO Info;
memset(&Info, 0, sizeof(Info));

Info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
Info.bmiHeader.biWidth = width;
Info.bmiHeader.biHeight = height;
Info.bmiHeader.biPlanes = 1;
Info.bmiHeader.biBitCount = 32;
Info.bmiHeader.biCompression = BI_RGB;
Info.bmiHeader.biSizeImage = 0; //(((32 * width + 31) & ~31) / 8) * height;

return new Gdiplus::Bitmap(&Info, data);
}

否则请在此处查看我对原始手动位图创建的回答:Incorrect Bitmap Copy/Output

关于c++ - 如何将 int 数组转换为位图对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27285521/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com