将 TXT 转换为 JPG

发布于 2024-08-12 04:27:35 字数 247 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

左岸枫 2024-08-19 04:27:35

我认为你要么想要

Bitmap b = new Bitmap(data);
b.Save("picture.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

或者只是按原样保存数据......

I think you either want

Bitmap b = new Bitmap(data);
b.Save("picture.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

or just save data as it is...

强辩 2024-08-19 04:27:35

下载图像时,您可能会使用某种网络流来读取数据。

我会尝试首先将该数据写入内存流,然后在该流上创建一个位图 (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.

那伤。 2024-08-19 04:27:35

我不知道为什么你不能将文件保存为 .jpg...因为你使用的是 libcurl 这不应该是一个问题:

FILE* f = _tfopen(wLocalFilePath.c_str(), _T("wb+"));
 if(!f)
  return ERROR_FILE;

 curl_easy_setopt(curl, CURLOPT_WRITEDATA, f);

 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteFileCallcack);

*注意:代码是 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:

FILE* f = _tfopen(wLocalFilePath.c_str(), _T("wb+"));
 if(!f)
  return ERROR_FILE;

 curl_easy_setopt(curl, CURLOPT_WRITEDATA, f);

 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteFileCallcack);

*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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文