I've been running into a frustrating problem for a while now. I use
image.FromStrea m to open a tif, then perform some drawstring methods, and
then save the file again. The tiffs are in 1 bit per pixel format, so there
is some compression going on when we save the file. Quite a few files are
opened and closed. Everything seems to work fine for a couple hours. The
only draw back is the cpu is generally at 100%. Then the code starts failing
at the FromStream method call with the "Object reference not set to an
instance of an object."
The tif resides on the machine's hard drive and looks fine. The file stream
also looks fine. I can close the process and reopen and the tiff that just
failed will now succeed. I am relying on the stream.close and the image
object to go out of scope to close the image object. I'm not calling
dispose. Maybe this is the cause of the problem problem, the machine
eventually gets in a bad state. Any help would be greatly appreciated.
using( Stream stream = File.Open( sourceFile, FileMode.Open,
FileAccess.Read , FileShare.Read ) )
{
if( stream == null )
{
throw new Exception( ... );
}
try
{
// Don't use fromFile, it puts a lock on the file and it stays locked
// long after the imageObject goes out of scope.
image = System.Drawing. Image.FromStrea m( stream );
}
catch( Exception ex ){...}
image.drawstrin g(...)
save image with 1bit-per-pixel compression
} 3 4668
Thanks for the reply. My problem occurs on the FromStream call, so I
wouldn't even make it to the rotate methods. I don't think your problem is
quite the same, but I think your fix might help me elsewhere.
On another note, I've since added the Image.Dispose call to my code with no
success. I'm still running into the error on FromStream. The only extra
clue I have now is that occasionally I get an error from the dispose method
that says "This object is use elsewhere". What I don't know yet is if this
error is occuring at the same time I get the FromStream error, or 1 file
before.
"mattaku" wrote: Not sure if my problem is related. I've been trying to read in Image data from a memory stream after converting it from base64 text. I can read in an Image and set it as the Form1.backgroun dImage, but could not read in the base64 text data. This does work for other Images, but not backgroundImage properties. Well, I read some other threads elsewhere and noticed that someone fixed some other "FromStream " method bug by rotating the Image. Well, sure enough, my code started to work! Don't ask me why.
byte[] byteArray = Convert.FromBas e64String( base64String ); MemoryStream memStrm = new MemoryStream( byteArray, 0, byteArray.Lengt h ); retObj = Image.FromStrea m( memStrm );
// these next two lines is to fix a weird C#/.Net bug ((Image)retObj) .RotateFlip( RotateFlipType. Rotate180FlipNo ne ); ((Image)retObj) .RotateFlip( RotateFlipType. Rotate180FlipNo ne ); memStrm.Close() ;
"CanyonJ" wrote:
I've been running into a frustrating problem for a while now. I use image.FromStrea m to open a tif, then perform some drawstring methods, and then save the file again. The tiffs are in 1 bit per pixel format, so there is some compression going on when we save the file. Quite a few files are opened and closed. Everything seems to work fine for a couple hours. The only draw back is the cpu is generally at 100%. Then the code starts failing at the FromStream method call with the "Object reference not set to an instance of an object." The tif resides on the machine's hard drive and looks fine. The file stream also looks fine. I can close the process and reopen and the tiff that just failed will now succeed. I am relying on the stream.close and the image object to go out of scope to close the image object. I'm not calling dispose. Maybe this is the cause of the problem problem, the machine eventually gets in a bad state. Any help would be greatly appreciated.
using( Stream stream = File.Open( sourceFile, FileMode.Open, FileAccess.Read , FileShare.Read ) ) { if( stream == null ) { throw new Exception( ... ); }
try { // Don't use fromFile, it puts a lock on the file and it stays locked // long after the imageObject goes out of scope. image = System.Drawing. Image.FromStrea m( stream ); } catch( Exception ex ){...}
image.drawstrin g(...) save image with 1bit-per-pixel compression }
I don't need to rotate my image either...
The solution is to just rotate the image 180 degrees then back 180 degrees.
This "fixes" something wrong with the Image object. Try it.
"CanyonJ" wrote: Thanks for the reply. My problem occurs on the FromStream call, so I wouldn't even make it to the rotate methods. I don't think your problem is quite the same, but I think your fix might help me elsewhere.
On another note, I've since added the Image.Dispose call to my code with no success. I'm still running into the error on FromStream. The only extra clue I have now is that occasionally I get an error from the dispose method that says "This object is use elsewhere". What I don't know yet is if this error is occuring at the same time I get the FromStream error, or 1 file before.
"mattaku" wrote:
Not sure if my problem is related. I've been trying to read in Image data from a memory stream after converting it from base64 text. I can read in an Image and set it as the Form1.backgroun dImage, but could not read in the base64 text data. This does work for other Images, but not backgroundImage properties. Well, I read some other threads elsewhere and noticed that someone fixed some other "FromStream " method bug by rotating the Image. Well, sure enough, my code started to work! Don't ask me why.
byte[] byteArray = Convert.FromBas e64String( base64String ); MemoryStream memStrm = new MemoryStream( byteArray, 0, byteArray.Lengt h ); retObj = Image.FromStrea m( memStrm );
// these next two lines is to fix a weird C#/.Net bug ((Image)retObj) .RotateFlip( RotateFlipType. Rotate180FlipNo ne ); ((Image)retObj) .RotateFlip( RotateFlipType. Rotate180FlipNo ne ); memStrm.Close() ;
"CanyonJ" wrote:
I've been running into a frustrating problem for a while now. I use image.FromStrea m to open a tif, then perform some drawstring methods, and then save the file again. The tiffs are in 1 bit per pixel format, so there is some compression going on when we save the file. Quite a few files are opened and closed. Everything seems to work fine for a couple hours. The only draw back is the cpu is generally at 100%. Then the code starts failing at the FromStream method call with the "Object reference not set to an instance of an object." The tif resides on the machine's hard drive and looks fine. The file stream also looks fine. I can close the process and reopen and the tiff that just failed will now succeed. I am relying on the stream.close and the image object to go out of scope to close the image object. I'm not calling dispose. Maybe this is the cause of the problem problem, the machine eventually gets in a bad state. Any help would be greatly appreciated.
using( Stream stream = File.Open( sourceFile, FileMode.Open, FileAccess.Read , FileShare.Read ) ) { if( stream == null ) { throw new Exception( ... ); }
try { // Don't use fromFile, it puts a lock on the file and it stays locked // long after the imageObject goes out of scope. image = System.Drawing. Image.FromStrea m( stream ); } catch( Exception ex ){...}
image.drawstrin g(...) save image with 1bit-per-pixel compression }
Sorry, I didn't read your response that closely. Ignore previous response.
:) Can you try to read in the file into a buffer and create a memoryStream
(just to see if that works)?
"mattaku" wrote: I don't need to rotate my image either...
The solution is to just rotate the image 180 degrees then back 180 degrees. This "fixes" something wrong with the Image object. Try it.
"CanyonJ" wrote:
Thanks for the reply. My problem occurs on the FromStream call, so I wouldn't even make it to the rotate methods. I don't think your problem is quite the same, but I think your fix might help me elsewhere.
On another note, I've since added the Image.Dispose call to my code with no success. I'm still running into the error on FromStream. The only extra clue I have now is that occasionally I get an error from the dispose method that says "This object is use elsewhere". What I don't know yet is if this error is occuring at the same time I get the FromStream error, or 1 file before.
"mattaku" wrote:
Not sure if my problem is related. I've been trying to read in Image data from a memory stream after converting it from base64 text. I can read in an Image and set it as the Form1.backgroun dImage, but could not read in the base64 text data. This does work for other Images, but not backgroundImage properties. Well, I read some other threads elsewhere and noticed that someone fixed some other "FromStream " method bug by rotating the Image. Well, sure enough, my code started to work! Don't ask me why.
byte[] byteArray = Convert.FromBas e64String( base64String ); MemoryStream memStrm = new MemoryStream( byteArray, 0, byteArray.Lengt h ); retObj = Image.FromStrea m( memStrm );
// these next two lines is to fix a weird C#/.Net bug ((Image)retObj) .RotateFlip( RotateFlipType. Rotate180FlipNo ne ); ((Image)retObj) .RotateFlip( RotateFlipType. Rotate180FlipNo ne ); memStrm.Close() ;
"CanyonJ" wrote:
> I've been running into a frustrating problem for a while now. I use > image.FromStrea m to open a tif, then perform some drawstring methods, and > then save the file again. The tiffs are in 1 bit per pixel format, so there > is some compression going on when we save the file. Quite a few files are > opened and closed. Everything seems to work fine for a couple hours. The > only draw back is the cpu is generally at 100%. Then the code starts failing > at the FromStream method call with the "Object reference not set to an > instance of an object." > The tif resides on the machine's hard drive and looks fine. The file stream > also looks fine. I can close the process and reopen and the tiff that just > failed will now succeed. I am relying on the stream.close and the image > object to go out of scope to close the image object. I'm not calling > dispose. Maybe this is the cause of the problem problem, the machine > eventually gets in a bad state. Any help would be greatly appreciated. > > using( Stream stream = File.Open( sourceFile, FileMode.Open, > FileAccess.Read , FileShare.Read ) ) > { > if( stream == null ) > { > throw new Exception( ... ); > } > > try > { > // Don't use fromFile, it puts a lock on the file and it stays locked > // long after the imageObject goes out of scope. > image = System.Drawing. Image.FromStrea m( stream ); > } > catch( Exception ex ){...} > > image.drawstrin g(...) > save image with 1bit-per-pixel compression > } > This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: DotNetJunkies User |
last post by:
i am using a dll that places an image data in memory and returns to me two wariable long P1 and long P2
i am using C#
P1 is the memory address and P2 is the number of bytes written
i want to place this image in a picturebox named pictureBox1 how can i do this
in c++ the code works like this
stream.write((void*) P1,P2);
its equavalent in C# should be
Stream str = new MemoryStream()
str.Write((void*) P1,0,P2);
|
by: Anonieko Ramos |
last post by:
> I have a graphics images that I want to convert to
> ASCII art. How do I do it?
>
Code:
- Default.aspx.cs
|
by: Saya |
last post by:
Hello,
This is a repost 'cause I haven't solve the problem: I can't use the
System.Drawing class 'Image.FromStream' in the CompactFramework
environment. What I've done with respect to Brendan's suggestion is as
follows:
Brendan, thanks for the reply!
I'm a little bit further now, but not yet finished.
I've come this far, see code below:
Stream s =
|
by: Mchuck |
last post by:
I've seen several newsgroup topics everywhere concerning
this, as well as a couple of articles from the MSDN
website, but this error still baffles me.
It has to do with using the Image.FromStream(...) function
to load an image into a PictureBox control from a byte
array received from an SQL Server database. Here's a
snippet of what I've been trying to achieve:
----------------------------
|
by: CanyonJ |
last post by:
I've been running into a frustrating problem for a while now. I use
image.FromStream to open a tif, then perform some drawstring methods, and
then save the file again. The tiffs are in 1 bit per pixel format, so there
is some compression going on when we save the file. Quite a few files are
opened and closed. Everything seems to work fine for a couple hours. The
only draw back is the cpu is generally at 100%. Then the code starts...
| |
by: Lance |
last post by:
hey all,
first time vb.net 2005 user, after sticking vb6 out for a long time...
anyway, using this code
======================
Dim FS As FileStream = File.OpenRead(Filename)
Dim theImage As Image
Try
theImage = Image.FromStream(FS, False, False)
|
by: John Daly |
last post by:
Does anyone know how to create an image (JPEG) from an HTTPResponse object? I
am working on system that has a map pop up from our GIS department. I want
create an image at runtime from this popup and display that image on the main
page instead of opening a new window. This image will be a memory stream
only, but will need to be kept from page to page, and printer if required.
Any help will be much appreciated. If anyone knows of any...
|
by: bookon |
last post by:
I was running into the System.Drawing.Image.FromStream "parameter is
not valid" on some of the images I was retrieving from a blob column in
Sql Server. I thought there were corrupt images as almost all worked
(all are gifs), and only a few broke when this line ran: Image img =
Image.FromStream(ms); here is the original code:
b = (byte)dt.Rows.ItemArray;
//b.ToString()
ms = new MemoryStream();
ms.Write(b, 0, b.Length);
|
by: =?Utf-8?B?UmludSBHb3BhbGFrcmlzaG5hIFBpbGxhaQ==?= |
last post by:
Hi,
Please help me to write a dll in C# , that will read each pages of a
tiff image from a file and a memory stream object ( need two ways) and
creatre a new tiff image object.The dll should return the combined tif image
object.
Thnks in advance
Rinu G P
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |