Esempio n. 1
0
	bool SmtSmfRasLayer::Fetch(eSmtFetchType type)
	{
		if (!IsOpen())
			return false;

		char szImgUrl[MAX_LAYER_FILE_NAME];

		SmtDataSourceInfo info;
		m_pOwnerDs->GetInfo(info);

		sprintf(szImgUrl,"%s",m_szLayerFileName);

		long lCodeType = GetImageTypeByFileExt(m_szLayerFileName);

		CxImage img;

		if (img.Load(szImgUrl,lCodeType))
		{
			BYTE *pImageBuf = NULL;
			long lImageBufSize = 0;
			fRect fLocRect;

			m_pMemLayer->GetRasterRect(fLocRect);
	
			fLocRect.rt.y  = fLocRect.lb.y + fLocRect.Width()*img.GetHeight()/img.GetWidth();

			if (img.Encode(pImageBuf,lImageBufSize,lCodeType))
			{
				return (SMT_ERR_NONE == m_pMemLayer->CreaterRaster((const char *)pImageBuf,lImageBufSize,fLocRect,lCodeType));
			}
		}

		return false;
	}
Esempio n. 2
0
  __declspec(dllexport) bool LoadImage(const char *file, unsigned int maxwidth, unsigned int maxheight, ImageInfo *info)
  {
    if (!file || !info) return false;

	if (IsDir(file))
		return false;

	  // load the image
    DWORD dwImageType = GetImageType(file);
    CxImage *image = new CxImage(dwImageType);
    if (!image) return false;

    int actualwidth = maxwidth;
    int actualheight = maxheight;
    try
    {
      if (!image->Load(file, dwImageType, actualwidth, actualheight) || !image->IsValid())
      {
#if !defined(_LINUX) && !defined(__APPLE__)
	    int nErr = GetLastError();
#else
	    int nErr = errno;
#endif
        printf("PICTURE::LoadImage: Unable to open image: %s Error:%s (%d)\n", file, image->GetLastError(),nErr);
        delete image;
        return false;
      }
    }
    catch (...)
    {
      printf("PICTURE::LoadImage: Unable to open image: %s\n", file);
      delete image;
      return false;
    }
    // ok, now resample the image down if necessary
    if (ResampleKeepAspect(*image, maxwidth, maxheight) < 0)
    {
      printf("PICTURE::LoadImage: Unable to resample picture: %s\n", file);
      delete image;
      return false;
    }

    // make sure our image is 24bit minimum
    image->IncreaseBpp(24);

    // fill in our struct
    info->width = image->GetWidth();
    info->height = image->GetHeight();
    info->originalwidth = actualwidth;
    info->originalheight = actualheight;
    memcpy(&info->exifInfo, image->GetExifInfo(), sizeof(EXIFINFO));

    // create our texture
    info->context = image;
    info->texture = image->GetBits();
    info->alpha = image->AlphaGetBits();
    return (info->texture != NULL);
  };
