mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -06:00 
			
		
		
		
	ENH:update base64 conversion method
jira:[for model mall] Change-Id: Ia609ae4a559e0e2711e37db32738c057e8a8a33a
This commit is contained in:
		
							parent
							
								
									01f4948e88
								
							
						
					
					
						commit
						d631a672ab
					
				
					 1 changed files with 26 additions and 18 deletions
				
			
		|  | @ -311,10 +311,14 @@ std::map<std::string, std::vector<json>> ProjectPanel::Reload(wxString aux_path) | |||
|                     pfile_obj["size"] = formatBytes((unsigned long)filelen); | ||||
| 
 | ||||
|                     //image
 | ||||
|                     if (file_path_obj.extension() == ".jpg" || | ||||
|                         file_path_obj.extension() == ".jpeg" || | ||||
|                         file_path_obj.extension() == ".png" || | ||||
|                         file_path_obj.extension() == ".bmp") | ||||
|                     if (file_extension == ".jpg"    || | ||||
|                         file_extension == ".jpeg"   || | ||||
|                         file_extension == ".pjpeg"  || | ||||
|                         file_extension == ".png"    || | ||||
|                         file_extension == ".jfif"   || | ||||
|                         file_extension == ".pjp"    || | ||||
|                         file_extension == ".webp"   || | ||||
|                         file_extension == ".bmp") | ||||
|                     { | ||||
| 
 | ||||
|                         wxString base64_str = to_base64(file_path); | ||||
|  | @ -343,25 +347,29 @@ std::string ProjectPanel::formatBytes(unsigned long bytes) | |||
| 
 | ||||
| wxString ProjectPanel::to_base64(std::string file_path)  | ||||
| { | ||||
|     std::map<std::string, wxBitmapType> base64_format; | ||||
|     base64_format[".jpg"] = wxBITMAP_TYPE_JPEG; | ||||
|     base64_format[".jpeg"] = wxBITMAP_TYPE_JPEG; | ||||
|     base64_format[".png"] = wxBITMAP_TYPE_PNG; | ||||
|     base64_format[".bmp"] = wxBITMAP_TYPE_BMP; | ||||
|     std::ifstream imageFile(encode_path(file_path.c_str()), std::ios::binary); | ||||
|     if (!imageFile) { | ||||
|         return wxEmptyString; | ||||
|     } | ||||
| 
 | ||||
|     std::string extension = file_path.substr(file_path.rfind("."), file_path.length()); | ||||
|     std::ostringstream imageStream; | ||||
|     imageStream << imageFile.rdbuf(); | ||||
| 
 | ||||
|     auto image = new wxImage(encode_path(file_path.c_str())); | ||||
|     wxMemoryOutputStream mem; | ||||
|     image->SaveFile(mem, base64_format[extension]); | ||||
|     std::string binaryImageData = imageStream.str(); | ||||
| 
 | ||||
|     std::string extension; | ||||
|     size_t last_dot = file_path.find_last_of("."); | ||||
| 
 | ||||
|     if (last_dot != std::string::npos) { | ||||
|         extension = file_path.substr(last_dot + 1); | ||||
|     } | ||||
| 
 | ||||
|     wxString bease64_head = wxString::Format("data:image/%s;base64,", extension); | ||||
| 
 | ||||
|     wxString km = wxBase64Encode(mem.GetOutputStreamBuffer()->GetBufferStart(), | ||||
|         mem.GetSize()); | ||||
| 
 | ||||
|     std::wstringstream wss; | ||||
|     wss << L"data:image/jpg;base64,"; | ||||
|     //wss << wxBase64Encode(km.data(), km.size());
 | ||||
|     wss << km; | ||||
|     wss << bease64_head; | ||||
|     wss << wxBase64Encode(binaryImageData.data(), binaryImageData.size()); | ||||
| 
 | ||||
|     wxString base64_str = wss.str(); | ||||
|     return  base64_str; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 tao wang
						tao wang