コード例 #1
1
void TVizMapContext::Export(const TStr& FNm, const TStr& EncoderType, const int& Width, 
        const int& Height, const bool& ShowPointNmP, const int& PointFontSize, 
        const int& PointNmFontScale, const double& PointWgtThreshold, const bool& ShowCatNmP,
        const bool& ShowKeyWdP, const int& KeyWdFontSize, const bool& ShowMgGlassP, 
        const int& LegendGridWidth, const int& LegendGridHeight) {

    // create graphics
    Gdiplus::Bitmap* Bmp = new Gdiplus::Bitmap(Width, Height);
    Gdiplus::Graphics* g = Gdiplus::Graphics::FromImage(Bmp);
    PGks BmpGks = TWfGks::New();
    // paint graphics
    HDC HdcHandle = g->GetHDC(); BmpGks->BeginPaint(HdcHandle);
    Paint(BmpGks, ShowPointNmP, PointFontSize, PointNmFontScale,
        PointWgtThreshold, -1, ShowCatNmP, ShowKeyWdP, KeyWdFontSize, ShowMgGlassP, 
        LegendGridWidth, LegendGridHeight);
    BmpGks->EndPaint(); g->ReleaseHDC(HdcHandle);
    // save to disk
    WCHAR* FNmWChar = new WCHAR[FNm.Len() + 1];
    const int Res = MultiByteToWideChar(CP_ACP, 0, 
        FNm.CStr(), FNm.Len() + 1, FNmWChar, FNm.Len() + 1);
    CLSID pngClsid; GetEncoderClsid(EncoderType, &pngClsid);
    Bmp->Save(FNmWChar, &pngClsid, NULL);
    // clean after
    delete FNmWChar; delete Bmp; delete g;
}
コード例 #2
0
ファイル: PictureHandler.cpp プロジェクト: BigkoalaZhu/Recall
//=================================================================================
//	SavePicture
//
//	Overloaded version of the above
//=================================================================================
void PictureHandler::SavePicture(
	UINT*&				imgBuffer,
	int					width,
	int					height,
	string&				outFilename,
	string&				saveLocation,
	int					format,
	const string&		str)// 0 is for BMP and 1 for JPEG
{
	int sz = width*height;

	Bitmap bmp(width, height, width*sizeof(UINT), PixelFormat32bppARGB, (unsigned char *)imgBuffer);

	//-----------------------------------------
	// Prepare path and save the result images
	//-----------------------------------------
	CLSID picClsid;
	if( 1 == format ) GetEncoderClsid(L"image/jpeg", &picClsid);
	if( 0 == format ) GetEncoderClsid(L"image/bmp",  &picClsid);

	string path = saveLocation;
	char fname[_MAX_FNAME];
	_splitpath(outFilename.c_str(), NULL, NULL, fname, NULL);
	path += fname;

	if( 0 != str.compare("") ) path.append(str);
	if( 1 == format ) path.append(".jpg");
	if( 0 == format ) path.append(".bmp");

	wstring wholepath = Narrow2Wide(path);
	const WCHAR* wp = wholepath.c_str();

	Status st = bmp.Save( wp, &picClsid, NULL );
	_ASSERT( st == Ok );
}
コード例 #3
0
ファイル: EditTiffUnit.cpp プロジェクト: ands904/SEnum
static void __fastcall StopSaveBitmap2Tiff(void) {
//-------------------------------------------------------------------------------
//                      Закрывает вывод страниц в *.tif                         |
//-------------------------------------------------------------------------------
    if (SaveBitmap2TiffState == 0) return;

    if (SaveBitmap2TiffState == 2) {
        Gdiplus::EncoderParameters encoderParameters;
        ULONG parameterValue;
        CLSID encoderClsid;
        encoderParameters.Count = 1;
        encoderParameters.Parameter[0].Guid = aEncoderSaveFlag;
        encoderParameters.Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong;
        encoderParameters.Parameter[0].NumberOfValues = 1;
        encoderParameters.Parameter[0].Value = &parameterValue;
        GetEncoderClsid(L"image/tiff", &encoderClsid);
        parameterValue = Gdiplus::EncoderValueFlush;
        sres = SaveBitmap2TiffBitmap1->SaveAdd(&encoderParameters);
    }

    delete[] SaveBitmap2TiffFiln; SaveBitmap2TiffFiln = NULL;
    delete SaveBitmap2TiffBitmap32; SaveBitmap2TiffBitmap32 = NULL;
    delete SaveBitmap2TiffGraphics; SaveBitmap2TiffGraphics = NULL;
    delete SaveBitmap2TiffBitmap1; SaveBitmap2TiffBitmap1 = NULL;

    SaveBitmap2TiffState = 0;
}
コード例 #4
0
ファイル: io-gdip-utils.c プロジェクト: chipx86/gtk
gboolean
gdip_save_pixbuf (GdkPixbuf *pixbuf,
                  const WCHAR *format,
                  const EncoderParameters *encoder_params,
                  GdkPixbufSaveFunc save_func,
                  gpointer user_data,
                  GError **error)
{
  GpBitmap *image;
  CLSID clsid;
  gboolean success;

  if (!GetEncoderClsid (format, &clsid)) {
    g_set_error_literal (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_FAILED, _("Unsupported image format for GDI+"));
    return FALSE;
  }
  
  image = gdip_pixbuf_to_bitmap (pixbuf);

  if (image == NULL) {
    g_set_error_literal (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_FAILED, _("Couldn't save"));
    return FALSE;
  }
  
  success = gdip_save_bitmap_to_callback (image, &clsid, encoder_params, save_func, user_data, error);

  GdipDisposeImage ((GpImage *)image);

  return success;
}
コード例 #5
0
ファイル: sea_itt_lib.cpp プロジェクト: 01org/IntelSEAPI
bool ConvertToGif(Gdiplus::GpBitmap* pBitmap, LPCWSTR szGifPath)
{
    CLSID clsid = {};
    if (!GetEncoderClsid(L"image/gif", &clsid))
        return false;

    return Gdiplus::Ok == GdiPlusFn::Get<FGdipSaveImageToFile>("GdipSaveImageToFile")(pBitmap, szGifPath, &clsid, nullptr);
}
コード例 #6
0
ファイル: PictureHandler.cpp プロジェクト: BigkoalaZhu/Recall
//=================================================================================
//	SavePicture
//
//	Saves the given buffer as a JPEG or BMP image depeding on which encoder CLSID
//	is used.
//=================================================================================
void PictureHandler::SavePicture(
	vector<UINT>&		imgBuffer,
	int					width,
	int					height,
	string&				outFilename,
	string&				saveLocation,
	int					format,
	const string&		str)// 0 is for BMP and 1 for JPEG
{
	int sz = width*height;
	UINT* uintBuffer = new UINT[sz];

	for( int p = 0; p < sz; p++ ) uintBuffer[p] = imgBuffer[p];

	Bitmap bmp(width, height, width*sizeof(UINT), PixelFormat32bppARGB, (unsigned char *)uintBuffer);

	//-----------------------------------------
	// Prepare path and save the result images
	//-----------------------------------------
	CLSID picClsid;
	if( 1 == format ) GetEncoderClsid(L"image/jpeg", &picClsid);
	if( 0 == format ) GetEncoderClsid(L"image/bmp",  &picClsid);

	//string path = "C:\\Temp\\";
	string path = saveLocation;
	//string fpath = Wide2Narrow(outFilename);
	char fname[_MAX_FNAME];
	_splitpath(outFilename.c_str(), NULL, NULL, fname, NULL);
	//int dummy(0);
	//_splitpath_s(outFilename.c_str(), NULL, dummy, NULL, dummy, fname, dummy, NULL, dummy);
	path += fname;

	//if( 0 == strcmp(str.c_str(),"") ) path.append(str);
	if( 0 != str.compare("") ) path.append(str);
	if( 1 == format ) path.append(".jpg");
	if( 0 == format ) path.append(".bmp");

	wstring wholepath = Narrow2Wide(path);
	const WCHAR* wp = wholepath.c_str();

	Status st = bmp.Save( wp, &picClsid, NULL );
	_ASSERT( st == Ok );

	if(uintBuffer) delete [] uintBuffer;
}
コード例 #7
0
ファイル: EngineDump.cpp プロジェクト: Nargesf/Sumatrapdf
bool RenderDocument(BaseEngine *engine, const WCHAR *renderPath, float zoom=1.f, bool silent=false)
{
    if (!CheckRenderPath(renderPath))
        return false;

    if (str::EndsWithI(renderPath, L".txt")) {
        str::Str<WCHAR> text(1024);
        for (int pageNo = 1; pageNo <= engine->PageCount(); pageNo++)
            text.AppendAndFree(engine->ExtractPageText(pageNo, L"\r\n", NULL, Target_Export));
        if (silent)
            return true;
        ScopedMem<WCHAR> txtFilePath(str::Format(renderPath, 0));
        ScopedMem<char> textUTF8(str::conv::ToUtf8(text.Get()));
        ScopedMem<char> textUTF8BOM(str::Join(UTF8_BOM, textUTF8));
        return file::WriteAll(txtFilePath, textUTF8BOM, str::Len(textUTF8BOM));
    }

    if (str::EndsWithI(renderPath, L".pdf")) {
        if (silent)
            return false;
        ScopedMem<WCHAR> pdfFilePath(str::Format(renderPath, 0));
        return engine->SaveFileAsPDF(pdfFilePath, true) || PdfCreator::RenderToFile(pdfFilePath, engine);
    }

    bool success = true;
    for (int pageNo = 1; pageNo <= engine->PageCount(); pageNo++) {
        RenderedBitmap *bmp = engine->RenderBitmap(pageNo, zoom, 0);
        success &= bmp != NULL;
        if (!bmp && !silent)
            ErrOut("Error: Failed to render page %d for %s!", pageNo, engine->FileName());
        if (!bmp || silent) {
            delete bmp;
            continue;
        }
        ScopedMem<WCHAR> pageBmpPath(str::Format(renderPath, pageNo));
        if (str::EndsWithI(pageBmpPath, L".png")) {
            Bitmap gbmp(bmp->GetBitmap(), NULL);
            CLSID pngEncId = GetEncoderClsid(L"image/png");
            gbmp.Save(pageBmpPath, &pngEncId);
        }
        else if (str::EndsWithI(pageBmpPath, L".bmp")) {
            size_t bmpDataLen;
            ScopedMem<char> bmpData((char *)SerializeBitmap(bmp->GetBitmap(), &bmpDataLen));
            if (bmpData)
                file::WriteAll(pageBmpPath, bmpData, bmpDataLen);
        }
        else { // render as TGA for all other file extensions
            size_t tgaDataLen;
            ScopedMem<unsigned char> tgaData(tga::SerializeBitmap(bmp->GetBitmap(), &tgaDataLen));
            if (tgaData)
                file::WriteAll(pageBmpPath, tgaData, tgaDataLen);
        }
        delete bmp;
    }

    return success;
}
コード例 #8
0
ファイル: GDIPluseEx.cpp プロジェクト: awendemo/Ghca-RasHook
BOOL GDIPluseExt::SaveScreenToJpg(CRect rect)
{
	// 得到屏幕DC
	HWND hDeskWnd = ::GetDesktopWindow();                        //获得屏幕的HWND. 
	CDC *pDestDC = CDC::FromHandle(::GetDC(hDeskWnd));           //获取当前整个屏幕DC
	int Width = rect.Width();                                    //宽
	int Height = rect.Height();                                  //高

	// 创建与屏幕兼容的Bitmap 
	CBitmap memBitmap;   
	memBitmap.CreateCompatibleBitmap(pDestDC, Width, Height);

	// 创建屏幕的内存DC
	CDC memDC;     
	memDC.CreateCompatibleDC(pDestDC);

	// 将兼容Bitmap格式选入内存DC
	memDC.SelectObject(&memBitmap);

	// 将屏幕DC数据copy至内存DC
	memDC.BitBlt(0, 0, Width, Height, pDestDC, 0, 0, SRCCOPY); 

	// 获得位图信息
	BITMAP bmpInfo;
	memBitmap.GetBitmap(&bmpInfo);

	// 生成BITMAPINFO
	BITMAPINFO m_BITMAPINFO;
	memset(&m_BITMAPINFO, 0, sizeof(BITMAPINFO));
	m_BITMAPINFO.bmiHeader.biSize     = sizeof(BITMAPINFOHEADER);
	m_BITMAPINFO.bmiHeader.biPlanes     = 1;
	m_BITMAPINFO.bmiHeader.biBitCount    = bmpInfo.bmBitsPixel;
	m_BITMAPINFO.bmiHeader.biCompression   = BI_RGB;
	m_BITMAPINFO.bmiHeader.biWidth     = bmpInfo.bmWidth;
	m_BITMAPINFO.bmiHeader.biHeight     = bmpInfo.bmHeight;

	// 获取位图数据
	BYTE * pBuffer = new BYTE[bmpInfo.bmWidthBytes * bmpInfo.bmHeight];
	GetDIBits(memDC.m_hDC, (HBITMAP) memBitmap.m_hObject, 0, Height, pBuffer,
		(LPBITMAPINFO) &m_BITMAPINFO, DIB_RGB_COLORS);

	// 生成位图
	Bitmap *pSrcBmp = Bitmap::FromBITMAPINFO(&m_BITMAPINFO, (void*)pBuffer);

	// 保存成jpg文件
	CLSID encoderClsid;
	GetEncoderClsid(L"image/jpeg", &encoderClsid);
	pSrcBmp-> Save(L"destop.jpg", &encoderClsid);

	// 释放内存
	delete pSrcBmp;
	delete pBuffer;
	AfxGetMainWnd()->ReleaseDC(pDestDC);
	return TRUE;
}
コード例 #9
0
ファイル: GdiPlusImage.cpp プロジェクト: HuugY/MFC_Project
bool CGdiPlusImage::Save(LPCTSTR pszFileName,LPCTSTR format)
{
	//╪стьнд╪Ч
	CT2CW strFileName(pszFileName);

	//м╪оЯ╠ё╢Ф
	CLSID Clsid;
	GetEncoderClsid(format, &Clsid);
	if( m_pImage->Save((LPCWSTR)strFileName, &Clsid) == Ok )
		return true;

	return false;
}
コード例 #10
0
bool CGdiPlusImage::Save(LPCTSTR pszFileName,LPCTSTR format)
{
    //¼ÓÔØÎļþ
    CT2CW strFileName(pszFileName);

    //ͼÏñ±£´æ
    CLSID Clsid;
    GetEncoderClsid(format, &Clsid);
    if( m_pImage->Save((LPCWSTR)strFileName, &Clsid) == Ok )
        return true;

    return false;
}
コード例 #11
0
ファイル: JpegExporter.cpp プロジェクト: LiDongbao/YAP
		void ExportImage(T* image, int width, int height, const wchar_t * output_folder, bool stretch_pixel_data)
		{
			boost::shared_array<unsigned char> buffer(new unsigned char[width * height * 4]);
			T* data_cursor = image;

			auto result = std::minmax_element(data_cursor, data_cursor + width * height);
			T min_data = *result.first;
			T max_data = *result.second;

			for (unsigned char* buffer_cursor = buffer.get(); buffer_cursor < buffer.get() + width * height * 4; buffer_cursor += 4)
			{
				unsigned short temp;
				if (stretch_pixel_data)
				{
					temp = StretchPixelData(data_cursor, min_data, max_data);
				}
				else
				{
					temp = static_cast<unsigned short>(*data_cursor);
				}
				if (data_cursor == NULL)
				{
					break;
				}
				*buffer_cursor = *(buffer_cursor + 1) = *(buffer_cursor + 2) = static_cast<unsigned char>(temp);
				*(buffer_cursor + 3) = 255;
				++data_cursor;
			}

			Gdiplus::Bitmap bitmap(width, height, width * 4, PixelFormat32bppRGB, buffer.get());
			CLSID  encoderClsid;
			if (!GetEncoderClsid(L"image/jpeg", &encoderClsid))
			{
				return;
			}
			wostringstream file_name;
			static unsigned int jpeg_index = 0;
			file_name << ++jpeg_index;

			wstring file_path = output_folder;
			if (wcslen(output_folder) > 3)
			{
				file_path += L"\\";
			}
			file_path += file_name.str();
			file_path += L".jpg";

			Gdiplus::Status status = bitmap.Save(const_cast<wchar_t*>(file_path.c_str()), &encoderClsid, NULL);
		}