Esempio n. 3
0
HBITMAP CSkin::LoadImage(const char *filename)
{
  CxImage image;
  image.Load(filename);
  if(!image.IsValid()) {
    return NULL;
  }
  
  return image.MakeBitmap(NULL);
}
Esempio n. 4
0
CxImage* loadImage(const char* imagePath, DWORD imageType)
{
	CxImage* image = new CxImage;
	if (!image->Load(imagePath, imageType))
	{
		printf("get image error!\n");
		return NULL; 
	}
	return image;
}
Esempio n. 5
0
void EditToolbarUI::onPaint(__in HWND hWnd, __in WPARAM wParam, __in LPARAM lParam)
{	
	static CxImage toolBarImg;
	static CxImage toolBarHoverImg;
	static CxImage toolBarSelImg;

	BOOL bLoadResult = FALSE;
	if (!bLoadResult)
	{
		toolBarImg.Load(m_sToolbarInfo.m_strPicPath.c_str(), CXIMAGE_SUPPORT_PNG);
		toolBarHoverImg.Load(m_sToolbarInfo.m_strHoverPicPath.c_str(), CXIMAGE_SUPPORT_PNG);
		toolBarSelImg.Load(m_sToolbarInfo.m_strSelPicPath.c_str(), CXIMAGE_SUPPORT_PNG);

		bLoadResult = TRUE;
	}
	
	//draw background
	HDC hPaintDC = GetDC(m_hwnd);
	RECT rcWnd = {0};
	GetClientRect(m_hwnd, &rcWnd);
	toolBarImg.Draw(hPaintDC, rcWnd);

	if (m_iMouseMoveIdx >= 0)
	{
		//draw mouse move
		RECT &rcClip = m_sToolbarInfo.m_sItemRect[m_iMouseMoveIdx];
		toolBarHoverImg.Draw(hPaintDC, rcWnd, &rcClip, true);
	}

	if (m_iSelectIdx >= 0)
	{
		//draw selected
		RECT &rcClip = m_sToolbarInfo.m_sItemRect[m_iSelectIdx];
		toolBarSelImg.Draw(hPaintDC, rcWnd, &rcClip, true);
	}

	ReleaseDC(m_hwnd, hPaintDC);
}
Esempio n. 6
0
int main(int argc, char* argv[])
{
	CxImage image;

    if (argc<3) {
        fprintf(stderr, image.GetVersion());
        fprintf(stderr, "\nConsole demo\n");
        fprintf(stderr, "usage: %s input-file output-file\n", argv[0]);
        return 1;
    }

	CString filein(argv[1]);
	CString extin(FindExtension(filein));
	extin.MakeLower();
	int typein = FindFormat(extin);
	if (typein == CXIMAGE_FORMAT_UNKNOWN) {
        fprintf(stderr, "unknown extension for %s\n", argv[1]);
        return 1;
	}

	CString fileout(argv[2]);
	CString extout(FindExtension(fileout));
	extout.MakeLower();
	int typeout = FindFormat(extout);
	if (typeout == CXIMAGE_FORMAT_UNKNOWN) {
        fprintf(stderr, "unknown extension for %s\n", argv[2]);
        return 1;
	}


	if (!image.Load(argv[1],typein)){
        fprintf(stderr, "%s\n", image.GetLastError());
        fprintf(stderr, "error loading %s\n", argv[1]);
        return 1;
	}

	if (!image.Save(argv[2],typeout)){
        fprintf(stderr, "%s\n", image.GetLastError());
        fprintf(stderr, "error saving %s\n", argv[2]);
        return 1;
	}

	printf("Done!\n");
	return 0;
}
std::string UserListModule_Impl::getGrayLocalPathFromFilename(std::string& finename)
{
	CString csFileName = util::stringToCString(finename);
	CString csGrayAvatarPath = module::getMiscModule()->getDownloadDir() + PREFIX_GRAY_AVATAR + csFileName;
	//本地磁盘存在
	if (util::isFileExist(csGrayAvatarPath))
	{
		return util::cStringToString(csGrayAvatarPath);
	}
	else
	{
		//不存在则对图片做灰度处理并且保存到本地
		CxImage cximage;
		CString csAvatarPath = module::getMiscModule()->getDownloadDir() + csFileName;
		bool bSucc = cximage.Load(csAvatarPath);
		if (bSucc)
		{
			cximage.GrayScale();
			module::getCaptureModule()->saveToFile(cximage.MakeBitmap(), csAvatarPath);
		}
	}

	return "";
}
Esempio n. 8
0
  __declspec(dllexport) bool CreateFolderThumbnail(const char **file, const char *thumb, int maxWidth, int maxHeight)
  {
    if (!file || !file[0] || !file[1] || !file[2] || !file[3] || !thumb) return false;

    CxImage folderimage(maxWidth, maxHeight, 32, CXIMAGE_FORMAT_PNG);
    folderimage.AlphaCreate();
    int iWidth = maxWidth / 2;
    int iHeight = maxHeight / 2;
    for (int i = 0; i < 2; i++)
    {
      for (int j = 0; j < 2; j++)
      {
        int width = iWidth;
        int height = iHeight;
        bool bBlank = false;
        if (strlen(file[i*2 + j]) == 0)
          bBlank = true;
        if (!bBlank)
        {
          CxImage image;
          if (image.Load(file[i*2 + j], CXIMAGE_FORMAT_JPG, width, height))
          {
            // resize image to iWidth
            if (ResampleKeepAspect(image, iWidth - 2, iHeight - 2) >= 0)
            {
              int iOffX = (iWidth - 2 - image.GetWidth()) / 2;
              int iOffY = (iHeight - 2 - image.GetHeight()) / 2;
              for (int x = 0; x < iWidth; x++)
              {
                for (int y = 0; y < iHeight; y++)
                {
                  RGBQUAD rgb;
                  if (x < iOffX || x >= iOffX + (int)image.GetWidth() || y < iOffY || y >= iOffY + (int)image.GetHeight())
                  {
                    rgb.rgbBlue = 0; rgb.rgbGreen = 0; rgb.rgbRed = 0; rgb.rgbReserved = 0;
                  }
                  else
                  {
                    rgb = image.GetPixelColor(x - iOffX, y - iOffY);
                    rgb.rgbReserved = 255;
                  }
                  folderimage.SetPixelColor(x + j*iWidth, y + (1 - i)*iHeight, rgb, true);
                }
              }
            }
            else
              bBlank = true;
          }
          else
            bBlank = true;
        }
        if (bBlank)
        { // no image - just fill with black alpha
          for (int x = 0; x < iWidth; x++)
          {
            for (int y = 0; y < iHeight; y++)
            {
              RGBQUAD rgb;
              rgb.rgbBlue = 0; rgb.rgbGreen = 0; rgb.rgbRed = 0; rgb.rgbReserved = 0;
              folderimage.SetPixelColor(x + j*iWidth, y + (1 - i)*iHeight, rgb, true);
            }
          }
        }
      }
    }
    ::DeleteFile(thumb);
    if (!folderimage.Save(thumb, CXIMAGE_FORMAT_PNG))
    {
      printf("Unable to save thumb file");
      ::DeleteFile(thumb);
      return false;
    }
    return true;
  };
