static unsigned char *red = NULL;
static unsigned char *green = NULL;
static unsigned char *blue = NULL;
wxImage ImagePaletteHandler(wxImage& image)
{
if(!red)
{
//1.暂时不释放,有内存泄露.
red = new unsigned char[256];
green = new unsigned char[256];
blue = new unsigned char[256];
for(int i = 0;i < 256;++i)
{
red[i]=green[i]=blue[i]=i;
}
}
wxPalette palette(256,red,green,blue);
assert(palette.IsOk());
image.SetPalette(palette);
image.SetOption(wxIMAGE_OPTION_BMP_FORMAT,wxBMP_8BPP);//设置为8位深度
//内存输出流 把文件写为内存数据
wxMemoryOutputStream *output_stream = new wxMemoryOutputStream();
image.SaveFile(*output_stream,wxBITMAP_TYPE_BMP);
//内存输入流 把流中的内存数据读为文件。
wxMemoryInputStream *input_stream = new wxMemoryInputStream(*output_stream);
wxImage m_image(*input_stream,wxBITMAP_TYPE_BMP);
delete output_stream;
delete input_stream;
return m_image;
}
[wxWidgets]_[初级]_[使用调色版对图片进行调色]
最新推荐文章于 2022-12-29 17:07:03 发布