将 TXT 转换为 JPG
我正在使用 libcurl 来下载文件。我下载了图像(JPG),但只能将其另存为txt文件。有没有什么方法可以将数据(字符串)更改为JPG并保存?
谢谢
编辑:
我怎样才能转换这个流?
Bitmap b = new Bitmap(data);
b.Save("picture.jpg", b); <-- this gives me error
I am using libcurl to download file. I download the image (JPG), but I can only save it as txt file. Is there any methods that could change data (string) to JPG and save it ?
Thanks
Edit:
How can I convert this stream ?
Bitmap b = new Bitmap(data);
b.Save("picture.jpg", b); <-- this gives me error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
查看第二个参数。
Look at the second parameter.
我认为你要么想要
或者只是按原样保存数据......
I think you either want
or just save data as it is...
下载图像时,您可能会使用某种网络流来读取数据。
我会尝试首先将该数据写入内存流,然后在该流上创建一个位图 (
Bitmap b = new Bitmap(memStream);
) 并保存位图作为 JPEG 文件。那行得通吗?否则,您真的应该真正发布一些源代码,以便我们可以看到您在做什么。
编辑
请在发布源代码时编辑您的问题 - 不要添加其他回复,这不是论坛软件,如果您这样做,人们会感到困惑。
When downloading the image, you'll probably have some kind of network stream to read the data from.
I'd try to write that data to a memory stream first, then create a
Bitmap
on that stream (Bitmap b = new Bitmap(memStream);
) and save the bitmap as JPEG file. Does that work.Otherwise, you should really really post some source code so we can see what you're doing.
EDIT
Please edit your question when posting the source code - do not add another reply, this is not a forum software and people will get confused if you do.
我不知道为什么你不能将文件保存为 .jpg...因为你使用的是 libcurl 这不应该是一个问题:
*注意:代码是 C++ 语言,我不确定你使用的是什么语言但如果您使用其他语言,它应该给您一个提示。
wLocalFilePath 是您要保存下载内容的文件的完整路径,当然扩展名是(c:\picture.jpg),您应该打开文件以二进制模式写入,将文件指针传递给curl处理与您的写入回调函数一起,您应该被设置。
I'm not sure why you can't save the file as .jpg.... since you are using libcurl this shouldnt be a problem:
*Note: the code is in C++ and I'm not sure what language you are using but it should give ya a hint if you are using other languages.
wLocalFilePath is the full path of the file where you want to save your downloaded content with the extension of course for example (c:\picture.jpg) and you should open the file to write in binary mode, pass the file pointer to the curl handle along with your write callback function and you should be set.