c# - Loading, saving, and then loading an image again throws "A generic error occurred in GDI+" -
I remember that for a different code a while ago, but it's back , with a retaliation, but with some new code I can not seem to know.
This is definitely normal
, to make sure!
Target
I am trying to create a form that allows the user:
- Select an image.
- Save (which closes the form), and saves the image to
byte []
in the database. - Open the form (which
byte [] ) loads the image. - Allow them to save again.
- Allow them to open the form again, display the picture (again).
A very standard load / save situation.
The problem
Everything works well for loading and saving SQL Server. The problem I am experiencing is to do it again and again with a byte []
and save along with it, though I am using the same settings. Take a look at this code , Which I have mixed to display the problem:
static zero main (string [] arg) {// start image initial image = (bitmap) bitmapfof file (@ 'D : \ Picture.jpg "); // save in a memory stream and bytes r Receive the initial image bites = SaveimageTobbets; // Reload this saved image; Bitmap bitloaded image = Load imageflowbits; // save in bytes again; throws "GDI + has a common error. Var secondary imagebits = save image tags (personalized byte);} Private static byte [] Seymite notebooks (bitmap image) {byte [] imageBytes; (MemoryStream imagestream = new memories Use Rim ()) (Fig. Save (Cvistrym, Image. Roformet); // "There was a general error in GDI +." Threw saved second imageBytes = imageStream.ToArray (); } Returns image bits; } Private static bitmap load imagefolbets (byte [] bytes) {(memorystream imagestream = new memorystream (bytes)) {bitmap image = (bitmap) bitmap. Firststream; Return image; }}
Error A typical error occurred in GDI.
is thrown because the image is saved for MemoryStream
the time period I checked the time before saving before RawFormat
by inspecting the value Second was not done before: Save
1: Save {b96b3cae-0728- 11d3-9d7b-0000f81ef32e} 2: {b96b3cae-0728-11d3-9d7b-0000f81ef32e}
Values are the same, so this can not be a problem in losing image format
information.
Can anyone help debug this problem? The code sample I used has been tested with JPEG, and
I had the same belief that I had the same recent problem you used to build your MemoryStream around We have to leave the statement that will be left. Creating bitmaps refers to the stream that it had created. You can read it about it.
Private static bitmap load imagefolbets (byte [] bytes) {var imageStream = new memorystream (bytes)) var image = (bitmap) bitmap. Formstream (imagestream); Return image; }
Comments
Post a Comment