473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Non-standard image formats

Language: C#

I have written a library of image processing functions that work on a System.Drawing.Image object. Works fine for BMPs and JPEGs and PNGs and the like. Yesterday my boss told me the next step is to be able to handle proprietary formats that some of our clients use. All of them follow a basic principle: some header, then pixel values. So to get started the first file format is simply pixel values as raw data.

So I've read a file in through a filestream and converted them to a byte[] the length of the file stream. This works for standard images also However I cannot just create an image object from the standard array. I will need to take my pixel values and write a bitmap, and that will be my image object.
How do I do this?

Thank you.
Jan 18 '07 #1
5 1149
Motoma
3,237 Expert 2GB
Language: C#

I have written a library of image processing functions that work on a System.Drawing.Image object. Works fine for BMPs and JPEGs and PNGs and the like. Yesterday my boss told me the next step is to be able to handle proprietary formats that some of our clients use. All of them follow a basic principle: some header, then pixel values. So to get started the first file format is simply pixel values as raw data.

So I've read a file in through a filestream and converted them to a byte[] the length of the file stream. This works for standard images also However I cannot just create an image object from the standard array. I will need to take my pixel values and write a bitmap, and that will be my image object.
How do I do this?

Thank you.

You will need to create a Bitmap object, and use the SetPixel() method, iterating through both your dataset and the bitmap to draw the image.
Jan 18 '07 #2
You will need to create a Bitmap object, and use the SetPixel() method, iterating through both your dataset and the bitmap to draw the image.
Won't that be incredibly slow? The image files are about 16MB.

Also, to create the bitmap object I will need to know the height and width of the image. If I just have the byte[] containing the pixel values, how will I know the height and width?

The sample images I have are arranged like this:

5718 rows x 1472 columns of unsigned words (16 bit data)
5894 rows x 1472 columns of unsigned words (16 bit data)
5700 rows x 1472 columns of unsigned words (16 bit data)
Jan 18 '07 #3
Motoma
3,237 Expert 2GB
Won't that be incredibly slow? The image files are about 16MB.
Yes, however, dealing with bitmaps this large is almost always slow.

Also, to create the bitmap object I will need to know the height and width of the image. If I just have the byte[] containing the pixel values, how will I know the height and width?

The sample images I have are arranged like this:

5718 rows x 1472 columns of unsigned words (16 bit data)
5894 rows x 1472 columns of unsigned words (16 bit data)
5700 rows x 1472 columns of unsigned words (16 bit data)
I'm sorry, I am a little confused.
It seams like you know the dimensions of your images, they all seem to have a1472 columns (I am assuming width?).
You could always use headers you mentioned would be attached, or the extrapolate size based on the amount of data you read in.
Regardless of the image format you use, you will still need to know the dimensions of your image.
If you need a quicker method of drawing bitmaps, you may have to read up on the standard, there probably is a way you could write the raw pixel data into memory.

Sorry I couldn't be more help.
Jan 18 '07 #4
I know that each has a width of 1472 pixels. The height is variable and depends on the image. Can I do

byte[] array;

int bmpWidth = 1472;
int bmpHeight = (array.Length/bmpWidth)/2;
Bitmap bitmap = new Bitmap(bmpWidth, bmpHeight, PixelFormat.Format16bppGrayScale);

If so, how can I read it in using setpixel?
Jan 18 '07 #5
Motoma
3,237 Expert 2GB
I know that each has a width of 1472 pixels. The height is variable and depends on the image. Can I do

byte[] array;

int bmpWidth = 1472;
int bmpHeight = (array.Length/bmpWidth)/2;
Bitmap bitmap = new Bitmap(bmpWidth, bmpHeight, PixelFormat.Format16bppGrayScale);
If the width is always 1472 px, and you want the image to be in 16bit Grayscale, then yes, this all looks correct.


If so, how can I read it in using setpixel?
Itterating through your array with nested for loops, you will need to cast every two bytes as a Color, and then use setpixel with the X and Y positions.

Pseudo code:

Expand|Select|Wrap|Line Numbers
  1. for(int x = 0; y < bmpHeight; x++)
  2.   for(int y = 0; y < 1742; y++)
  3.     bitmap.SetPixel(x, y, (color)array[(y*1472+x)*2]);
  4.  
I am quite sure that this code won't run, as the cast to a color from is sure to be incorrect.
I hope this helps you.
Jan 18 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: lothar | last post by:
re: 4.2.1 Regular Expression Syntax http://docs.python.org/lib/re-syntax.html *?, +?, ?? Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few...
5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
25
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
32
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
8
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I...
11
by: ypjofficial | last post by:
Hello All, So far I have been reading that in case of a polymorphic class ( having at least one virtual function in it), the virtual function call get resolved at run time and during that the...
2
by: Ian825 | last post by:
I need help writing a function for a program that is based upon the various operations of a matrix and I keep getting a "non-aggregate type" error. My guess is that I need to dereference my...
0
by: amitvps | last post by:
Secure Socket Layer is very important and useful for any web application but it brings some problems too with itself. Handling navigation between secure and non-secure pages is one of the cumbersome...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
12
by: puzzlecracker | last post by:
is it even possible or/and there is a better alternative to accept input in a nonblocking manner?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.