memorystream

Saving a bitmap into a MemoryStream

限于喜欢 提交于 2020-01-12 06:28:30
问题 Should I allocate the memory or just the object of the memory stream: Is this OK? MemoryStream memoryStream = new MemoryStream(); bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg); If I need to define the MemoryStream size, how can I get it from Bitmap? 回答1: .NET is a managed environment: specifically, memory allocation is usually managed on your behalf by the .NET runtime. You don't typically need to allocate the memory yourself. Sometimes, however, you do need to inform the

Delphi: Easiest way to search for string in memorystream

孤人 提交于 2020-01-11 12:33:24
问题 What's the easiest way to search for a string within a memory stream (and multiple strings) and return true or false? 回答1: var ms:TMemoryStream; strS:TStringStream; aStr:string; aPos:integer; found:boolean; begin ms:=TMemoryStream.Create; ms.LoadFromFile('c:\aFile.txt'); strS:=TStringStream.Create; strS.LoadFromStream(ms); aPos:=pos(aStr,strS.dataString); found:=aPos>0; end; TStringStream is an often forgetten but very useful tool - easier and safer than messing with pChars, etc. For multiple

Highlight keywords in a pdf using itextsharp and render it to the browser

十年热恋 提交于 2020-01-06 19:32:28
问题 I have an existing pdf .I am using itextSharp to open the document and highlight keywords dynamically and when I save this into a file it works fine, but when I write it into a memory Stream and try to render it on the browser the highlights are not there. Here is the code public void SearchPDF() { //Create a new file from our test file with highlighting string highLightFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Highlighted.pdf"); // Stream //Bind a

MemoryStream looks like corrupt the file using iTextSharp

一笑奈何 提交于 2020-01-06 14:11:51
问题 I have two codes: string fileInput = @"c:\temp\input.pdf"; string fileOutput = @"c:\temp\saida.pdf"; PdfReader reader = new PdfReader(fileInput); Stream output = new System.IO.FileStream(fileOutput, System.IO.FileMode.Create); Document doc = new Document(); PdfCopy writer = new PdfCopy(doc, output); doc.Open(); PdfImportedPage pagina = writer.GetImportedPage(reader, 23); writer.AddPage(pagina); doc.Close(); output.Close(); It works very well! The file has 46.451 bytes But I need use Memory

How to convert base64 string to doc/docx in c#?

浪尽此生 提交于 2020-01-03 04:56:08
问题 I am working on mvc web based project, and want to convert base64 string to doc/docx file using c# ..I've idea about converting base64 to image file but don't have doc/docx file,have searched a lot but didn't get any solution. anyone have idea about this...? Thanks in advance.. 回答1: You can simply create rtf file Add system.windows.forms reference to your project RichTextBox rtb = new RichTextBox(); rtb.Text = "Base64String"; rtb.Save("Path"); And about creating docx file Use this open source

How do I send a PDF in a MemoryStream to the printer in .Net?

不打扰是莪最后的温柔 提交于 2020-01-03 02:27:46
问题 I have a PDF created in memory using iTextSharp and contained in a MemoryStream. I now need to translate that MemoryStream PDF into something the printer understands. I've used Report Server in the past to render the pages to the printer format but I cant use it for this project. Is there a native .Net way of doing this? For example, GhostScript would be OK if it was a .Net assembly but I don't want to bundle any non .Net stuff along with my installer. The PrintDocument class in .Net is great

.Net MemoryStream close issue

点点圈 提交于 2020-01-03 02:00:34
问题 For a .Net MemoryStream object instance, do I need to close it explicitly after using it? Or no need to close it? Which is the best practices? I am using VSTS2008 + .Net 3.5 + C#. 回答1: you should close it when you are done with it. The best practice is to close the stream in the finally section of a try-catch-finally block. you can get more information here: http://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx 回答2: Better yet would be to use Using using (MemoryStream ms = /*get

MemoryStream replacement?

北慕城南 提交于 2020-01-02 04:41:09
问题 A few weeks ago I read something about a new class in .Net 4/4.5 that performs better than MemoryStream, but I can't seem to find it anymore. I've looked in the IO namespace and could not find anything. Does anyone remember reading something like that? Thanks 回答1: Perhaps you read about Memory Tributary, a CodePlex project that provides a MemoryStream replacement better suited for large amounts of memory MemoryTributary is a MemoryStream replacement using multiple memory segments to store the

Asynchronous memory streaming approach: which of the following?

眉间皱痕 提交于 2020-01-02 03:46:06
问题 I am working on solution which uses asynchronous memory streaming and I am thinking about right approach for implementing such. Which one is more convenient? The first, simple: //First approach: linear async private async static Task WriteToStreamFirstVariant() { MemoryStream memoryStream = new MemoryStream(); byte[] data = new byte[256]; try { await memoryStream.WriteAsync(data, 0, data.Length); } catch(Exception exception) { //Handling exception } finally { memoryStream.Dispose(); } } Or

What is the best practice for storing a file upload to a MemoryStream (C#)?

天大地大妈咪最大 提交于 2020-01-01 17:26:16
问题 I need to temporary store a file upload to a MemoryStream. What would be the best method to do this using asp.net (3.5)? Here's what I have so far. It works (locally tested), but it does not look right to me. protected void lnkUploadFile_Click(object sender, EventArgs e) { MemoryStream memStream = new MemoryStream(); BinaryWriter sWriter = new BinaryWriter(memStream); foreach (byte b in flUpload.FileBytes) { sWriter.Write(b); } sWriter.Flush(); // writing to file to verify file stream