怎样用c++builder 6对本地图片c 怎么进行base64编码码

c++ 图片转成base64类型,然后进行编码_百度知道
c++ 图片转成base64类型,然后进行编码
现在base64编码的代码我有,就是不知道如何将图片读出的2进制流转成base64类型。windows下可以用CryptBinaryToStringA,但是我的代码要移植到linux,所以CryptBinaryToStringA不能用了
我有更好的答案
用二进制的方式打开文件读取,把文件读取到数组,然后把数组抛给函数进行base64编码。 为了稳妥起见你的二进制数组可以定义成 unsigned char array1[数组大小];
如图,读出的2进制不转成base64类型,是不能进行base64编码的。图片fread之后的ibuffer不转换查看值就是个?
采纳率:68%
为您推荐:
其他类似问题
base64的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。网站已改版,请使用新地址访问:
BASE64 C++Builder 编解码 Crypt_De algrithms 加密解密 269万源代码下载- www.pudn.com
&文件名称: BASE64& & [
& & & & &&]
&&所属分类:
&&开发工具: C++ Builder
&&文件大小: 697 KB
&&上传时间:
&&下载次数: 39
&&提 供 者:
&详细说明:C++Builder BASE64编解码-C++ Builder BASE64 encoding and decoding
文件列表(点击判断是否您需要的文件,如果是垃圾请在下面评价投诉):
&&BASE64\Project1.bpr&&......\Project1.cpp&&......\Project1.exe&&......\Project1.obj&&......\Project1.res&&......\Project1.tds&&......\Project1.~bpr&&......\Project1.~cpp&&......\Unit1.cpp&&......\Unit1.dfm&&......\Unit1.h&&......\Unit1.obj&&......\Unit1.~cpp&&......\Unit1.~dfm&&......\Unit1.~h&&......\ZBase64.cpp&&......\ZBase64.h&&......\ZBase64.obj&&......\ZBase64.~cpp&&......\ZBase64.~h&&BASE64
&[]:很好,推荐下载
&输入关键字,在本站269万海量源码库中尽情搜索:
&[] - DES加密C++Builder实现,
实现按钮源代码
&[] - c++加密解密,可以对文件进行加密解密,采用异或加密方式
&[] - base64加密解密,c语言实现.
方便移植。
&[] - C++ Base64编码/解码源代码
inline int Base64Encode(char * base64code, const char * src, int src_len = 0)
inline int Base64Decode(char * buf, const char * b
&[] - base64加密解密,c语言实现.
方便移植。
&[] - Base 64 加解码程序
&[] - 一个自己写的加密/解密DLL文件,包含(Base64, BlowFish, AES, RSA,DES3,GOST)等算法以及用delphi 和 C++Builder 调用的例子源码和调用说明文件。下次自动登录
现在的位置:
& 综合 & 正文
Base64编解码(C++版),图片编解码
Note: I have started to move some scripts and source code from this website to .
This affects some or all of the scripts found on this page. They should be found under .
I don't intend to maintain the scripts and or sources on this page any longer (so they might be outdated). But I will try to improve the code in the GitHub repository and accept Push Requests.
The cpp file
base64.cpp
base64.cpp and base64.h
Copyright (C)
René Nyffenegger
This source code is provided 'as-is', without any express or implied
warranty. In no event will the author be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must n you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
#include "base64.h"
#include &iostream&
static const std::string base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
static inline bool is_base64(unsigned char c) {
return (isalnum(c) || (c == '+') || (c == '/'));
std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
int i = 0;
int j = 0;
unsigned char char_array_3[3];
unsigned char char_array_4[4];
while (in_len--) {
char_array_3[i++] = *(bytes_to_encode++);
if (i == 3) {
char_array_4[0] = (char_array_3[0] & 0xfc) && 2;
char_array_4[1] = ((char_array_3[0] & 0x03) && 4) + ((char_array_3[1] & 0xf0) && 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) && 2) + ((char_array_3[2] & 0xc0) && 6);
char_array_4[3] = char_array_3[2] & 0x3f;
for(i = 0; (i &4) ; i++)
ret += base64_chars[char_array_4[i]];
for(j = j & 3; j++)
char_array_3[j] = '\0';
char_array_4[0] = (char_array_3[0] & 0xfc) && 2;
char_array_4[1] = ((char_array_3[0] & 0x03) && 4) + ((char_array_3[1] & 0xf0) && 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) && 2) + ((char_array_3[2] & 0xc0) && 6);
char_array_4[3] = char_array_3[2] & 0x3f;
for (j = 0; (j & i + 1); j++)
ret += base64_chars[char_array_4[j]];
while((i++ & 3))
ret += '=';
std::string base64_decode(std::string const& encoded_string) {
int in_len = encoded_string.size();
int i = 0;
int j = 0;
int in_ = 0;
unsigned char char_array_4[4], char_array_3[3];
while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
char_array_4[i++] = encoded_string[in_]; in_++;
if (i ==4) {
for (i = 0; i &4; i++)
char_array_4[i] = base64_chars.find(char_array_4[i]);
char_array_3[0] = (char_array_4[0] && 2) + ((char_array_4[1] & 0x30) && 4);
char_array_3[1] = ((char_array_4[1] & 0xf) && 4) + ((char_array_4[2] & 0x3c) && 2);
char_array_3[2] = ((char_array_4[2] & 0x3) && 6) + char_array_4[3];
for (i = 0; (i & 3); i++)
ret += char_array_3[i];
for (j = j &4; j++)
char_array_4[j] = 0;
for (j = 0; j &4; j++)
char_array_4[j] = base64_chars.find(char_array_4[j]);
char_array_3[0] = (char_array_4[0] && 2) + ((char_array_4[1] & 0x30) && 4);
char_array_3[1] = ((char_array_4[1] & 0xf) && 4) + ((char_array_4[2] & 0x3c) && 2);
char_array_3[2] = ((char_array_4[2] & 0x3) && 6) + char_array_4[3];
for (j = 0; (j & i - 1); j++) ret += char_array_3[j];
The header file
#include &string&
std::string base64_encode(unsigned char const* , unsigned int len);
std::string base64_decode(std::string const& s);
The test file
#include "base64.h"
#include &iostream&
int main() {
const std::string s = "ADP GmbH\nAnalyse Design & Programmierung\nGesellschaft mit beschr?nkter Haftung" ;
std::string encoded = base64_encode(reinterpret_cast&const unsigned char*&(s.c_str()), s.length());
std::string decoded = base64_decode(encoded);
std::cout && "encoded: " && encoded && std::
std::cout && "decoded: " && decoded && std::
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace G // Using GDI+
Graphics graphics(hdc); // Get this however you get this
std::string encodedImage = "&Your Base64 Encoded String goes here&";
std::string decodedImage = base64_decode(encodedImage); // using the base64
// library I linked
DWORD imageSize = decodedImage.length();
HGLOBAL hMem = ::GlobalAlloc(GMEM_MOVEABLE, imageSize);
LPVOID pImage = ::GlobalLock(hMem);
memcpy(pImage, decodedImage.c_str(), imageSize);
IStream* pStream = NULL;
::CreateStreamOnHGlobal(hMem, FALSE, &pStream);
Image image(pStream);
graphics.DrawImage(&image, destRect);
pStream-&Release();
GlobalUnlock(hMem);
GlobalFree(hMem);
【上篇】【下篇】C++的Base64编码类
#include &string&&
const static class CConvert{&
&static void _enBase64Help(unsigned char chasc[3],unsigned char chuue[4]);&
&static void _deBase64Help(unsigned char chuue[4],unsigned char chasc[3]);&
&static string enBase64( const char* inbuf, size_t inbufLen );&
&static string enBase64( const string &inbuf);&
&static int deBase64( string src, char* outbuf );&
&static string deBase64( string src);&
#include &stdafx.h&&
#include &Convert.h&&
void CConvert::_enBase64Help(unsigned char chasc[3],unsigned char chuue[4])&
&int i, k=2;&
&unsigned char t = 0;&&
&for(i=0; i&3; i++)&
& *(chuue+i) = *(chasc+i)&&k;&
& *(chuue+i) |=&
& t = *(chasc+i)&&(8-k);&
& t &&= 2;&
& k += 2;&
&*(chuue+3) = *(chasc+2)&63;&
&for ( i=0; i&4; i++ ) {&
& if ( (*(chuue+i)&=128) && (*(chuue+i)&=25) ) {&
&& *(chuue+i) += 65; // 'A'-'Z'&
& } else if ( (*(chuue+i)&=26) && (*(chuue+i)&=51) ) {&
&& *(chuue+i) += 71; // 'a'-'z'&
& } else if ( (*(chuue+i)&=52) && (*(chuue+i)&=61) ) {&
&& *(chuue+i) -= 4; // 0-9&
& } else if ( *(chuue+i)==62 ) {&
&& *(chuue+i) = 43; // +&
& } else if ( *(chuue+i)==63 ) {&
&& *(chuue+i) = 47; // /&
void CConvert::_deBase64Help(unsigned char chuue[4],unsigned char chasc[3]) {&
&int i,k=2;&
&unsigned char t=0;&&
&for( i=0; i&4; i++) {&
& if ( (*(chuue+i)&=65) && (*(chuue+i)&=90))&&
&& *(chuue+i) -= 65; // 'A'-'Z' -& 0-25&
& else if ( (*(chuue+i)&=97)&&(*(chuue+i)&=122) )& &
&& *(chuue+i) -= 71; // 'a'-'z' -& 26-51&
& else if ( (*(chuue+i)&=48)&&(*(chuue+i)&=57) )&&
&& *(chuue+i) += 4; // '0'-'9' -& 52-61&
& else if ( *(chuue+i)==43 )&&
&& *(chuue+i) = 62; // + -& 62&
& else if ( *(chuue+i)==47 )&&
&& *(chuue+i) = 63; // / -& 63&
& else if ( *(chuue+i)==61 )&&
&& *(chuue+i) = 0;& // = -& 0& Note: 'A'和'='都对应了0&
&for ( i=0; i&3; i++ ) {&
& *(chasc+i) = *(chuue+i) &&&
& k += 2;&
& t = *(chuue+i+1) && (8-k);&
& *(chasc+i) |=&
string CConvert::enBase64( const char* inbuf, size_t inbufLen ) {&
&string outS&
&unsigned char in[8];&
&unsigned char out[8];&
&out[4] = 0;&
&size_t blocks = inbufLen / 3;&
&for ( size_t i=0; i& i++ ) {&
& in[0] = inbuf[i*3];&
& in[1] = inbuf[i*3+1];&
& in[2] = inbuf[i*3+2];&
& _enBase64Help(in,out);&
& outStr += out[0];&
& outStr += out[1];&
& outStr += out[2];&
& outStr += out[3];&
&if ( inbufLen % 3 == 1 ) {&
& in[0] = inbuf[inbufLen-1];&
& in[1] = 0;&
& in[2] = 0;&
& _enBase64Help(in,out);&
& outStr += out[0];&
& outStr += out[1];&
& outStr += '=';&
& outStr += '=';&
&} else if ( inbufLen % 3 == 2 ) {&
& in[0] = inbuf[inbufLen-2];&
& in[1] = inbuf[inbufLen-1];&
& in[2] = 0;&
& _enBase64Help(in,out);&
& outStr += out[0];&
& outStr += out[1];&
& outStr += out[2];&
& outStr += '=';&
&return string(outStr);&
string CConvert::enBase64( const string &inbuf)&
&return CConvert::enBase64( inbuf.c_str(), inbuf.size() );&
int CConvert::deBase64( string src, char* outbuf ) {&&
&// Break when the incoming base64 coding is wrong&
&if((src.size() % 4 )!= 0 )&
&&&&&&& {&
&&&&&&&&&&&&&&& return 0;&
&&&&&&& }&&
&unsigned char in[4];&
&unsigned char out[3];&&
&size_t blocks = src.size()/4;&
&for ( size_t i=0; i& i++ ) {&
& in[0] = src[i*4];&
& in[1] = src[i*4+1];&
& in[2] = src[i*4+2];&
& in[3] = src[i*4+3];&
& _deBase64Help(in,out);&
& outbuf[i*3]&& = out[0];&
& outbuf[i*3+1] = out[1];&
& outbuf[i*3+2] = out[2];&
&int length = src.size() / 4 * 3;&
&if ( src[src.size()-1] == '=' ) {&
& length--;&
& if ( src[src.size()-2] == '=' ) {&
&& length--;&
string CConvert::deBase64( string src)&
&&&&&&& char * buf=new char[src.length()*2];&
&&&&&&& int len=deBase64(src,buf);&
&&&&&&& buf[len]='\0';&
&&&&&&& string result=string(buf,len);&
&&&&&&& delete []&
摘自 moon5284的专栏

我要回帖

更多关于 对图片进行base64编码 的文章

 

随机推荐