|
Great ...
You NEED to read up on inheritance, especially if this is a project for school.
Inheritance is a very important aspect of the .NET framework ( or any OO language for that matter) and not understanding it will do nothing but cause headaches in the future.
I'm sure you were assigned a book to read that covers this in painful detail.
I AM NOT GOING TO COMPLETE YOUR PROJECT FOR YOU, although I can't blame you for trying.
Not to mention I'm positive your teacher is familiar with CP, and I'm also pretty sure getting code of the net for your project is a big no no.
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
The obvious thing to do is to create a new project (probably a Console app) and paste the code snippets into it (one at a time).
The compiler will tell you if there any syntax errors.
You can fix those and then try running the code to see if there are any run-time errors (step through it with the debugger).
That way you will learn something.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
|
Do not repost. It is considered rude here.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
|
Sometimes silence can be deafening...
My advice is free, and you may get what you paid for.
|
|
|
|
|
I really cannot help you with your problem.
------------------------------------
"When Belly Full, Chin Hit Chest"
Confucius 502BC
|
|
|
|
|
employee information is privileged indeed.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
As there is no information do we assume you are not employed?
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
It has to be a candidate for best post ever !!!!
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
I guess that you must be posting from The Empty Quarter[^]
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
in vb.net how i get the start and stop time in timer control... that mean if i having two textbox. if named as start and stop. in that i need to click mean the timer to start and click stop maen the timer will stop autimatically... i need a vb.net code for this concept..
|
|
|
|
|
What have you got so far?
My advice is free, and you may get what you paid for.
|
|
|
|
|
Very good!
Make the bugger work, I bet it is a homework problem for college.
------------------------------------
"When Belly Full, Chin Hit Chest"
Confucius 502BC
|
|
|
|
|
it is a trick question, you can't calculate time. Not even in VB. Tempus fugit.[^]
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hello everybody,
within an otherwise more simple project I have to deal with something that goes far beyond my knowledge so far. Probably someone of you can help with hints or a snippet?
The goal is to display a picture format which isn't supported from gdi+ on a form. So I already had to go through a lot of advanced stuff with GCHandle etc., but meanwhile I'm far enough that something (coming from the picture file at least) shows on the screen... unfortunately it's only a mixture of colored pixels . Considering the picture specification (if you're interested you find it here[^]) each pixel is represented by a 32-bit word, that is (in my particular case) divided into three 10-bit-integers (RGB) and two padding bits (zero).
With the code below I create an array of 32-bit-integers from the image information in the file, which are supposed to represent the pixels. But how can I access the RGB information? I.e., how would I be able to derive 10-bit-integers from a 32-bit word? Or am I running into a dead-end with the whole concept?
Thanks for any help and advice! Please keep it a bit simple, since for me there seem to be several completely new issues hidden...
Michael
The main code I use is:
Public Sub DisplayImage(ByVal PicFile As FileInfo)
Dim W As UInteger = 200
Dim H As UInteger = 154
Dim stride As UInteger = 4 * W
Dim arrayImage() As UInt32 = MakePixelArray(PicFile)
Dim gch As GCHandle = GCHandle.Alloc(arrayImage, GCHandleType.Pinned)
Dim pBuf As IntPtr = gch.AddrOfPinnedObject
PictureBox1.Width = W
PictureBox1.Height = H
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
PictureBox1.Image = New Bitmap(W, H, stride, Imaging.PixelFormat.Format32bppRgb, pBuf)
gch.Free()
End Sub
Despite my picture (and the resulting array - see next snippet) is 2048 wide and 1536 high, I still have to set W and H to lower values in order to avoid an AccessViolationExcepiton. But that's another issue...
My actual problem seems to be in the 'MakePixelArray' function, because I can't retrieve the 10-bit-Integers needed for RGB from the DWORD. Here's what I have:
Private Function MakePixelArray(ByVal PicFile As FileInfo) As Array
Dim ft As FileStream = New FileStream(PicFile.FullName, FileMode.Open)
Dim brh As BinaryReader = New BinaryReader(ft)
ft.Position = 8192
Dim PixelArray(CInt(PicFile.Length - ft.Position) / 4 - 1) As UInteger
For i = 0 To (PixelArray.Length - 1)
Dim buff As UInteger = SwapDWORD(brh.ReadUInt32)
PixelArray(i) = buff
Next i
ft.Close()
brh = Nothing
ft = Nothing
Return PixelArray
End Function Just for completion here's the SwapDWORD function which is needed because the file is written in big endian:
Private Function SwapDWORD(ByVal i As UInt32) As UInt32
Return ((i And &HFF) << 24) + ((i And &HFF00) << 8) + ((i And &HFF0000) >> 8) _
+ ((i >> 24) And &HFF)
End Function
|
|
|
|
|
Something like:
Dim buff As UInteger
buff = &H33388911
Dim Red As UInt32 = (buff And &H3FF)
Dim Green As UInt32 = (buff And &HFFC00) >> 10
Dim Blue As UInt32 = (buff And &H3FF00000) >> 20
This example would give Red = &H111, Green = &H222, Blue = &H333.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Hi Moreno,
thank you for taking some time. Since I'm a bit clumsy with Hex-stuff I just went and tried your piece of code, replacing the 'buff' value with a UInt32 read from the file (and swapped).
The changed function now considers that the array only consists of 3 Elements (RGB) per pixel instead of 4 (bytes). It now reads like
Private Function MakeRGBArray(ByVal PicFile As FileInfo) As Array
Dim ft As FileStream = New FileStream(PicFile.FullName, FileMode.Open)
Dim brh As BinaryReader = New BinaryReader(ft)
ft.Position = 8192 ' start with first pixel after the header
' change array dimensions from 4 bytes per pixel to 3 (RGB)
Dim RGBArray(CInt(PicFile.Length - ft.Position) / 4 * 3 - 1) As UInt32
For i = 0 To (RGBArray.Length - 1) Step 3
Dim buff As UInt32 = SwapDWORD(brh.ReadUInt32)
RGBArray(i) = (buff And &H3FF)
RGBArray(i + 1) = (buff And &HFFC00) >> 10
RGBArray(i + 2) = (buff And &H3FF00000) >> 20
Next i
ft.Close()
brh = Nothing
ft = Nothing
Return RGBArray
End Function
To make it short: I can't tell if your idea works, since there's no reasonable result - just a different very bluish pattern. And to be honest: I'm also afraid there's something else wrong with my code, too? As you see in the main function, I also have to use the 'Imaging.PixelFormat.Format32bppRgb' parameter when creating the new bitmap. Changing it results in an ArgumentException
BTW: With your code added, the first pixel returns buff=562758160 (&H218B0210) exactly in the order like it's written in the file (==> Red=528, Green=704, Blue=536)
Do you probably have another hint where I'm trapped in my code salad?
Thank you again,
Michael
|
|
|
|
|
Hi Michael,
Please note that mine was just an example: you should check which is the specific data format in your file: in my example, I gave it for granted that the 1st 10 bit would hold red, then 10 bits for green and finally 10 bits for blue. And no alpha. This might be different from the actual file format you're using.
If you want to share your file and the format, I might be able to help you more.
EDIT: share your code for drawing the picture, if you want - the problem may be there (since you say red, green and blue components seem to be read correctly from the data file).
2+2=5 for very large amounts of 2
(always loved that one hehe!)
modified on Thursday, August 6, 2009 1:53 PM
|
|
|
|
|
Ciao Moreno,
thanks for your support . I've just sent you some stuff to the address at stasnc, hoping that's correct. The code and link to the file specification is also part of my original post.
I'm really looking forward to hearing from you!
Regards
Michael
|
|
|
|
|
Hi Michael,
Getting your stuff just now, I'll have a look at the code and will let you know.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
I had a first look at the stuff, and I sure see one problem, which as you thought is related to the Format24bppRgb format.
This format requires three Byte s for each pixel (red, green, blue), while you provide three UInt32 .
Try to make your RGBArray a Byte array, and you'll probably be done.
I'll have a deeper look anyway, and see if what I said is ok and if there's anything else to fix.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
modified on Friday, August 7, 2009 6:16 AM
|
|
|
|
|
Thanks for looking - I just came home from work and changed what you suggest.
The result is an overflow exception in the lines "RGBArray(i) = (buff And &H3FF)" etc., in which I then try to put a 10-bit value (held in buff which is UInt32, right?) into a single byte (8 bits). How would I correctly downconvert the result of the line into a byte? My silly approach to return 8/10th of course lead to an overflow exception, too...
BTW: I hope you had enough other stuff to do today and didn't drown in all the possibilities to fix
|
|
|
|
|
In order to convert your 10 bits values to 8 bits, you must simply lose the two least significant bits (which is the same as dividing the value by 4):
RGBArray(i) = (buff And &H3FF) >> 2;
RGBArray(i + 1) = (buff And &HFFC00) >> 12;
RGBArray(i + 2) = (buff And &H3FF00000) >> 22;
Try this and you should be doing fine with a Byte array.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Hello Michael,
I did not read the whole document about the Cineon File Format, but did a similar research about a image format of a vision mixer's still store (Kahuna) recently. There where the colors also 10 bit (this is common in broadcasting video) but the color was not in RGB but in YUV-format. If you have strange colors, when you are done, start investigating in this direction.
By the way: you should not open your cineon file as a bitmap, but as a byte-array (as suggested), then you could get the three 10-bits out of the 32-bit integer, without GDI+ confuses you. Then alocate a 24-Bit (RGB) Bitmap and use something like setpixel (for testing only, is very slow) to write your converted RGB-values to the bitmap.
To get around the slow setpixel look for articles about manipulating bitmap directly using 'dirty-buffers', but not before you see a picture with the slow method...
Hope to help you find your way, good luck:
Didi
|
|
|
|