 |
|
|
 |
|
 |
Hi
I want to know how to extract data from bmp image file like pixel data, number of rows,number od columns, bits allocated (bit depth) etc.
Please suggest or tell me any article is available or not.
Thanks
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
Read the MSDN documentation for this.
Or, a very good explanation is given by Charles Petzold in his book "Programming Windows", 5th Edition. This book has a chapter on the Windows BMP format.
The BMP format itself is quite simple. The file will have a header, followed by pixel data. You need to interpret the pixel data based on the information given in the header.
- Amarnath
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
|
 |
|
 |
Hi,
Very simple code in VS9 C# below takes a JPEG presented to me as a byte[] and converts it to an image. The same code fails when presented a byte[] of a JPEG2000 file. I'm about to conclude MS GDI still (in 2009) can't handle JPEG2000, but thought I'd first see if anyone knew differently.
byte[] baImageData; using (var mStream = new MemoryStream(baImageData)) { //Image imageFullSize = new Bitmap(mStream); Image imageFullSize = Image.FromStream(mStream); ... mStream.Close(); }
Commented line shows another attempt that failed with same invalid param exception.
AJ
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
 |
I want to create an image from an byte array having information about the image.... the code i m doing is [code]
InputStream in=getClass().getResourceAsStream("/qoute.png"); int length=in.read(); byte[] buff=new byte[length]; size=in.read(buff); img=Image.createImage(buff,0,buff.length);// giving Illegal argument exception [\code]
when it create an image the ode throws an exception IllegalArgument Exception.....
Plz help me bcoz i want it for my project
|
| Sign In·View Thread·PermaLink | 1.00/5 (2 votes) |
|
|
|
 |
|
 |
In a real world application, to avoid consuming unused memory you should make sure the stream is closing when everything is done:
using (MemoryStream ms = new MemoryStream()) { imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif); return ms.ToArray(); }
It's easy because of the IDisposable interface. Best regards!
MCTS, MCP
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Hi Folk..your code works in .net 2.0 or .net 1.1 .. but it doesnt work in .net 3.5 can you tell me how to go about with this...
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
The Image.FromStream method defines an exception:
The stream does not have a valid image format-or-stream is null.
I am trying to convert an arbitrary byte array (an encryption key) to an image (for safer storage). I keep getting the error 'Parameter is not valid' which suggest to me that my arbitrary byte array is not a valid image format.
I am concluding that this method only works when you convert an image to a byte array and back, not when you start with an arbitrary byte array.
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
 |
Aye, that's true. You must remember that the data contained in a byte array derived from an image is not merely bytes that get translated into pixel colors arbitrarily. The byte array also must contain header information and be internally formatted according to one of the useable image types (GIF, JPEG, etc...).
If you just send an arbitrary byte array, the chances that it will happen to have the correct format to let it be turned into an image are extremely remote. You might be able to pull it off by adding header and other needed information into the byte array, but that could be complex and still might not work.
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
I have to store icon files into database. System.Drawing.Imaging.ImageFormat.Icon does not work. So I used .Bmp instead & the first method works fine.
first method:
private byte[] ConvertImageToByte(Image image) { MemoryStream ms = new MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); return ms.ToArray(); }
second method:
private Image ConvertByteToImage(byte[] byteImage) { MemoryStream ms = new MemoryStream(byteImage); Image newImage = Image.FromStream(ms); :confused: return newImage; }
But the above code throws exception for second method saying invalid arguments at second line. Is there any particular reason. Please let me know.
Thanks in
-- modified at 18:39 Thursday 22nd November, 2007
|
| Sign In·View Thread·PermaLink | 5.00/5 (3 votes) |
|
|
|
 |
|
 |
I am getting the same error when trying to convert a byte array to an image. At the line you have indicated, I get the error: 'Parameter is not valid.' Any thoughts on why?
|
| Sign In·View Thread·PermaLink | 3.00/5 (2 votes) |
|
|
|
 |
|
 |
Same. I'm getting the impression that there must be a way to load a particular encoding, because saving the image out as a TIFF and then reloading and converting the stream (for testing) is giving this same exception. Any ideas would be greatly appreciated.
- Lance 'ji' May
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
Very good convert to Binary, it was just what I was looking for.
Here is some addtional code that will use a page to render and image into the Image control from another page.
Image1.ImageUrl = "RenderImage.aspx";
** The Code Below is RenderImage.aspx - This will resize the image and render it to the browser. The calling page will now have the image.
private void ResizeAndRenderImage(System.Drawing.Image image, int height, int width, string contentType) { //Orignal Image System.Drawing.Image FullSizeImg = image; //Dummy callback, for what I have no idea System.Drawing.Image.GetThumbnailImageAbort dummyCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
//The resized image System.Drawing.Image ThumbNailImg = FullSizeImg.GetThumbnailImage(width, height, dummyCallBack, IntPtr.Zero);
System.Drawing.Imaging.ImageFormat ImgFormat; ImgFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
switch (contentType.Trim().ToLower()) { case "image/pjpeg": ImgFormat = System.Drawing.Imaging.ImageFormat.Jpeg; break; case "image/x-png": ImgFormat = System.Drawing.Imaging.ImageFormat.Png; break; case "image/gif": ImgFormat = System.Drawing.Imaging.ImageFormat.Gif; break; } //Convert the image to byte and set image type MemoryStream Imagems = new MemoryStream(); ThumbNailImg.Save(Imagems, ImgFormat);
//Render the image so the Image on the calling page gets it. Response.Clear(); Response.ContentType = ContentType; Response.BinaryWrite(Imagems.ToArray());
FullSizeImg.Dispose(); ThumbNailImg.Dispose(); } public bool ThumbnailCallback() { return false; }
Just contact me if you want all the code.
Use my contact page at www.SURFThru.com
.
|
| Sign In·View Thread·PermaLink | 3.50/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
 |