コード例 #12
0
void SaveThumbnail(DisplayState& ds) {
    if (!ds.thumbnail) {
        return;
    }

    AutoFreeW bmpPath(GetThumbnailPath(ds.filePath));
    if (!bmpPath) {
        return;
    }
    AutoFreeW thumbsPath(path::GetDir(bmpPath));
    if (dir::Create(thumbsPath)) {
        CrashIf(!str::EndsWithI(bmpPath, L".png"));
        Bitmap bmp(ds.thumbnail->GetBitmap(), nullptr);
        CLSID tmpClsid = GetEncoderClsid(L"image/png");
        bmp.Save(bmpPath.Get(), &tmpClsid, nullptr);
    }
}
コード例 #13
0
BOOL GdiPlusPicDrawer::SaveFilePrivate(Image* pImage, LPCTSTR imgFile, ImageFormatEnum imageFormat)
{
	CLSID pngClsid;
	Status st = GenericError;
	LPCTSTR type = L"image/png";
	switch (imageFormat)
	{
	case IF_jpg:
		type = L"image/jpg";
		break;
	case IF_png:
	default:
		break;
	}
	if (GetEncoderClsid(type, &pngClsid))
		st = pImage->Save(imgFile, &pngClsid, NULL);
	return st == Ok;
}
コード例 #14
0
ファイル: Utils.cpp プロジェクト: 0xmono/miranda-ng
void SaveGIF(HBITMAP hBmp, TCHAR* szFilename) {
	Gdiplus::GdiplusStartupInput gdiplusStartupInput;
	ULONG_PTR                    gdiplusToken;
	Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

	Gdiplus::Bitmap *pBitmap = Gdiplus::Bitmap::FromHBITMAP(hBmp, (HPALETTE)GetStockObject(DEFAULT_PALETTE) );
	if( pBitmap ) {
		// Get the CLSID of the GIF encoder.
		CLSID clsidEncoder;
		if( GetEncoderClsid(L"image/gif", clsidEncoder)) {
			LPWSTR pswFile = mir_t2u(szFilename);
			pBitmap->Save((const WCHAR*)pswFile, &clsidEncoder, NULL);
			mir_free(pswFile);
		}
		delete pBitmap;
	}
	Gdiplus::GdiplusShutdown(gdiplusToken);
}
コード例 #15
0
ファイル: fileCore.cpp プロジェクト: jcampos73/DraftCable
int savebmp(HBITMAP hbm,HPALETTE hpal,const wchar_t *lpszCodec,LPCTSTR lpszPath)
{


   // Initialize GDI+.
   //GdiplusStartupInput gdiplusStartupInput;
   //ULONG_PTR gdiplusToken;
   //GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

   CLSID   encoderClsid;
   Status  stat;
   //Image*   image = new Image(L"sample.png");
   Bitmap*   image = new Bitmap(hbm,hpal);

   // Get the CLSID of the PNG encoder.
   //GetEncoderClsid(L"image/gif", &encoderClsid);
   GetEncoderClsid(lpszCodec, &encoderClsid);

   #ifndef UNICODE 

		wchar_t wszPath[MAX_PATH+1];
		char szPath[MAX_PATH+1];

		mbstowcs( wszPath, lpszPath, sizeof(wszPath) );

		wcstombs(szPath, wszPath, sizeof(szPath));

   #endif

	stat = image->Save(lpszPath, &encoderClsid, NULL);

   if(stat == Ok)
      printf("Bird.png was saved successfully\n");
   else
      printf("Failure: stat = %d\n", stat); 

   delete image;
   //GdiplusShutdown(gdiplusToken);
   return 0;
}
コード例 #16
0
ファイル: Utils.cpp プロジェクト: kxepal/miranda-ng
void SaveTIF(HBITMAP hBmp, TCHAR* szFilename)
{
	//http://www.codeproject.com/Messages/1406708/How-to-reduce-the-size-of-an-Image-using-GDIplus.aspx
	ULONG_PTR						gdiplusToken;
	Gdiplus::GdiplusStartupInput	gdiplusStartupInput;
	Gdiplus::Status stat;
	Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

	Gdiplus::Bitmap *pBitmap = Gdiplus::Bitmap::FromHBITMAP(hBmp, (HPALETTE)GetStockObject(DEFAULT_PALETTE));
	if (pBitmap) {
		// Get the CLSID of the GIF encoder.
		CLSID EncCLSID;
		if (GetEncoderClsid(L"image/tiff", EncCLSID)) {
			//--- Create a 2-parameter array, for Compression and for Color Bit depth
			Gdiplus::EncoderParameters* EncParams = (Gdiplus::EncoderParameters*) malloc(sizeof(Gdiplus::EncoderParameters) + 1 * sizeof(Gdiplus::EncoderParameter));
			//	Gdiplus::EncoderParameters pEncoderParameters;
			//--- Use LZW Compression instead of Group 4, since it works for color and G4 doesn't
			ULONG ulCompression = Gdiplus::EncoderValueCompressionLZW;
			ULONG ulColorDepth = 24L;

			EncParams->Count = 2;
			EncParams->Parameter[0].Guid = Gdiplus::EncoderCompression;
			EncParams->Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong;
			EncParams->Parameter[0].NumberOfValues = 1;
			EncParams->Parameter[0].Value = &ulCompression;
			EncParams->Parameter[1].Guid = Gdiplus::EncoderColorDepth;
			EncParams->Parameter[1].Type = Gdiplus::EncoderParameterValueTypeLong;
			EncParams->Parameter[1].NumberOfValues = 1;
			EncParams->Parameter[1].Value = &ulColorDepth;

			LPWSTR pswFile = mir_t2u(szFilename);
			stat = pBitmap->Save((const WCHAR*)pswFile, &EncCLSID, EncParams);
			mir_free(pswFile);
			free(EncParams);
		}
		delete pBitmap;
	}
	Gdiplus::GdiplusShutdown(gdiplusToken);
}
コード例 #17
0
ファイル: giimagep.cpp プロジェクト: acekiller/touchvg
bool GiGdipImage::getEncoder(const wchar_t* filename, WCHAR format[20], CLSID& clsidEncoder)
{
    const wchar_t* ext = filename ? wcsrchr(filename, '.') : NULL;
    if (NULL == ext)
        return false;

    int i = s_extCount;
    while (--i >= 0)
    {
        if (lstrcmpiW(s_extEncoders[i].szFileExt, ext) == 0)
        {
            if (NULL == s_Encoders[i].encoderType)
            {
                GetEncoderClsid(s_extEncoders[i].encoderType, &s_Encoders[i].clsidEncoder);
                s_Encoders[i].encoderType = s_extEncoders[i].encoderType;
            }
            lstrcpyW(format, s_extEncoders[i].encoderType);
            clsidEncoder = s_Encoders[i].clsidEncoder;
            break;
        }
    }

    return i >= 0;
}
コード例 #18
0
ファイル: system.cpp プロジェクト: AlloyTeam/webtop
void SaveBitmap(Bitmap* pbm, wstring path){
	CLSID tiffClsid;
	GetEncoderClsid((L"image/"+ GetExtW(path)).data(), &tiffClsid);
	pbm->Save(path.data(), &tiffClsid);
}
コード例 #19
0
ファイル: CreateKMZ.cpp プロジェクト: SimonL66/OziGen
bool CreateKMZ(long minx, long maxx, long miny, long maxy, LPCSTR mapname, long tileWidth, long tileHeight, long trackSize, int nDatabase, int nDrawOrder) // int nProduct, int nCountry, int nLayer)
{
unsigned char * bitmap_memory = NULL;

long bitmap_width, dest_bitmap_width;
long bitmap_height, dest_bitmap_height;

long bitmap_memory_size;
unsigned char bitmap_palette[1024];
long bitmap_palette_length;

int nMetres = MyMap.GetMetresPerTile();
int nPixels = MyMap.GetPixelsPerTile();

double dTileScale = (double) nMetres / nPixels;

//dTileScale = 1.0;

	CProgressWindow wndProgress;
	wndProgress.Initialize();

	CString str_fname;

	str_fname.Format("%s.txf", mapname);
	read_txf(str_fname, &nPoints, &points);

	str_fname.Format("%s.png", mapname);

	if (minx > maxx) {
		long t = minx;
		minx = maxx;
		maxx = t;
	}
	if (miny > maxy) {
		long t = miny;
		miny = maxy;
		maxy = t;
	}

// ToDo: Need to make collar work for OSM and OSPro etc. 
//	long collar = CalculateCollar(minx/**1000*/, maxx/**1000*/, miny/**1000*/, maxy/**1000*/);
/*
	long collar = 1;
	minx -= (collar/nMetres)*nMetres;
	maxx += (collar/nMetres)*nMetres;
	miny -= (collar/nMetres)*nMetres;
	maxy += (collar/nMetres)*nMetres;
*/
	wndProgress.ResetProgressBar("Tile:", ((maxy-miny)*(maxx-minx)/nMetres*nMetres));

	bool successful = false;

	if (nDatabase == DBASE_LOCAL) {

		if (MyMap.GetCountry() == COUNTRY_FR && MyMap.GetProduct() == PRODUCT_02) {

			successful = IGN_ReadTiles(minx, maxx, miny, maxy, wndProgress, 
							bitmap_palette, bitmap_palette_length, 
							bitmap_memory , bitmap_memory_size, 
							bitmap_width, dest_bitmap_width,
							bitmap_height, dest_bitmap_height);
		} else {

			successful = OSPro_ReadTiles(minx, maxx, miny, maxy, wndProgress, 
										bitmap_palette, bitmap_palette_length, 
										bitmap_memory , bitmap_memory_size, 
										bitmap_width, dest_bitmap_width,
										bitmap_height, dest_bitmap_height);

		}

	} else {

		bool b_use_TL3 = nDatabase == DBASE_TRACKLOGS_3;

		successful = ReadTracklogsTile(minx, maxx, miny, maxy, wndProgress, 
										bitmap_palette, bitmap_palette_length, 
										bitmap_memory , bitmap_memory_size, 
										bitmap_width, dest_bitmap_width,
										bitmap_height, dest_bitmap_height,
										b_use_TL3);
	}

	if (!successful) {
		if (bitmap_memory)
			free(bitmap_memory);
		return false;
	}

	if (bitmap_memory == NULL) {
		printf("No images to process\n");
		return false;
	}


	Gdiplus::GdiplusStartupInput gdiplusStartupInput;
	ULONG_PTR gdiplusToken;
	Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

	CLSID	encoderClsid;
	// Get the CLSID of the JPEG encoder.
	GetEncoderClsid(L"image/jpeg", &encoderClsid);

	Gdiplus::EncoderParameters encoderParameters;
	encoderParameters.Count = 1;
	ULONG quality = 80;
	encoderParameters.Parameter[0].Guid = Gdiplus::EncoderQuality;
	encoderParameters.Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong;
	encoderParameters.Parameter[0].NumberOfValues = 1;
	encoderParameters.Parameter[0].Value = &quality;

	// xy
	// 00 10 20 30 40
	// 01 11 21 31 41
	// 02 12 22 32 42
	// 03 13 23 33 43
	if ((MyMap.GetProjection() == 3857) || (MyMap.GetProjection() == 900913)) {
		nMetres = 1;
	} else {
		nMetres = 1000;
	}
// Note: 1000 is the rotatey collar!
/*
	minx *= 1000;
	maxx *= 1000;
	miny *= 1000;
	maxy *= 1000;
*/

	double lat,lon;
	OZIGEN_NorthingEasting_to_LatLon(maxy-nMetres, minx+nMetres, &lat, &lon);
	double minlat = lat;
	double maxlat = lat;
	double minlon = lon;
	double maxlon = lon;
	OZIGEN_NorthingEasting_to_LatLon(maxy-nMetres, maxx-nMetres, &lat, &lon);
	if (lat < minlat) minlat = lat;
	if (lat > maxlat) maxlat = lat;
	if (lon < minlon) minlon = lon;
	if (lon > maxlon) maxlon = lon;
	OZIGEN_NorthingEasting_to_LatLon(miny+nMetres, minx+nMetres, &lat, &lon);
	if (lat < minlat) minlat = lat;
	if (lat > maxlat) maxlat = lat;
	if (lon < minlon) minlon = lon;
	if (lon > maxlon) maxlon = lon;
	OZIGEN_NorthingEasting_to_LatLon(miny+nMetres, maxx-nMetres, &lat, &lon);
	if (lat < minlat) minlat = lat;
	if (lat > maxlat) maxlat = lat;
	if (lon < minlon) minlon = lon;
	if (lon > maxlon) maxlon = lon;

/* SNL 24/10/2013 are these only used for display purposes?

//	printf("%d %d %d %d\n\n", minx+1000, miny+1000, maxx-1000, maxy-1000);
	OZIGEN_LatLon_to_NorthingEasting(minlat, minlon, &lat, &lon);
//	printf("%f %f %f %f\n", minlat, minlon, lat, lon);
	OZIGEN_LatLon_to_NorthingEasting(minlat, maxlon, &lat, &lon);
//	printf("%f %f %f %f\n", minlat, maxlon, lat, lon);
	OZIGEN_LatLon_to_NorthingEasting(maxlat, maxlon, &lat, &lon);
//	printf("%f %f %f %f\n", maxlat, maxlon, lat, lon);
	OZIGEN_LatLon_to_NorthingEasting(maxlat, minlon, &lat, &lon);
//	printf("%f %f %f %f\n\n", maxlat, minlon, lat, lon);
*/

	char kmzName[512];
	GetCurrentDirectory(sizeof(kmzName), kmzName);
	CString Currdir = kmzName;						// Save current directory

	// change directory to %TEMP% and make folder 'files'
	GetTempPath(sizeof(kmzName), kmzName);
	SetCurrentDirectory(kmzName);
	CreateDirectory("files", NULL);

	sprintf(kmzName, "%s\\%s.kmz", Currdir, mapname);

	FILE * fp = fopen("doc.kml", "w+");
	if (fp == NULL) {
		printf("Couldn't open doc.kml\n");
		return false;
	}

	fprintf(fp,	"<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"
				"<kml xmlns=\"http://earth.google.com/kml/2.1\">\n"
				"<Document>\n"
				"<name>Custom Map</name>\n"
				"<Region>\n"
				"<LatLonAltBox>\n"
				"<north>%.9f</north>\n"
				"<south>%.9f</south>\n"
				"<east>%.9f</east>\n"
				"<west>%.9f</west>\n"
				"</LatLonAltBox>\n"
				"</Region>\n",
				maxlat,
				minlat,
				maxlon,
				minlon);


	long nTilesAcross=(dest_bitmap_width+(tileWidth-1))/tileWidth;
	long nTilesDown=(dest_bitmap_height+(tileHeight-1))/tileHeight;

	JPEG_tile_list tiles;
	
	long across, down;
	for (across=0; across<nTilesAcross; across++) {
		for (down=0; down<nTilesDown; down++) {
			if (nPoints) {
				if (!TileNearTrack( minlat+(maxlat-minlat)*(nTilesDown-down)/nTilesDown,
									minlat+(maxlat-minlat)*(nTilesDown-down-1)/nTilesDown,
									minlon+(maxlon-minlon)*across/nTilesAcross,
									minlon+(maxlon-minlon)*(across+1)/nTilesAcross, nPoints, points, trackSize) )
					continue;
/*				if (!PointNearTrack(minlat+(maxlat-minlat)*(nTilesDown-down)/nTilesDown,					// ne
									minlon+(maxlon-minlon)*(across+1)/nTilesAcross, nPoints, points) &&
					!PointNearTrack(minlat+(maxlat-minlat)*(nTilesDown-down-1)/nTilesDown,					// se
									minlon+(maxlon-minlon)*(across+1)/nTilesAcross, nPoints, points) &&
					!PointNearTrack(minlat+(maxlat-minlat)*(nTilesDown-down)/nTilesDown,					// nw
									minlon+(maxlon-minlon)*across/nTilesAcross, nPoints, points) &&
					!PointNearTrack(minlat+(maxlat-minlat)*(nTilesDown-down-1)/nTilesDown,					// sw
									minlon+(maxlon-minlon)*across/nTilesAcross, nPoints, points) &&
					!PointNearTrack(minlat+(maxlat-minlat)*(2*nTilesDown-2*down-1)/2/nTilesDown,			// middle
									minlon+(maxlon-minlon)*(2*across+1)/2/nTilesAcross, nPoints, points))
						continue;
*/
			}
			JPEG_tile * pTile = new JPEG_tile;
			pTile->fname.Format("files/c%02d%02d.jpg", down, across);
			pTile->lat_north = minlat+(maxlat-minlat)*(nTilesDown-down)/nTilesDown;
			pTile->lon_east  = minlon+(maxlon-minlon)*(across+1)/nTilesAcross;
			pTile->lat_south = minlat+(maxlat-minlat)*(nTilesDown-down-1)/nTilesDown;
			pTile->lon_west = minlon+(maxlon-minlon)*across/nTilesAcross;
			pTile->offset_x0 = dest_bitmap_width*across/nTilesAcross;
			pTile->offset_x1 = dest_bitmap_width*(across+1)/nTilesAcross;
			pTile->offset_y0 = dest_bitmap_height*down/nTilesDown;
			pTile->offset_y1 = dest_bitmap_height*(down+1)/nTilesDown;
			tiles.AddTail(pTile);
		}
	}

	Global_AddToResultsWindow("Number of tiles = %d",tiles.GetCount());

	if (tiles.GetCount() > 100) {

		if (AfxMessageBox("Warning Tile Count > 100!", MB_OKCANCEL) == IDCANCEL)
			return false;
	}

	wndProgress.m_progress_bar.SetRange(1, tiles.GetCount());

	long index = 1;
	POSITION pos;
	for (pos=tiles.GetHeadPosition(); pos != NULL; tiles.GetNext(pos)) {

		JPEG_tile * pTile = (JPEG_tile *)tiles.GetAt(pos);
//		printf("JPEG %d of %d\r", index++, tiles.GetCount());

		wndProgress.m_progress_bar.SetPos(index);
		wndProgress.m_edit_message.Format("JPEG: %d of %d", index++, tiles.GetCount());
		wndProgress.UpdateData(FALSE);

		DoEvents();

		if (wndProgress.m_Cancelled) return false;

		fprintf(fp, "<GroundOverlay>\n"
					"<drawOrder>%d</drawOrder>\n"
					"<Icon>\n"
					"<href>%s</href>\n"
					"</Icon>\n"
					"<LatLonBox>\n"
					"<north>%.9f</north>\n"
					"<east>%.9f</east>\n"
					"<south>%.9f</south>\n"
					"<west>%.9f</west>\n"
					"</LatLonBox>\n"
					"<Region>\n"
					"<LatLonAltBox>\n"
					"<north>%.9f</north>\n"
					"<east>%.9f</east>\n"
					"<south>%.9f</south>\n"
					"<west>%.9f</west>\n"
					"</LatLonAltBox>\n"
					"<Lod>\n"
					"<minLodPixels>64</minLodPixels>\n"
					"</Lod>\n"
					"</Region>\n"
					"<color>A1FFFFFF</color>\n"
					"</GroundOverlay>\n",
					nDrawOrder,
					pTile->fname,
					pTile->lat_north,
					pTile->lon_east,
					pTile->lat_south,
					pTile->lon_west,
					pTile->lat_north,
					pTile->lon_east,
					pTile->lat_south,
					pTile->lon_west);

		Gdiplus::Rect r(0, 0, pTile->offset_x1-pTile->offset_x0, pTile->offset_y1-pTile->offset_y0);
		Gdiplus::Bitmap bmp(r.GetRight(), r.GetBottom(), PixelFormat24bppRGB );
		Gdiplus::BitmapData bmpData;
		bmp.LockBits(&r, Gdiplus::ImageLockModeRead | Gdiplus::ImageLockModeWrite, PixelFormat24bppRGB, &bmpData);

		long x,y;

		for (y=pTile->offset_y0; y<pTile->offset_y1; y++) {
			lat = maxlat-(maxlat-minlat)/dest_bitmap_height*y;
			unsigned char * dest_bitmap_offset = ((unsigned char *)bmpData.Scan0) + bmpData.Stride*(y-pTile->offset_y0);
			for (x=pTile->offset_x0; x<pTile->offset_x1; x++) {
				lon = minlon+(maxlon-minlon)/dest_bitmap_width*x;
				double northing, easting;
				OZIGEN_LatLon_to_NorthingEasting(lat, lon, &northing, &easting);

				if ((MyMap.GetProjection() == 3857) || (MyMap.GetProjection() == 900913)) {
				} else {
					northing += 0.5;
					easting += 0.5;
				}

				if (northing < miny || easting < minx || northing > maxy || easting > maxx) {
					// No bitmap data present -- white
					*dest_bitmap_offset++ = 255;
					*dest_bitmap_offset++ = 255;
					*dest_bitmap_offset++ = 255;
				} else {
					// Look up colour of bitmap pixel - SNL 24/10/2013
					unsigned char * pal;
					if ((MyMap.GetProjection() == 3857) || (MyMap.GetProjection() == 900913)) {

//						pal = bitmap_palette + 4*bitmap_memory[(long)((y)*bitmap_width + (long) (x))];
//						pal = bitmap_palette + 4*bitmap_memory[(long)((northing-miny))*bitmap_width + (long)((easting-minx))];
						pal = bitmap_palette + 4*bitmap_memory[(long)((northing-miny)/dTileScale)*bitmap_width +
																 (long)((easting-minx)/dTileScale)];
					} else {
						pal = bitmap_palette + 4*bitmap_memory[(long)((maxy-northing)/dTileScale)*bitmap_width +
																 (long)((easting-minx)/dTileScale)];
					}
					*dest_bitmap_offset++ = pal[0];
					*dest_bitmap_offset++ = pal[1];
					*dest_bitmap_offset++ = pal[2];
				}
			}
		}

		bmp.UnlockBits(&bmpData);
		wchar_t wbuffer[64];
		int i;
		for (i=0; i<pTile->fname.GetLength(); i++)
			wbuffer[i] = pTile->fname.GetAt(i);
		wbuffer[i] = 0;
		bmp.Save(wbuffer, &encoderClsid, &encoderParameters);
	}

	fprintf(fp, "</Document>\n"
				"</kml>\n");
	fclose(fp);

	// Add jpegs / kml to kmz file
	DeleteFile(kmzName);
	ZipFileAdd(kmzName, "doc.kml");
	DeleteFile("doc.kml");


	long indexZip = 1;
	wndProgress.m_progress_bar.SetRange(1, tiles.GetCount());

	for (pos=tiles.GetHeadPosition(); pos != NULL; tiles.GetNext(pos)) {
		JPEG_tile * pTile = (JPEG_tile *)tiles.GetAt(pos);

		wndProgress.m_progress_bar.SetPos(indexZip);
		wndProgress.m_edit_message.Format("Zip: %d of %d", indexZip++, tiles.GetCount());
		wndProgress.UpdateData(FALSE);
		DoEvents();

		ZipFileAdd(kmzName, pTile->fname);

		DeleteFile(pTile->fname);
	}

	RemoveDirectory("files");
	SetCurrentDirectory(Currdir);
	tiles.RemoveAll();
	if (nPoints) {
		free(points);
		nPoints = 0;
		points = NULL;
	}

	Gdiplus::GdiplusShutdown(gdiplusToken);

	free(bitmap_memory);

	return true;
}
コード例 #20
0
ファイル: EditTiffUnit.cpp プロジェクト: ands904/SEnum
static void __fastcall SaveBitmap2Tiff(Gdiplus::Bitmap *bm, int npage) {
//-------------------------------------------------------------------------------
//                  Выводит очередную страницу в файл *.tif                     |
// Если npage == 0, то не выводит номер страницы                                |
// Полагает, что если это многостраничный файл, то страница уже выбрана         |
//-------------------------------------------------------------------------------
    if (SaveBitmap2TiffState == 0) return;


    // ------------------ для начала строим образ в SaveBitmap2TiffBitmap32 (SaveBitmap2TiffGraphics)
    int x, y, w, h;

    h = bm->GetHeight();
    w = bm->GetWidth();

    Gdiplus::SolidBrush whiteBrush(Gdiplus::Color(255, 255, 255, 255));
    SaveBitmap2TiffGraphics->FillRectangle(&whiteBrush, Gdiplus::Rect(0, 0, SaveBitmapW, SaveBitmapH));

    //Gdiplus::Matrix matr;
    Gdiplus::Rect r;
    //if (w > h) {                            // Если изображение шире, чем выше
    //    matr.Rotate(270.0f);                // поворачиваем его на 270 градусов
    //    SaveBitmap2TiffGraphics->SetTransform(&matr);
    //    r.X = -SaveBitmapH;
    //    r.Y = -30;
    //    r.Width = SaveBitmapH - 30;
    //    r.Height = SaveBitmapW - 30;
    //} else {
    //    r.X = 30;
    //    r.Y = 0;
    //    r.Width = SaveBitmapW - 30;
    //    r.Height = SaveBitmapH - 30;
    //}
    r.X = 0;
    r.Y = 0;
    r.Width = SaveBitmapW;
    r.Height = SaveBitmapH;

    SaveBitmap2TiffGraphics->DrawImage(bm, r, 0, 0, w, h, Gdiplus::UnitPixel, 0, 0, 0);

    // matr.Reset();
    // SaveBitmap2TiffGraphics->SetTransform(&matr);

    if (npage != 0) {            // Здесь выводим номер страницы
        AnsiString snum;
        wchar_t wnum[20];
        Gdiplus::Pen whitePen40(Gdiplus::Color(255, 255, 255, 255), 45);
        snum.printf("%d", npage);
        snum.WideChar(wnum, 20);
        Gdiplus::Font myFont(L"Arial", 40, Gdiplus::FontStyleBold);
        Gdiplus::PointF origin(SaveBitmapW - 160, 20.0f);
        Gdiplus::SolidBrush blackBrush(Gdiplus::Color(255, 0, 0, 0));
        SaveBitmap2TiffGraphics->DrawLine(&whitePen40, SaveBitmapW - 200, 50, SaveBitmapW, 50);
        if (npage > 0) {
            SaveBitmap2TiffGraphics->DrawString(wnum, -1, &myFont, origin, &blackBrush);
        }
    }


    // ------- строим SaveBitmap2TiffBitmap1
    UINT *pix;
    unsigned char byte, bit, *pix1;

    w = SaveBitmapW; h = SaveBitmapH;
    Gdiplus::Rect BitsRect(0, 0, SaveBitmapW, SaveBitmapH);
    Gdiplus::BitmapData *bits = new Gdiplus::BitmapData;
    Gdiplus::BitmapData *bits1 = new Gdiplus::BitmapData;
    sres = SaveBitmap2TiffBitmap32->LockBits(&BitsRect, Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, bits);
    sres = SaveBitmap2TiffBitmap1->LockBits(&BitsRect, Gdiplus::ImageLockModeWrite, PixelFormat1bppIndexed, bits1);

    for (y = 0; y < SaveBitmapH; y++) {
        pix = (UINT *)((int)bits->Scan0 + bits->Stride * y);
        pix1 = (unsigned char *)((int)bits1->Scan0 + bits1->Stride * y);
        byte = 0;
        for (x = 0; x < SaveBitmapW; x++, pix++) {
            if ((*pix & 0xFF) > 0xD8) {
                bit = 1;
            }
            else bit = 0;
            byte <<= 1; byte |= bit;
            if ((x & 7) == 7) {
                *pix1++ = byte;
                byte = 0;
            }
        }
    }

    SaveBitmap2TiffBitmap32->UnlockBits(bits); delete bits;
    SaveBitmap2TiffBitmap1->UnlockBits(bits1); delete bits1;


    // ------- и наконец выводим очередную страницу SaveBitmap2TiffBitmap1
    Gdiplus::EncoderParameters encoderParameters;
    ULONG parameterValue;

    // An EncoderParameters object has an array of
    // EncoderParameter objects. In this case, there is only
    // one EncoderParameter object in the array.
    encoderParameters.Count = 1;
    // Initialize the one EncoderParameter object.
    // encoderParameters.Parameter[0].Guid = Gdiplus::EncoderSaveFlag;
    encoderParameters.Parameter[0].Guid = aEncoderSaveFlag;
    encoderParameters.Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong;
    encoderParameters.Parameter[0].NumberOfValues = 1;
    encoderParameters.Parameter[0].Value = &parameterValue;

    // Get the CLSID of the TIFF encoder.
    CLSID encoderClsid;
    GetEncoderClsid(L"image/tiff", &encoderClsid);

    if (SaveBitmap2TiffState == 1) {                    // Требуется вывести первую страницу
        parameterValue = Gdiplus::EncoderValueMultiFrame;
        sres = SaveBitmap2TiffBitmap1->Save(SaveBitmap2TiffFiln, &encoderClsid, &encoderParameters);
    } else {
        parameterValue = Gdiplus::EncoderValueFrameDimensionPage;
        sres = SaveBitmap2TiffBitmap1->SaveAdd(&encoderParameters);
    }

    SaveBitmap2TiffState = 2;
}
コード例 #21
0
ファイル: CreateBirdseye.cpp プロジェクト: SimonL66/OziGen
bool CreateJNXJpeg(JPEG_tile_list& tiles, long minx, long maxx, long miny, long maxy, CString mapname, long tileWidth, long tileHeight, int nDatabase, int nDrawOrder)
{

	CProgressWindow wndProgress;
	wndProgress.Initialize();

// ToFix as this ain't right!
double dMetersPerPixel = (double) MyMap.GetMetresPerTile()/MyMap.GetPixelsPerTile();
int nTileWidth = MyMap.GetMetresPerTile();

// JKL's code to create the JPEGs

//	long width, height;
//	long x,y;

	unsigned char * bitmap_memory = NULL;

	long bitmap_width, dest_bitmap_width;
	long bitmap_height, dest_bitmap_height;

	long bitmap_memory_size;
//	long square_width;
//	long square_height;
	unsigned char bitmap_palette[1024];
	long bitmap_palette_length;

	if (minx > maxx) {
		long t = minx;
		minx = maxx;
		maxx = t;
	}
	if (miny > maxy) {
		long t = miny;
		miny = maxy;
		maxy = t;
	}

//	long collar = CalculateCollar(minx*1000, maxx*1000, miny*1000, maxy*1000);
	long collar = CalculateCollar(minx, maxx, miny, maxy);
	minx -= (collar/1000)*1000;
	maxx += (collar/1000)*1000;
	miny -= (collar/1000)*1000;
	maxy += (collar/1000)*1000;

	wndProgress.ResetProgressBar("Tile:", ((maxy-miny)*(maxx-minx))/1000*1000);

	bool successful = false;

	if (nDatabase == DBASE_LOCAL) {

		if (MyMap.GetCountry() == COUNTRY_FR && MyMap.GetProduct() == PRODUCT_02) {

			successful = IGN_ReadTiles(minx, maxx, miny, maxy, wndProgress, 
										bitmap_palette, bitmap_palette_length, 
										bitmap_memory , bitmap_memory_size, 
										bitmap_width, dest_bitmap_width,
										bitmap_height, dest_bitmap_height);
		} else {
			successful = OSPro_ReadTiles(minx, maxx, miny, maxy, wndProgress, 
										bitmap_palette, bitmap_palette_length, 
										bitmap_memory , bitmap_memory_size, 
										bitmap_width, dest_bitmap_width,
										bitmap_height, dest_bitmap_height);
		}

	} else {

		bool b_use_TL3 = nDatabase == DBASE_TRACKLOGS_3;

		successful = ReadTracklogsTile(minx, maxx, miny, maxy, wndProgress, 
										bitmap_palette, bitmap_palette_length, 
										bitmap_memory , bitmap_memory_size, 
										bitmap_width, dest_bitmap_width,
										bitmap_height, dest_bitmap_height,
										b_use_TL3);

	}

//	dest_bitmap_width = 400*(maxx-minx-2*collar/1000);
//	dest_bitmap_height = 400*(maxy-miny-2*collar/1000);

	dest_bitmap_width = nTileWidth*((maxx-minx-(2*collar))/1000);
	dest_bitmap_height = nTileWidth*((maxy-miny-(2*collar))/1000);

	if (!successful) {
		if (bitmap_memory)
			free(bitmap_memory);
		return false;
	}

	if (bitmap_memory == NULL) {
		printf("No images to process\n");
		return false;
	}

	Gdiplus::GdiplusStartupInput gdiplusStartupInput;
	ULONG_PTR gdiplusToken;
	Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

	CLSID	encoderClsid;
	// Get the CLSID of the JPEG encoder.
	GetEncoderClsid(L"image/jpeg", &encoderClsid);

	Gdiplus::EncoderParameters encoderParameters;
	encoderParameters.Count = 1;
	ULONG quality = 80;
	encoderParameters.Parameter[0].Guid = Gdiplus::EncoderQuality;
	encoderParameters.Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong;
	encoderParameters.Parameter[0].NumberOfValues = 1;
	encoderParameters.Parameter[0].Value = &quality;

	// xy
	// 00 10 20 30 40
	// 01 11 21 31 41
	// 02 12 22 32 42
	// 03 13 23 33 43
/*
	minx *= 1000;
	maxx *= 1000;
	miny *= 1000;
	maxy *= 1000;
*/
	double lat,lon;
	OZIGEN_NorthingEasting_to_LatLon(maxy-collar, minx+collar, &lat, &lon);
	double minlat = lat;
	double maxlat = lat;
	double minlon = lon;
	double maxlon = lon;
	OZIGEN_NorthingEasting_to_LatLon(maxy-collar, maxx-collar, &lat, &lon);
	if (lat < minlat) minlat = lat;
	if (lat > maxlat) maxlat = lat;
	if (lon < minlon) minlon = lon;
	if (lon > maxlon) maxlon = lon;
	OZIGEN_NorthingEasting_to_LatLon(miny+collar, minx+collar, &lat, &lon);
	if (lat < minlat) minlat = lat;
	if (lat > maxlat) maxlat = lat;
	if (lon < minlon) minlon = lon;
	if (lon > maxlon) maxlon = lon;
	OZIGEN_NorthingEasting_to_LatLon(miny+collar, maxx-collar, &lat, &lon);
	if (lat < minlat) minlat = lat;
	if (lat > maxlat) maxlat = lat;
	if (lon < minlon) minlon = lon;
	if (lon > maxlon) maxlon = lon;

	OZIGEN_LatLon_to_NorthingEasting(minlat, minlon, &lat, &lon);
	OZIGEN_LatLon_to_NorthingEasting(minlat, maxlon, &lat, &lon);
	OZIGEN_LatLon_to_NorthingEasting(maxlat, maxlon, &lat, &lon);
	OZIGEN_LatLon_to_NorthingEasting(maxlat, minlon, &lat, &lon);


	char jnxName[512];
	GetCurrentDirectory(sizeof(jnxName), jnxName);
	CString Currdir = jnxName;						// Save current directory

	// change directory to %TEMP% and make folder 'files'
	GetTempPath(sizeof(jnxName), jnxName);
	SetCurrentDirectory(jnxName);
	CreateDirectory("files", NULL);

//	sprintf(jnxName, "%s\\%s.kmz", Currdir, mapname);

	long nTilesAcross=(dest_bitmap_width+(tileWidth-1))/tileWidth;
	long nTilesDown=(dest_bitmap_height+(tileHeight-1))/tileHeight;

//	KMZ_tiles tiles; - gone global
	
	long across, down;
	for (across=0; across<nTilesAcross; across++) {
		for (down=0; down<nTilesDown; down++) {

			JPEG_tile * pTile = new JPEG_tile;
			pTile->fname.Format("files/c%02d%02d.jpg", down, across);
			pTile->lat_north = minlat+(maxlat-minlat)*(nTilesDown-down)/nTilesDown;
			pTile->lon_east  = minlon+(maxlon-minlon)*(across+1)/nTilesAcross;
			pTile->lat_south = minlat+(maxlat-minlat)*(nTilesDown-down-1)/nTilesDown;
			pTile->lon_west = minlon+(maxlon-minlon)*across/nTilesAcross;
			pTile->offset_x0 = dest_bitmap_width*across/nTilesAcross;
			pTile->offset_x1 = dest_bitmap_width*(across+1)/nTilesAcross;
			pTile->offset_y0 = dest_bitmap_height*down/nTilesDown;
			pTile->offset_y1 = dest_bitmap_height*(down+1)/nTilesDown;
			tiles.AddTail(pTile);
		}
	}

	Global_AddToResultsWindow("Number of tiles = %d",tiles.GetCount());


// SNL
	wndProgress.ResetProgressBar("JPEG:",tiles.GetCount());

	long tileCount=0;
	long index = 1;
	POSITION pos;
	for (pos=tiles.GetHeadPosition(); pos != NULL; tiles.GetNext(pos)) {
		
		wndProgress.ProgressBar();

		if (wndProgress.m_Cancelled) return false;

		JPEG_tile * pTile = (JPEG_tile *)tiles.GetAt(pos);

		Gdiplus::Rect r(0, 0, pTile->offset_x1-pTile->offset_x0, pTile->offset_y1-pTile->offset_y0);
		Gdiplus::Bitmap bmp(r.GetRight(), r.GetBottom(), PixelFormat24bppRGB );
		Gdiplus::BitmapData bmpData;
		bmp.LockBits(&r, Gdiplus::ImageLockModeRead | Gdiplus::ImageLockModeWrite, PixelFormat24bppRGB, &bmpData);

		long x,y;
		for (y=pTile->offset_y0; y<pTile->offset_y1; y++) {
			lat = maxlat-(maxlat-minlat)/dest_bitmap_height*y;
			unsigned char * dest_bitmap_offset = ((unsigned char *)bmpData.Scan0) + bmpData.Stride*(y-pTile->offset_y0);
			for (x=pTile->offset_x0; x<pTile->offset_x1; x++) {
				lon = minlon+(maxlon-minlon)/dest_bitmap_width*x;
				double northing, easting;
				OZIGEN_LatLon_to_NorthingEasting(lat, lon, &northing, &easting);
				northing += 0.5;
				easting += 0.5;
				if (northing < miny || easting < minx || northing > maxy || easting > maxx) {
					// No bitmap data present -- white
					*dest_bitmap_offset++ = 255;
					*dest_bitmap_offset++ = 255;
					*dest_bitmap_offset++ = 255;
				} else {
					// Look up colour of bitmap pixel
					unsigned char * pal = bitmap_palette + 
												4*bitmap_memory[(long)((maxy-northing)/dMetersPerPixel)*bitmap_width +
																(long)((easting-minx)/dMetersPerPixel)];
					*dest_bitmap_offset++ = pal[0];
					*dest_bitmap_offset++ = pal[1];
					*dest_bitmap_offset++ = pal[2];
				}
			}
		}
		bmp.UnlockBits(&bmpData);
		wchar_t wbuffer[64];
		int i;
		for (i=0; i<pTile->fname.GetLength(); i++)
			wbuffer[i] = pTile->fname.GetAt(i);
		wbuffer[i] = 0;
		bmp.Save(wbuffer, &encoderClsid, &encoderParameters);
		tileCount++;
	}


	SetCurrentDirectory(Currdir);
//	tiles.RemoveAll();
/*
	if (nPoints) {
		free(points);
		nPoints = 0;
		points = NULL;
	}
*/

	Gdiplus::GdiplusShutdown(gdiplusToken);

	free(bitmap_memory);


// Next bit from Map2JNX

	// up to five levels. nLevels gives the actual count
	static level_t levels[5];

	// information about all files
	static std::list<file_t> files;

	// the JNX file header to be copied to the outfile
	static jnx_hdr_t jnx_hdr;

	// the tile information table for all 5 levels
	static jnx_tile_t tileTable[JNX_MAX_TILES * 5];

	const uint8_t dummy = 0;
	uint32_t tileTableStart = 0;
	uint32_t tileCnt    = 0;

	const char *jnx_copyright = "Unknown";
	const char *jnx_subscname = "BirdsEye";
	const char *jnx_mapname   = "Unknown";

	char *copyright_buf = NULL;
	char *subscname_buf = NULL;
	char *mapname_buf   = NULL;

	double right    = -180.0;
	double top      =  -90.0;
	double left     =  180.0;
	double bottom   =   90.0;

	double scale = 0.0;

	// Number of used levels
	static int32_t nLevels = 1;

    FILE * fid = fopen(mapname+".jnx","wb");
	if(fid == 0)
    {
		// Failed to create file.
        return false;
    }

// New code writer start
//	POSITION pos;
	for (pos=tiles.GetHeadPosition(); pos != NULL; tiles.GetNext(pos)) {
		JPEG_tile * pTile = (JPEG_tile *)tiles.GetAt(pos);
		if (left > pTile->lon_west)
			left = pTile->lon_west;
		if (right < pTile->lon_east)
			right = pTile->lon_east;
		if (top < pTile->lat_north)
			top = pTile->lat_north;
		if (bottom > pTile->lat_south)
			bottom = pTile->lat_south;
	}
	nLevels = 1;
// New code writer end

	jnx_hdr.zorder  = nDrawOrder;
	jnx_hdr.left    = (int32_t)((left   * 0x7FFFFFFF) / 180);
	jnx_hdr.top     = (int32_t)((top    * 0x7FFFFFFF) / 180);
	jnx_hdr.right   = (int32_t)((right  * 0x7FFFFFFF) / 180);
	jnx_hdr.bottom  = (int32_t)((bottom * 0x7FFFFFFF) / 180);

	jnx_hdr.details = nLevels;

	for(int i=0; i<HEADER_BLOCK_SIZE; i++)
	{
		fwrite(&dummy, sizeof(dummy), 1, fid);
	}
	_fseeki64(fid,0,SEEK_SET);
	fwrite(&jnx_hdr, sizeof(jnx_hdr), 1, fid);

	// get all information to write the table of detail levels and the dummy tile table

	int i=0;

	level_t& level  = levels[i];

	level.nTiles   = tiles.GetCount();
	level.offset   = HEADER_BLOCK_SIZE;		// still has to be offset by complete header
	level.scale    = 1509;

	fwrite(&level.nTiles, sizeof(level.nTiles), 1, fid);
	fwrite(&level.offset, sizeof(level.offset), 1, fid);
	fwrite(&level.scale, sizeof(level.scale), 1, fid);
	fwrite(&level.dummy, sizeof(level.dummy), 1, fid);
	fwrite(jnx_copyright, strlen(jnx_copyright) + 1, 1, fid);

	// printf("\n    Level %i: % 5i tiles, offset %08X, scale: %i, %ix%i", i, level.nTiles, level.offset, level.scale, level.tileSize, level.tileSize);

	// write map loader info block
	uint32_t blockVersion = 0x00000009;
	char GUID[40];
	createGUID(GUID);

	fwrite(&blockVersion, sizeof(blockVersion), 1, fid);
	fwrite(GUID, 37, 1, fid);
	fwrite(jnx_subscname, strlen(jnx_subscname) + 1, 1, fid);
	fwrite(&dummy, sizeof(dummy), 1, fid);
	fwrite(&dummy, sizeof(dummy), 1, fid);
	fwrite(&dummy, sizeof(dummy), 1, fid);
	fwrite(jnx_mapname, strlen(jnx_mapname) + 1, 1, fid);
	fwrite(&nLevels , sizeof(nLevels), 1, fid);

	for(int i = 1; i <= nLevels; i++)
	{
		char str[40];
		sprintf(str,"Level %i", i);
		fwrite(str, strlen(str) + 1, 1, fid);
		fwrite(str, strlen(str) + 1, 1, fid);
		fwrite(jnx_copyright, strlen(jnx_copyright) + 1, 1, fid);
		fwrite(&i,sizeof(i), 1, fid);
	}

    // write dummy tile table
    tileTableStart = HEADER_BLOCK_SIZE;
    _fseeki64(fid, tileTableStart, SEEK_SET);
    fwrite(tileTable, sizeof(jnx_tile_t), tileCount, fid);

// New code writer start
	char TempPath[512];
	GetTempPath(sizeof(TempPath), TempPath);
	CString tPath = TempPath;
	tPath = tPath + "\\";

	wndProgress.ResetProgressBar("JNX:",tiles.GetCount());

	for (pos=tiles.GetHeadPosition(); pos != NULL; tiles.GetNext(pos)) {

		JPEG_tile * pTile = (JPEG_tile *)tiles.GetAt(pos);
//		printf("JPEG %d of %d\r", tileCnt, tiles.GetCount());

       jnx_tile_t& tile = tileTable[tileCnt++];

		tile.left    = (int32_t)(pTile->lon_west * 0x7FFFFFFF / 180);
		tile.top     = (int32_t)(pTile->lat_north * 0x7FFFFFFF / 180);
		tile.right   = (int32_t)(pTile->lon_east * 0x7FFFFFFF / 180);
		tile.bottom  = (int32_t)(pTile->lat_south * 0x7FFFFFFF / 180);

		tile.width  = (uint16_t)(pTile->offset_x1-pTile->offset_x0);
		tile.height = (uint16_t)(pTile->offset_y1-pTile->offset_y0);
		tile.offset = (uint32_t)(_ftelli64(fid) & 0x0FFFFFFFF);
		tile.size   = appendJPG(tPath + pTile->fname, fid);
	}

// New code writer end

    // terminate output file
    fwrite("BirdsEye", 8, 1, fid);

    // write final tile table
    _fseeki64(fid, tileTableStart, SEEK_SET);
    fwrite(tileTable, sizeof(jnx_tile_t), tileCount, fid);
 
	// done
    fclose(fid);

exit_CreateJNXJpeg:

    // Clean up
	if (copyright_buf) free(copyright_buf);
	if (subscname_buf) free(subscname_buf);
	if (mapname_buf) free(mapname_buf);

	//POSITION pos;
	for (pos=tiles.GetHeadPosition(); pos != NULL; tiles.GetNext(pos)) {
		JPEG_tile * pTile = (JPEG_tile *)tiles.GetAt(pos);
		DeleteFile(pTile->fname);
	}

	tiles.RemoveAll();

	return true;
}
コード例 #22
0
ファイル: MainFrm.cpp プロジェクト: SeoGB/exam
//-------------------------------------------------------------------------
// 그림파일로 저장
//-------------------------------------------------------------------------
void CMainFrame::OnFileSaveImage()
{
	//파일 다이얼로그 생성
	CFileDialog dlg(FALSE, L"bmp", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
					L"Bitmap File(*.bmp) | *.bmp |JPG File(*.jpg) | *.jpg |PNG File(*.png) | *.png ||", this);

	if(dlg.DoModal() == IDOK)
	{
		//////////////////////////////////////////////////////////////////////////
		// View 내용을 비트맵으로 만듬
		CRect clientRect;
		CGraphicEditorView* psView = (CGraphicEditorView*)GetActiveView();
		psView->GetClientRect(clientRect);
		//선택 라인을 그리지 않도록 선택 모드 해제
		BOOL bsSingleSelect = FALSE, bsMultiSelect = FALSE;
		if (psView->m_bsSelectMode) 
		{
			bsSingleSelect = TRUE;
			psView->m_bsSelectMode = FALSE;

		}
		if(psView->m_bsMultiSelectMode)
		{
			bsMultiSelect = TRUE;
			psView->m_bsMultiSelectMode = FALSE;
		}
		psView->RedrawWindow();
		CDC dcMem;
		dcMem.CreateCompatibleDC(psView->GetDC());
		CBitmap cBitmap, *pOldBitmap;
		cBitmap.CreateCompatibleBitmap(psView->GetDC(), clientRect.Width(), clientRect.Height());
		pOldBitmap = (CBitmap*)dcMem.SelectObject(cBitmap);
		dcMem.BitBlt(0, 0, clientRect.Width(), clientRect.Height(), psView->GetDC(), 0, 0, SRCCOPY);

		//////////////////////////////////////////////////////////////////////////
		// 파일 저장
		Bitmap loadBitmap(cBitmap, NULL); //위에서 생성한 CBitmap을 GDI+에서 사용하는 Bitmap 객체로 바꿈
		CLSID imgClsid; //이미지 코덱 정보
		switch(dlg.m_ofn.nFilterIndex)
		{
		case 1:	//BMP에 대한 이미지 코덱의 CLSID를 받아옴
			GetEncoderClsid(L"image/bmp", &imgClsid);
			break;
		case 2: //JPG에 대한 이미지 코덱의 CLSID를 받아옴
			GetEncoderClsid(L"image/jpeg", &imgClsid);
			break;
		case 3: //PNG에 대한 이미지 코덱의 CLSID를 받아옴
			GetEncoderClsid(L"image/png", &imgClsid);
			break;
		}
		//그림파일 저장 시 파라미터
		int nQuality = 100;
		EncoderParameters param;
		param.Count                       = 1; 
		param.Parameter[0].Guid           = EncoderQuality;
		param.Parameter[0].Type           = EncoderParameterValueTypeLong;
		param.Parameter[0].NumberOfValues = 1;
		param.Parameter[0].Value          = &nQuality;

		//그림 파일 저장
		CString fileName = dlg.GetPathName();
		loadBitmap.Save(fileName,&imgClsid, &param);

		//////////////////////////////////////////////////////////////////////////
		//선택 라인이 해제되었다면 다시 활성화
		if (bsSingleSelect) 
		{
			bsSingleSelect = FALSE;
			psView->m_bsSelectMode = TRUE;

		}
		if(bsMultiSelect)
		{
			bsMultiSelect = FALSE;
			psView->m_bsMultiSelectMode = TRUE;
		}
	}
}
コード例 #23
-1
ファイル: gyazowin.cpp プロジェクト: Torikova/Gyazowin
// PNG 形式で保存 (GDI+ 使用)
BOOL savePNG(LPCTSTR fileName, HBITMAP newBMP)
{
	BOOL				res = FALSE;

	GdiplusStartupInput	gdiplusStartupInput;
	ULONG_PTR			gdiplusToken;
	CLSID				clsidEncoder;

	// GDI+ の初期化
	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
	
	// HBITMAP から Bitmap を作成
	Bitmap *b = new Bitmap(newBMP, NULL);
	
	if (GetEncoderClsid(L"image/png", &clsidEncoder)) {
		// save!
		if (0 ==
			b->Save(fileName, &clsidEncoder, 0) ) {
				// 保存できた
				res = TRUE;
		}
	}
	
	// 後始末
	delete b;
	GdiplusShutdown(gdiplusToken);

	return res;
}
コード例 #24
-1
ファイル: gyazowin.cpp プロジェクト: Torikova/Gyazowin
// PNG 形式に変換
BOOL convertPNG(LPCTSTR destFile, LPCTSTR srcFile)
{
	BOOL				res = FALSE;

	GdiplusStartupInput	gdiplusStartupInput;
	ULONG_PTR			gdiplusToken;
	CLSID				clsidEncoder;

	// GDI+ の初期化
	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

	Image *b = new Image(srcFile, 0);

	if (0 == b->GetLastStatus()) {
		if (GetEncoderClsid(L"image/png", &clsidEncoder)) {
			// save!
			if (0 == b->Save(destFile, &clsidEncoder, 0) ) {
					// 保存できた
					res = TRUE;
			}
		}
	}

	// 後始末
	delete b;
	GdiplusShutdown(gdiplusToken);

	return res;
}
コード例 #25
-1
bool CGifEncoder::FinishEncoder()
{
	if (!m_started || !m_haveFrame)
	{
		return false;
	}
	bool	flag = true;
	Gdiplus::Status statue;
	SetImagePropertyItem();
	GUID gifGUID;
	Gdiplus::EncoderParameters encoderParams;
	GetEncoderClsid(L"image/gif", &gifGUID);
	encoderParams.Count = 1;
	encoderParams.Parameter[0].Guid = Gdiplus::EncoderSaveFlag;
	encoderParams.Parameter[0].NumberOfValues = 1;
	encoderParams.Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong;
	long firstValue = Gdiplus::EncoderValueMultiFrame;
	encoderParams.Parameter[0].Value = &firstValue;
	m_pImage->Save(m_pStrSavePath->c_str(), &gifGUID, &encoderParams);
	const size_t size = m_pBitMapVec.size();
	firstValue = Gdiplus::EncoderValueFrameDimensionTime;
	encoderParams.Parameter[0].Value = &firstValue;
	for (size_t ix = 0; ix <size; ix++)
	{
		statue = m_pImage->SaveAdd(m_pBitMapVec[ix], &encoderParams);
	}
	m_started = false;
	m_haveFrame = false;
	return(flag);
}