memorystream

MemoryStream usage leads to out of memory exception

北慕城南 提交于 2019-12-30 08:35:42
问题 I'am facing issues when using MemoryStream multiple times. Example: For Each XImage As XImage In pdfDocument.Pages(pageCount).Resources.Images Dim imageStream As New MemoryStream() XImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg) ' some further processing imageStream.Close() imageStream.Dispose() Next This piece of code cycles through images on a page of PDF file. The file may have up to cca 500 pages, lets say 5 images on each page. It leads to thousands of iterations. The

Why is there a memory leak when I do not .Dispose() Bitmaps that I .Save() to a MemoryStream?

非 Y 不嫁゛ 提交于 2019-12-30 07:13:45
问题 Say I create a Bitmap Bitmap bitmap = new Bitmap(320, 200); When I write it to some stream (in my case, it's a HttpResponseStream, as given out by HttpListenerResponse), everything is fine: bitmap.Save(stream, ImageFormat.Png); I don't need to bitmap.Dispose(), the resources used by the bitmap will get cleaned up automatically. The problem with directly writing a Png to a non-seekable stream however is that it might result in A generic error occurred in GDI+, which happened to me when I tried

Why is there a memory leak when I do not .Dispose() Bitmaps that I .Save() to a MemoryStream?

你离开我真会死。 提交于 2019-12-30 07:13:16
问题 Say I create a Bitmap Bitmap bitmap = new Bitmap(320, 200); When I write it to some stream (in my case, it's a HttpResponseStream, as given out by HttpListenerResponse), everything is fine: bitmap.Save(stream, ImageFormat.Png); I don't need to bitmap.Dispose(), the resources used by the bitmap will get cleaned up automatically. The problem with directly writing a Png to a non-seekable stream however is that it might result in A generic error occurred in GDI+, which happened to me when I tried

How to run unmanaged executable from memory rather than disc

核能气质少年 提交于 2019-12-29 05:25:09
问题 I want to embed a command-line utility in my C# application, so that I can grab its bytes as an array and run the executable without ever saving it to disk as a separate file (avoids storing executable as separate file and avoids needing ability to write temporary files anywhere). I cannot find a method to run an executable from just its byte stream. Does windows require it to be on a disk, or is there a way to run it from memory? If windows requires it to be on disk, is there an easy way in

Composite Stream Wrapper providing partial MemoryStream and full original Stream

放肆的年华 提交于 2019-12-29 01:38:32
问题 Does anyone know of a composite stream solution that will pre-load the first portion of a Stream in to a MemoryStream and keep the remainder as the original Stream which will be accessed when subsequent parts are required as necessary? I should imagine some wrapper class would implement the Stream interface and transparently juggle the access between the two streams depending upon which part is accessed. I'm hoping this is a solution someone may have solved before, maybe to optimize

Merge memorystreams to one iText document

梦想与她 提交于 2019-12-28 16:08:12
问题 I have four MemoryStreams of data that I want to merge and then open the pdfDocument, without creating a single file. It's possible to write them down to files and then merge them but that would be bad practice and that can also cause a few issues so I want to avoid that. However, I can not find a way to merge the MemoryStreams with iText5 for .NET. Right now, this is how I do it with files: private static void ConcatenateDocuments() { var stream = new MemoryStream(); var readerFrontPage =

When is GetBuffer() on MemoryStream ever useful?

荒凉一梦 提交于 2019-12-28 05:56:29
问题 I've known that GetBuffer() on a MemoryStream in C#/.NET has to be used with care, because, as the docs describe here, there can be unused bytes at the end, so you have to be sure to look only at the first MemoryStream.Length bytes in the buffer. But then I ran into a case yesterday where bytes at the beginning of the buffer were junk! Indeed, if you use a tool like reflector and look at ToArray() , you can see this: public virtual byte[] ToArray() { byte[] dst = new byte[this._length - this.

How to bind a MemoryStream to asp:image control?

耗尽温柔 提交于 2019-12-27 11:44:06
问题 Is there a way to bind a MemoryStream to asp:image control? 回答1: A handler can accept a url parameter like any other request. So instead of linking your <asp:image/> to image.ashx you'd set it to image.ashx?ImageID=[Your image ID here] . 回答2: Best bet is to create an HttpHandler that would return the image. Then bind the ImageUrl property on the asp:Image to the url of the HttpHandler. Here is some code. First create the HttpHandler: <%@ WebHandler Language="C#" Class="ImageHandler" %> using

Creating WPF BitmapImage from MemoryStream png, gif

柔情痞子 提交于 2019-12-27 11:43:12
问题 I am having some trouble creating a BitmapImage from a MemoryStream from png and gif bytes obtained from a web request. The bytes seem to be downloaded fine and the BitmapImage object is created without issue however the image is not actually rendering on my UI. The problem only occurs when the downloaded image is of type png or gif (works fine for jpeg). Here is code that demonstrates the problem: var webResponse = webRequest.GetResponse(); var stream = webResponse.GetResponseStream(); if

Creating WPF BitmapImage from MemoryStream png, gif

﹥>﹥吖頭↗ 提交于 2019-12-27 11:43:10
问题 I am having some trouble creating a BitmapImage from a MemoryStream from png and gif bytes obtained from a web request. The bytes seem to be downloaded fine and the BitmapImage object is created without issue however the image is not actually rendering on my UI. The problem only occurs when the downloaded image is of type png or gif (works fine for jpeg). Here is code that demonstrates the problem: var webResponse = webRequest.GetResponse(); var stream = webResponse.GetResponseStream(); if