memorystream

iTextSharp is producing a corrupt PDF with Response

耗尽温柔 提交于 2019-11-28 08:28:11
问题 i tryed both, but still not working iTextSharp + FileStream = Corrupt PDF file iTextSharp is producing a corrupt PDF using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream()) { //abre o documento para poder editar document.Open(); //Adiciona os campos de assinatura document.Add(Assinatura()); //fecha o documento ao finalizar a edição document.Close(); //Prepara o download byte[] bytes = memoryStream.ToArray(); memoryStream.Close(); Response.Clear(); Response.ContentType =

MemoryStream must be explicitely be disposed?

淺唱寂寞╮ 提交于 2019-11-28 03:57:20
问题 As MemoryStream is an unmanaged resource does it always have to be disposed? Given: 1) A method is invoked. 2) A MemoryStream object is created (MemoryStream ms = new MemoryStream();). 3) An exception occurs and is caught from the invoking classes. The reference on the MemoryStream object is therefore lost. Does this scenario need a try/finally-block (or using-statement)? 回答1: In general, all disposable objects must always be disposed. However, MemoryStream doesn't actually need to be

How can I pass MemoryStream data to unmanaged C++ DLL using P/Invoke

断了今生、忘了曾经 提交于 2019-11-28 03:36:07
问题 I need your help with the following scenario: I am reading some data from hardware into a MemoryStream (C#) and I need to pass this data in memory to a dll implemented in unmanaged C++ (using pointer ??). The data read (into stream) is very large (megabytes). I understand that I can P/Invoke this dll but what I am not sure is how to pass the pointer / reference of the stream data to the C++ API ? I must admit I am confused as I am new to C# - do I need to use unsafe / fixed since data is

Getting PdfStamper to work with MemoryStreams (c#, itextsharp)

泄露秘密 提交于 2019-11-27 23:30:20
It came to me to rework old code which signs PDF files into new one, which signs MemoryStreams (byte arrays) that come and are sent by web services. Simple, right? Well, that was yesterday. Today I just can't get it to work. This is the old code, which uses FileStreams and it works: public static string OldPdfSigner(PdfReader pdfReader, string destination, string password, string reason, string location, string pathToPfx) { using (FileStream pfxFile = new FileStream(pathToPfx, FileMode.Open, FileAccess.Read)) { ... using (PdfStamper st = PdfStamper.CreateSignature(pdfReader, new FileStream

MemoryStream in Using Statement - Do I need to call close()

坚强是说给别人听的谎言 提交于 2019-11-27 22:55:48
问题 When using a memory stream in a using statement do I need to call close? For instance is ms.Close() needed here? using (MemoryStream ms = new MemoryStream(byteArray)) { // stuff ms.Close(); } 回答1: No, it's not. using ensures that Dispose() will be called, which in turn calls the Close() method. You can assume that all kinds of Streams are getting closed by the using statement. From MSDN: When you use an object that accesses unmanaged resources, such as a StreamWriter, a good practice is to

Error“ Parameter is not valid ” while converting Bytes into Image

百般思念 提交于 2019-11-27 09:26:30
I am converting bytes into an image but I get an error Parameter is not valid I am pasting my code. Kindly check the code and suggested that was I am doing right or wrong. Image arr1 = byteArrayToImage(Bytess); This is the function. public static Image byteArrayToImage(byte[] byteArrayIn) { if (null == byteArrayIn || byteArrayIn.Length == 0) return null; MemoryStream ms = new MemoryStream(byteArrayIn); try { Process currentProcess1 = Process.GetCurrentProcess(); Image returnImage = Image.FromStream(ms); return returnImage; } catch (Exception ex) { MessageBox.Show(ex.Message); } } I applied

Copy MemoryStream to FileStream and save the file?

折月煮酒 提交于 2019-11-27 08:12:51
I don't understand what I'm doing wrong here. I generate couple of memory streams and in debug-mode I see that they are populated. But when I try to copy MemoryStream to FileStream in order to save the file fileStream is not populated and file is 0bytes long (empty). Here is my code if (file.ContentLength > 0) { var bytes = ImageUploader.FilestreamToBytes(file); // bytes is populated using (var inStream = new MemoryStream(bytes)) // inStream is populated { using (var outStream = new MemoryStream()) { using (var imageFactory = new ImageFactory()) { imageFactory.Load(inStream) .Resize(new Size

Simpler way to create a C++ memorystream from (char*, size_t), without copying the data?

为君一笑 提交于 2019-11-27 07:06:12
I couldn't find anything ready-made, so I came up with: class membuf : public basic_streambuf<char> { public: membuf(char* p, size_t n) { setg(p, p, p + n); setp(p, p + n); } } Usage: char *mybuffer; size_t length; // ... allocate "mybuffer", put data into it, set "length" membuf mb(mybuffer, length); istream reader(&mb); // use "reader" I know of stringstream , but it doesn't seem to be able to work with binary data of given length. Am I inventing my own wheel here? EDIT It must not copy the input data, just create something that will iterate over the data. It must be portable - at least it

Serializing/deserializing with memory stream

守給你的承諾、 提交于 2019-11-27 03:56:15
I'm having an issue with serializing using memory stream. Here is my code: /// <summary> /// serializes the given object into memory stream /// </summary> /// <param name="objectType">the object to be serialized</param> /// <returns>The serialized object as memory stream</returns> public static MemoryStream SerializeToStream(object objectType) { MemoryStream stream = new MemoryStream(); IFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, objectType); return stream; } /// <summary> /// deserializes as an object /// </summary> /// <param name="stream">the stream to

Image.FromStream() method returns Invalid Argument exception

僤鯓⒐⒋嵵緔 提交于 2019-11-27 02:05:45
I am capturing images from a smart camera imager and receiving the byte array from the camera through socket programming (.NET application is the client, camera is the server). The problem is that i get System.InvalidArgument exception at runtime. private Image byteArrayToImage(byte[] byteArray) { if(byteArray != null) { MemoryStream ms = new MemoryStream(byteArray); return Image.FromStream(ms, false, false); /*last argument is supposed to turn Image data validation off*/ } return null; } I have searched this problem in many forums and tried the suggestions given by many experts but nothing