如何不将音频和视频数据转换为byte []而又不从原始文件路径读取为byte []? [英] How do I convert audio and video data to byte[] without reading into byte[] from original filepath?

查看:56
本文介绍了如何不将音频和视频数据转换为byte []而又不从原始文件路径读取为byte []?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个C#.NET WinForms应用程序,需要在其中创建一个zip文件(使用DotNetZip),该文件由以下类型的项组成:

I'm writing a C# .NET WinForms app where I need to create a zip file (using DotNetZip) consisting of items of the following types:

System.Drawing.Image someImage

Microsoft.DirectX.AudioVideoPlayback.Audio someAudio

Microsoft.DirectX.AudioVideoPlayback.Audio someAudio

Microsoft.DirectX.AudioVideoPlayback.Video someVideo

Microsoft.DirectX.AudioVideoPlayback.Video someVideo

问题:在我发现的所有将图像,音频或视频文件转换为字节数组或Base64字符串的代码示例中,都使用文件的原始文件路径来转换项目...

Problem: In all the code examples I've found in which an image, audio or video file is converted to a byte array or Base64 string, the items are converted using the files' original filepaths...

byte() MediaInBytes = File.ReadAllBytes(originalfilepath);

由于生成的zip文件可能会在创建它的计算机之外的另一台计算机上打开,因此我无法使用每个图像,音频或视频文件的原始文件路径,因为这些图像,音频或视频文件可能在另一台计算机上不存在.一旦我添加了 图片,音频或视频文件,则不再使用原始文件路径.

所以我有两个选择:

1.找到一种方法,以将someimage,someaudio和somevideo添加到使用DotNetZip创建的zip存档中,而无需先将它们转换为Base64字符串或字节数组,或者
2.找到一种将someimage,someaudio和somevideo写入临时文件的方法,这样我就可以从那里添加它们.请记住,要将项目添加到DotNetZip zip文件中,该项目必须源自文件路径:

Since the resulting zip file may be opened on another computer other than the one it was created on, I cannot use each image, audio or video file's original filepath because those image, audio or video files may not exist on another computer. Once I add an image, audio or video file, the original filepath should no longer be used.

So I'm left with two options:

1. Find a way to add someimage, someaudio and somevideo to a zip archive created with DotNetZip without converting them to Base64 string or byte array first, or
2. Find a way to write someimage, someaudio and somevideo to a temp file so I can add them from there. Remember, to add an item to a DotNetZip zip file, the item must originate from a filepath:

Ionic.Zip.ZipEntry someEntry = zip.AddFile(filepath);

任何帮助将不胜感激.

Any help will be greatly appreciated.

推荐答案

我不明白您的担心.  创建zip文件的计算机只有在可以读取原始文件的所有字节的情况下才能这样做.  一旦有了MediaInBytes数组,原始文件路径就不再重要了.你推 使用所需的任何文件名将字节放入zip文件中.  在另一台计算机上,用户将使用您在zip中嵌入的名称解压缩文件. 
I don't understand your concern.  The machine that is creating the zip file can only do so if it can read all the bytes of the original file.  Once you have the MediaInBytes array, the original file path doesn't matter any more.  You shove the bytes into the zip using whatever file name you want.  On the other machine, the user will unzip the file with the name you embed in the zip. 


这篇关于如何不将音频和视频数据转换为byte []而又不从原始文件路径读取为byte []?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