Hi all!
I have problems when writting bitmap to a byte array and after reading it
back form byte[] to Bitmap object.
What I do is this: First I throw Bitmap to a memory-stream and then I write
it into byte[] from a stream.
Exception (System.Argumen tException: Invalid parameter used) occurs when
reading from byte[] over a memory-stream back to the Bitmap object.
Please help, I'm really stuck here!
Here's the code I use (Sorry for a long post):
private void btn_Start_Click (object sender, System.EventArg s e)
{
byte[] imageData;
imageData = this.ImageToByt eArray();
this.GetImageFr omByteArray(ima geData);
}
private byte[] ImageToByteArra y()
{
// Store thumbnail image into the thumbnailImage row
long _quality = 50;
// Add thumbnail image as byte array (OLE object)
System.IO.Strea m memoryStream =
this.BitmapToMe moryStream((Bit map)this.source ImageBox.Image,
ImageFormat.Jpe g, _quality);
//MemoryStream memoryStream = new MemoryStream();
//_thumbnail.Thum bnailImage.Save (memoryStream, ImageFormat.Jpe g);
byte[] rawData = new byte[memoryStream.Le ngth];
memoryStream.Re ad(rawData, 0, System.Convert. ToInt32(memoryS tream.Length));
memoryStream.Cl ose();
return rawData;
}
private MemoryStream BitmapToMemoryS tream(Bitmap _image, ImageFormat
_format, long _quality)
{
// Create MemoryStream object
MemoryStream memoryStream = new MemoryStream();
// Save the Bitmap to the Stream. If it's
// in JPEG format, save with the specified
// Quality level.
if (_format != ImageFormat.Jpe g)
{
// Save non-JPEG images withoug
// adjusting the Quality level
_image.Save(mem oryStream, _format);
}
else
{
// Adjust quality level of JPEG images.
// Create an EncoderParamete rs object containing the Quality level as a
// parameter.
EncoderParamete rs Params = new EncoderParamete rs(1);
Params.Param[0] = new EncoderParamete r(Encoder.Quali ty, _quality);
// Save the image using the JPEG encoder
// with the specified Quality level.
_image.Save(mem oryStream, this.GetEncoder Info("image/jpeg"), Params);
}
return memoryStream;
}
private ImageCodecInfo GetEncoderInfo( String mimeType)
// Return an encoder of the specified Mime type
// (e.g. "image/jpeg").
{
ImageCodecInfo Result = null;
ImageCodecInfo[] Encoders = ImageCodecInfo. GetImageEncoder s();
for(int i = 0; Result == null && i < Encoders.Length ; i++)
{
if (Encoders[i].MimeType == mimeType)
{
Result = Encoders[i];
}
}
return Result;
}
public void GetImageFromByt eArray(byte[] _rawData)
{
try
{
// Read data to a stream
byte[] rawData = new byte[0];
rawData = (byte[])_rawData;
int len = new int();
len = rawData.GetUppe rBound(0);
// Make a MemoryStream object to store bitmap from database
System.IO.Strea m memStream = new MemoryStream(ra wData);
// Make a bitmap object from a memory-stream
Bitmap image = new Bitmap(memStrea m);
memStream.Close ();
this.destinatio nImageBox.Image = (Bitmap)image;
}
catch(Exception e)
{
MessageBox.Show (e.ToString(), "GetImageFromBy teArray",
MessageBoxButto ns.OK, MessageBoxIcon. Exclamation);
}
} 0 3606 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Martyn Wynne |
last post by:
Hi,
Can anyone please tell me if there is any reason why when i am streaming
from a webrequest (decompressing on route) to a file on the hard drive, i
would be getting an exception of Filestream error
System.StackOverflowException every time the file gets to 8580Kbs.
Code is basically a modified Microsoft example, it errors on the line
Dim ar As IAsyncResult = _
|
by: Frank Jones |
last post by:
When manually running resgen.exe from the command prompt (Visual Studio .NET
2003 command prompt) I get the following error:
error: Invalid ResX input.
error: Specific exception: SerializationException Message: Invalid
ResX input. ---> SerializationException: Cannot find the assembly Common,
Version=1.0.1905.1173, Culture=neutral, PublicKeyToken=null.
2 error(s).
The file within the project it is erroring on is a custom control.
|
by: David Veeneman |
last post by:
This post is for the Google archive and does not require a reply.
I received an 'Invalid parameter used' error when trying to do
double-buffering with the .Net SetStyles method. I used this code in the
constructor of my UserControl to implement double buffering:
// Enable double buffering
this.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint,
|
by: Matthew Louden |
last post by:
I want to read how many records in the table, and insert a record with id
field which increment the counter by 1. However, I had the following runtime
on Dim s As Integer = CInt(dr("t")). Since "t" (I want to represent the
count, but just a tempoary variable, not a field in table) doesnt exist in
the table
sqlStmt = "SELECT COUNT(*) As t FROM TimeSlot;"
cmd = New SqlCommand(sqlStmt, conn)
cmd.Connection.Open()
|
by: Patrick.O.Ige |
last post by:
What could cause the error:-
System.NullReferenceException: Object reference not set to an instance of an
object.
Any ideas?
| |
by: Simon Harris |
last post by:
I have created a web service, which when I call in my browser presents the
text form etc. When I click the button, I get this error:
System.ArgumentException: Cannot convert to System.Int32.
Parameter name: type ---> System.FormatException: Input string was not in
a
correct format.
at System.Number.ParseInt32(String s, NumberStyles style,
NumberFormatInfo info)
at System.String.System.IConvertible.ToInt32(IFormatProvider provider)
|
by: Harshil |
last post by:
Hi All,
I am working on Vb.net application with oracle as my database. I have
developed reports using crystal report 9. Usually when you open reports
directly in crystal report viewer control it prompts you for any
necessary login information. My goal was to provide the login
information by means of code, so that the user is not prompted for any
login information. I tried to write the following code to achieve that
purpose. On running the...
|
by: CQ |
last post by:
Hi everyone,
I get the following error when compiling my code:
error: invalid initialization of non-const reference of type 'Vertex&'
from a temporary of type 'int'
The implementation of the function is as follows:
Vertex& IGEdge::Mate (Vertex const& vertex) {
|
by: Eric |
last post by:
I run a program which read emails from a text file. There is some thing
invalid in one or more text file. When program is busy doing parsing it
shows that error and process stop. I dont know which text file has that
error. Is it possible that i can handle that error during processing
some thing i mean ignore line, email so that my process will not be
interrupt.
Error: Invalid Procedure call or argument
Run time error 5
|
by: The|Godfather |
last post by:
Hi everybody,
I read Scotte Meyer's "Effective C++" book twice and I know that
he mentioned something specific about constructors and destructors that
was related to the
following error/warning: "error: invalid use of nonstatic data member "
However, he did NOT mention this error in the book explicitly.It
happens always in the constructor when you try to initialize some data
members in the constructor and try to accsess other data...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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.
| |