Esempio n. 9
0
void CCxImageARDlg::OnBnClickedBtnTemplate()
{
	// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
	if(cxImageARDoc.GetImage() != NULL){
		CxImage* cropImage = new CxImage;
		CxImage* templateImage = new CxImage;
		CxImage* buffer = cxImageARDoc.Binarization(original);
		
		TCHAR* templatePath[4];
		templatePath[0] = _T("..\\template\\template01.bmp");
		templatePath[1] = _T("..\\template\\template02.bmp");
		templatePath[2] = _T("..\\template\\template03.bmp");
		templatePath[3] = _T("..\\template\\template04.bmp");

		int width = original->GetWidth();
		int height = original->GetHeight();
		bool findmarker = false;
		const int search_window = 243;
		for(int k = 0; k < 1; k++){
			for(int y = 1; y < height-search_window; y+=4){
				for(int x = 1; x < width-search_window; x+=4){
					/* load template Image */
					templateImage->Load(templatePath[k], cxImageARDoc.FindType(templatePath[k]));
					templateImage = cxImageARDoc.Binarization(templateImage);

					/* extract the region of search window */
					cropImage = cxImageARDoc.extractRegion(CPointInt(x, y), CPointInt(x+search_window, y+search_window), buffer);
					
					/* Draw template and search window */
					CDC* pDC1, *pDC2;
					CRect rect1, rect2;
			
					pDC1 = m_pic_search.GetDC();
					m_pic_search.GetClientRect(&rect1);

					cropImage->Draw(pDC1->m_hDC, rect1);

					pDC2 = m_pic_template.GetDC();
					m_pic_template.GetClientRect(&rect2);

					templateImage->Draw(pDC2->m_hDC, rect2);


					ReleaseDC(pDC1);
					ReleaseDC(pDC2);

					/* template matching processing */
					cropImage->Resample(64, 64);
					if(cxImageARDoc.templateMatching(templateImage, cropImage)){
						/* if template matching is true, then draw the rect of matched area */
						RGBQUAD color;
						color.rgbBlue = 0;
						color.rgbGreen = 255;
						color.rgbRed = 0;
						cxImageARDoc.drawRect(CPointInt(x, y), CPointInt(x+search_window, y+search_window), result, color);
						findmarker = true;
						break;
					}
				}
				if(findmarker)	break;
			}
			if(findmarker)	break;
		}
		delete buffer;
		delete cropImage;
		delete templateImage;
	}
}