![](https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/onion/3.gif)
1
2
3
4
5
6
7
8
9
10
11
12
13
|
//@函数功能:将图片文件转换成vector<unsigned char>
void
photo_to_uvchar(
const
char
* photo_path, vector<unsigned
char
>& uvchar)
{
fstream fs(
"D:\\新文档代码\\test_photo.jpg "
) ;
// 创建个文件流对象,并打开"test_photo.jpg"
stringstream ss ;
// 创建字符串流对象
ss << fs.rdbuf() ;
// 把文件流中的字符输入到字符串流中
std::string src = ss.str() ;
// 获取流中的字符串
uvchar.resize( src.size()+1 );
unsigned
char
* pDst = &uvchar[0];
unsigned
char
* pSrc =
reinterpret_cast
<unsigned
char
*>(
const_cast
<
char
*>(src.c_str()));
memcpy
( pDst, pSrc, src.size() );
}
|
![](https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/onion/5.gif)
<div marginwidth="0" marginheight="0" scrolling="no" width="100%">
<div>
<div id="kp_box_87" data-pid="87" data-track-view="{"mod":"kp_popu_87-702","con":",,"}" data-track-click="{"mod":"kp_popu_87-702","con":",,"}"><script async="" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
</div>
</div>
<!-- <div class="question_wrap"><span>问题点数:</span><em>分</em></div> -->
</div>