上传从 WriteableBitmap 创建的 JPEG,而不先将其保存到用户计算机

发布于 2024-10-05 05:51:00 字数 226 浏览 3 评论 0原文

我有一个应用程序,允许用户将视频上传到服务器,该过程的一部分是在客户端上创建缩略图,该缩略图将在服务器上加载时用于视频。我有一个 writeablebitmap,我想将其转换为 jpeg 并上传到服务器。

是否可以在不先将 jpeg 保存到用户计算机的情况下执行此操作 - 我不想需要受信任的应用程序。是否可以先将其存储在独立存储中,然后从那里上传,就好像它只是用户计算机上的另一个文件一样?

谢谢 迈克尔

I have an application that allows users to upload videos to the server and part of the process is to create a thumbnail image on the client that will be used for the video when loaded on the server. I have a writeablebitmap that I want to convert to a jpeg and upload to the server.

Is it possible to do this without saving the jpeg to the user's computer first - I do not want to require a trusted app. Is it possible to store it in isolatedstorage first and then upload it from there as if it is just another file on the user's computer?

thanks
Michael

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

枕梦 2024-10-12 05:51:00

您必须在上传之前保存文件,但当然可以将其保存到隔离存储而不是通用文件系统。

Microsoft 独立存储快速入门可以写入图像。

图像的名称和实际图像文件本身保存在独立的存储中。图像名称保存在名为 userSettings 的设置中,键为 userImage。保存图像名称不是必需的,但保存是为了方便。图像文件保存在名为 Images 的目录中,并命名为 UserImageFile.jpg。

OpenFile 方法;

使用指定的共享和访问选项打开指定路径中的文件。此方法返回一个包含文件流的IsolatedStorageFileStream 对象。

您可以下载一些代码来帮助您入门。

You will have to save the file before uploading, but it is certainly possible to save it to Isolated Storage rather than the general file system.

There's a Microsoft Quickstart on Isolated Storage that writes an image.

the name of an image and the actual image file itself are saved in isolated storage. The image name is saved in a setting named userSettings with a key of userImage. Saving the image name is not required, but it is saved as a convenience. The image file is saved in a directory named Images and is named UserImageFile.jpg.

The OpenFile method;

Opens a file at a specified path using the specified sharing and access options. This method returns an IsolatedStorageFileStream object that contains the file's stream.

There's some code you can download which should get you started.

风透绣罗衣 2024-10-12 05:51:00

我实现了一个解决方案,允许我获取 WriteableBitmap,使用 FJCore 将其转换为 JPEG,并将其写入 MemoryStream 并将其发送到服务器。

FluxJpeg.Core.Encoder.JpegEncoder encoder = new FluxJpeg.Core.Encoder.JpegEncoder(img, quality, stream);

请参阅: 使用 FJCore 编码 Silverlight WriteableBitmap

然后我发现了一个很棒的 FileUploader 类,它我修改为上传 MemoryStream,避免首先创建本地文件。

原始:

public void StartUpload(FileInfo file)

修改:

public void StartUpload(Stream fileStream)

请参阅:http://www.codeproject.com/KB/silverlight/ SL4FileUploadAnd_SL4_MVVM.aspx

在服务器上,我使用上面链接中描述的 FileUpload.ashx 来接受流块并将它们写入服务器上的文件中。

使用 HttpWebRequest 调用 FileUpload.ashx,MemoryStream 会以块的形式向上发送,直到到达流的末尾。

当服务器接收到字节时,它们会被写入指定位置的文件中。

  • 迈克尔

I implemented a solution that allows me to take a WriteableBitmap, convert it to a JPEG using FJCore and write it to a MemoryStream and send it to the server.

FluxJpeg.Core.Encoder.JpegEncoder encoder = new FluxJpeg.Core.Encoder.JpegEncoder(img, quality, stream);

see: Using FJCore to encode Silverlight WriteableBitmap

Then I found a great FileUploader class which I modified to upload a MemoryStream avoiding having to create a local file first.

ORIG:

public void StartUpload(FileInfo file)

MODIFIED:

public void StartUpload(Stream fileStream)

see: http://www.codeproject.com/KB/silverlight/SL4FileUploadAnd_SL4_MVVM.aspx

On the server I used the FileUpload.ashx described in the link above to accept the chunks of the stream and write them to a file on the server.

Calling the FileUpload.ashx using a HttpWebRequest, the MemoryStream is sent up in chunks until the end of the stream is reached.

As they bytes are received on the server they are written out to a file in a specified location.

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