- PictureBox PictureBox1 = new PictureBox();
-
public void display(String filename)
-
{
-
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
-
BinaryReader br = new BinaryReader(fs);
-
if (br.ReadChar().ToString() + br.ReadChar().ToString() == "BM")
-
{
-
int bfSize = br.ReadInt32();
-
int bfReserved1 = br.ReadInt16();
-
int bfReserved2 = br.ReadInt16();
-
int bfoffbits = br.ReadInt32();
-
int biSize = br.ReadInt32();
-
int biWidth = br.ReadInt32();
-
int biHeight = br.ReadInt32();
-
int biPlanes = br.ReadInt16();
-
int biBitCount = br.ReadInt16();
-
int biCompression = br.ReadInt32();
-
int biSizeImage = br.ReadInt32();
-
int biXPelsPerMeter = br.ReadInt32();
-
int biYPelsPerMeter = br.ReadInt32();
-
int biClrUsed = br.ReadInt32();
-
int biClrImportant = br.ReadInt32();
-
int rgbRed = 0;
-
int rgbGreen = 0;
-
int rgbBlue = 0;
-
Bitmap bmp = new Bitmap(biWidth, biHeight);
-
PictureBox1.Size = new System.Drawing.Size(biWidth, biHeight);
-
-
try
-
{
-
for (int y = biHeight - 1; y >= 0; y--)
-
{
-
for (int x = 0; x < biWidth; x++)
-
{
-
}
-
}
-
-
PictureBox1.Image = bmp;
-
}
-
catch
-
{
-
MessageBox.Show("there is some problem with file format");
-
}
-
}
-
else
-
MessageBox.Show("this is not a bitmap file");
-
fs.Flush();
-
}
HI EVERYONE
I WANT TO GET BMP BY ITS HEDER INFORMATION THEN DISPLAY IT, THIS CODE RUNNING BUT DON'T WORK, ANYONE CAN HELP ME PLZ
18 5826
Ease up on the caps lock ;)
Can you please describe in a little more detail how it's not working? You mention it runs, but all you said is that it doesn't work. Does the image display incorrectly, or not at all? Is there an exception being thrown?
Post a bit more information and we'll see what we can do to help you out :)
Oh also, relax! It's easy to get worked up over a problem... it happens to me all the time. Try to step back and try to clear your head, maybe do something else for a while, then come back to it when you're more come. Sometimes that's all you need and things that have been eluding you become more clear.
it's running but only get the path of file but don't display picture,sometimes say "this is not a bitmap file" .
i should get bmp file by its heder information then display it pixel-by-pixel
i have note enough time ,:(
thanks
Well, your program outputs that message... it looks like it's the else condition to the following if block: - if (br.ReadChar().ToString() + br.ReadChar().ToString() == "BM")
Try this... - string headerCode = br.ReadChar().ToString() + br.ReadChar().ToString();
-
Console.WriteLine(headerCode);
-
if (headerCode == "BM") ...
See what it's reading out there. It's obviously not "BM" but that should let you see what it is. Note, you might either want to inspect it via a breakpoint or output the int values of the string too (in case the characters that come out aren't letters... like, if it's a newline you won't be able to see it, but it's there).
thanks its work, i have another problem .
how to display bmp file pixel-by-pixel and line-by-line without buffering it? :)
I'm not sure what you mean by that, can you clarify please?
in this code at first we buffered the bmp then display it . i want to Simultaneous that we read the bmp, display it .
Oh, you want to display it as it's being read out, so a large image would draw as it loaded? You don't want it to have a large delay, then draw the whole thing, right?
The way you're making the image, ie making a Bitmap object and filling it with data, you could probably draw it mid-load and it would be just fine. To that end, maybe you can put the loading of the bitmap data into some kind of background worker, then periodically refresh your main form on a timer which would just redraw the image based on it's current state?
If you do that, make sure you lock/unlock the image. I'm not sure if that's the exact approach, but it's something to look into. You might as well give it a try :)
thanks a lot, i'm going to try what you say:)
do u know why this code don't work? - private void Form1_Load(object sender, EventArgs e)
-
-
{
-
-
OpenFileDialog ofd = new OpenFileDialog();
-
ofd.ShowDialog();
-
-
-
FileStream fs = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read);
-
-
BinaryReader br = new BinaryReader(fs);
-
-
if (br.ReadChar().ToString() + br.ReadChar().ToString() == "BM")
-
-
{
-
-
int size = br.ReadInt32();
-
-
br.ReadInt16(); //Reserved
-
-
br.ReadInt16(); //Reserved
-
-
int offsetToBitmap = br.ReadInt32();
-
-
int bytesInStruct = br.ReadInt32();
-
-
int width = br.ReadInt32();
-
-
int height = br.ReadInt32();
-
-
short planes = br.ReadInt16();
-
-
short bitcount = br.ReadInt16();
-
-
int compression = br.ReadInt32();
-
-
int imagesize = br.ReadInt32();
-
-
br.ReadInt32(); //Reserved
-
-
br.ReadInt32(); //Reserved
-
-
int colorsused = br.ReadInt32();
-
-
int importantColors = br.ReadInt32();
-
-
Bitmap bmp = new Bitmap(width, height);
-
-
pictureBox1.Size = new Size(width, height);
-
-
byte[] pixels = br.ReadBytes(3 * width * height);
-
-
for (int p = pixels.Length - 1; p > 0; p -= 3)
-
-
{
-
-
Point a = GetXY(Convert.ToInt32((p + 1) / 3), width, height);
-
-
bmp.SetPixel(a.X, a.Y, Color.FromArgb(pixels[p], pixels[p - 1], pixels[p - 2]));
-
-
}
-
-
pictureBox1.Image = bmp;
-
-
}
-
-
//
-
-
fs.Flush();
-
-
-
-
}
-
-
private Point GetXY(int n, int width, int height)
-
-
{
-
-
int x = 0;
-
-
int y = 0;
-
-
int n2 = n;
-
-
while (n - width > 0)
-
-
{
-
-
n -= width;
-
-
y++;
-
-
}
-
-
while (n2 - height > 0)
-
-
{
-
-
n2 -= height;
-
-
}
-
-
x = n2 - 1;
-
-
return new Point(width - 1 - x, height - 1 - y);
-
-
}
Can you please describe the problem in more detail?
do u know how i get bmp header and put pixel by pixel in arry then display it without using bitmap class, i don't have enough time :(
I don't off hand, no... last time I had to read an image format I googled the specs and went to work. That said, I'd imagine that's how you got as far as you have, so perhaps you should describe what your code is doing and how it's not working, then maybe we can help you get to the bottom of it.
Also, regarding your time limit, it's worth pointing out that Bytes is not a place for you to get your assignments/work done for you. We can help you work through problems and understand concepts, but at the end of the day your work is yours to do. I'm sorry if we haven't been able to help you thus far, but please keep in mind that ultimately, the responsibility to have the work done on time is yours.
If you still need help on this issue, please post more details regarding the problem your code is having. How it doesn't work, what problems it might be generating. Any errors or exceptions, etc...
in first code i use this befor the first loop>> int padding = biWidth % 4;<< and add this in the next loop >> fs.Seek(padding, SeekOrigin.Current);<< beacuse the picture is shown Tilt .do u know why i could Division the biwidth on 4 ?
http://en.wikipedia.org/wiki/BMP_file_format
It looks like the row itself is padded to a multiple of 4 bytes, not each pixel. I'm not sure if that helps you.
Some good information there though. Go over your code using this wikipedia sheet and make sure you're reading the offsets properly. If you're still having trouble, maybe I'll take a crack at it and see if I have any luck.
At this point though, I gotta ask. Why can't you use the Image.FromFile method?
At this point though, I gotta ask. Why can't you use the Image.FromFile method?
>>> where i can use it?
- Bitmap b = Image.FromFile("an_image.bmp");
The only reason I didn't suggest it earlier is you seemed pretty adamant that you read the image manually. You seemed to suggest it was a requirement to read and parse the file.
Haha hopefully that's all you need after all :)
*Edit: I read back over your stuff and yea, you mentioned you want to read and show the bitmap simultaneously. Using Image.FromFile, it will completely buffer it then display it. If you still want what you laid out at the start, you'll likely have to continue with what you've started above.
hi again ,
1)i have problem with reading bmp file in 8 bit,do u know how can i load it in my program?
2) i still don't undrestand why the padding is
int padding = biWidth % 4;
:(
Hello,
1) I'm afraid I don't know the answer to that question. The current standard for the bitmap format is 32-bit or 24-bit, I don't know how an 8-bit bitmap works. Looking at the doc, it looks like it maps to a colour table. Read the wiki link above. If you're looking for a way to load it with Image.FromFile, if it doesn't do it automatically you might have to load it yourself after all.
2) Because that's what the format requires. I believe they wanted to make sure there was always the same amount of data on each row. I don't know the intricacies, that's just what someone decided on :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: pcPirate |
last post by:
Hi,
I have a control PictureBox and I need to display a picture from Sql
Database field, given data type Image.
i) How should I diplay the picture in the PictureBox from the database?
ii) How...
|
by: James Dean |
last post by:
I am drawing in a picturebox and am having some problems. I display
outputted images in the picturebox. If the image is too big for the
client area then i have scrollbars. The problem is that once...
|
by: active |
last post by:
Problem: The PictureBox display appears to have the image cut off. I.e.,
the image bottom does not display although the PictureBox has room for it.
It occurred to me that what was displayed was...
|
by: BrianW |
last post by:
I am working on a program that has multiple picturebox controls that a user
is allowed to move around which are contained within a panel control for
visual placement. In my mousedown event, I set...
|
by: Tom |
last post by:
I have a picturebox on my VB.NET form. The picturebox size mode is set to
stretched. I then load an image into that form and display it. As the user
moves the mouse over the form, I want to get and...
|
by: Rich |
last post by:
Hello,
I want to simulate the dynamic thumbnail display of Windows Explorer (winxp)
on a form or pannel container. If I place a picture box on my container
form/pannel and dimension it to the...
|
by: TomA |
last post by:
Hi All,
I have a picturebox on a form containing the photo of a person. As you
advance through the records, the photo updates. Rather than storing the
images in an inefficient blob field in a...
|
by: Andrzej |
last post by:
I have a picturebox on my C# .NET form. The picturebox size mode is set to
zoom. I then load an image into that form and display it. As the user
moves the mouse over the form, I want to get and...
|
by: nanaalwi |
last post by:
Hi,
Currently I'm developing a software using VB.net that can grab an image using Matrox Morphis card and display it in a PictureBox. The software can grab the image already and display it in the...
|
by: swagatikasahoo |
last post by:
how to display all lines if i will scroll the picturebox. hi,
ok i m sending the code.
******************************************************
Private Sub PictureBox1_Paint(ByVal sender As Object,...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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...
| |