【冬日绘版】如何把图片转成冬日绘版格式
  • 板块灌水区
  • 楼主donghanwen1225
  • 当前回复4
  • 已保存回复4
  • 发布时间2021/12/30 20:15
  • 上次更新2023/10/28 13:20:36
查看原帖
【冬日绘版】如何把图片转成冬日绘版格式
153687
donghanwen1225楼主2021/12/30 20:15

RT,本蒟蒻目前写了一个转换器,但是效果比较阴间,请问各位巨佬有比较优秀的转换器吗?
附一个本蒟蒻的代码:

#include<iostream>
#include<windows.h>
#include<string>
#include<gdiplus.h>
#include<cmath>
#pragma comment(lib,"gdiplus.lib")
using namespace std;
using namespace Gdiplus;
int c[101][3]={
	{0, 0, 0},
	{255, 255, 255},
	{170, 170, 170},
	{85, 85, 85},
	{254, 211, 199},
	{255, 196, 206},
	{250, 172, 142},
	{255, 139, 131},
	{244, 67, 54},
	{233, 30, 99},
	{226, 102, 158},
	{156, 39, 176},
	{103, 58, 183},
	{63, 81, 181},
	{0, 70, 112},
	{5, 113, 151},
	{33, 150, 243},
	{0, 188, 212},
	{59, 229, 219},
	{151, 253, 220},
	{22, 115, 0},
	{55, 169, 60},
	{137, 230, 66},
	{215, 255, 7},
	{255, 246, 209},
	{248, 203, 140},
	{255, 235, 59},
	{255, 193, 7},
	{255, 152, 0},
	{255, 87, 34},
	{184, 63, 39},
	{121, 85, 72}
};
const int sl=32;
int mabs(int x){return x<0?-x:x;}
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
   UINT  num = 0;          // number of image encoders
   UINT  size = 0;         // size of the image encoder array in bytes

   ImageCodecInfo* pImageCodecInfo = NULL;

   GetImageEncodersSize(&num, &size);
   if(size == 0)
      return -1;  // Failure

   pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
   if(pImageCodecInfo == NULL)
      return -1;  // Failure

   GetImageEncoders(num, size, pImageCodecInfo);

   for(UINT j = 0; j < num; ++j)
   {
      if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
      {
         *pClsid = pImageCodecInfo[j].Clsid;
         free(pImageCodecInfo);
         return j;  // Success
      }    
   }

   free(pImageCodecInfo);
   return -1;  // Failure
}
int main()
{
	GdiplusStartupInput gdiplusstartupinput;
    ULONG_PTR gdiplustoken;
    GdiplusStartup(&gdiplustoken, &gdiplusstartupinput, NULL);
	
	Bitmap* bmp=new Bitmap(L"small.bmp");
	int h=bmp->GetHeight();
	int w=bmp->GetWidth();
	
	Color col;
	for(int i=0;i<w;i++)
		for(int j=0;j<h;j++)
		{
			bmp->GetPixel(i,j,&col);
			int r=col.GetR();
			int g=col.GetG();
			int b=col.GetB();
			int wz;
			double minn=1e15;
			for(int k=0;k<sl;k++)
			{
				int now1=mabs(r-c[k][0]),now2=mabs(g-c[k][1]),now3=mabs(b-c[k][2]);
				double tmp1=sqrt(now1*now1+now2*now2+now3*now3);
				double tmp2=now1+now2+now3;
				double now=(tmp1+tmp2)/2;
				if(now<minn)
				{
					minn=now;
					wz=k;
				}
			}
			Color color(c[wz][0],c[wz][1],c[wz][2]);
			bmp->SetPixel(i,j,color);
		}
	CLSID tmp;
	GetEncoderClsid(L"image/bmp",&tmp);
	bmp->Save(L"test.bmp",&tmp,NULL);
	GdiplusShutdown(gdiplustoken);
 	return 0;
}
2021/12/30 20:15
加载中...