Click here to Skip to main content
15,898,373 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: employe information Pin
Ashfield6-Aug-09 8:46
Ashfield6-Aug-09 8:46 
AnswerRe: employe information Pin
Steven J Jowett6-Aug-09 9:54
Steven J Jowett6-Aug-09 9:54 
AnswerRe: employe information Pin
Henry Minute6-Aug-09 10:22
Henry Minute6-Aug-09 10:22 
Questioncalculate start and stop time Pin
KannanNatesan6-Aug-09 2:32
KannanNatesan6-Aug-09 2:32 
AnswerRe: calculate start and stop time Pin
Johan Hakkesteegt6-Aug-09 3:10
Johan Hakkesteegt6-Aug-09 3:10 
GeneralRe: calculate start and stop time Pin
Dalek Dave6-Aug-09 3:27
professionalDalek Dave6-Aug-09 3:27 
GeneralRe: calculate start and stop time Pin
Luc Pattyn6-Aug-09 4:19
sitebuilderLuc Pattyn6-Aug-09 4:19 
QuestionHow would I deal with 10-bit-integer? Pin
Sonhospa5-Aug-09 22:37
Sonhospa5-Aug-09 22:37 
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 D'Oh! | :doh: . 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

AnswerRe: How would I deal with 10-bit-integer? Pin
Moreno Airoldi5-Aug-09 23:41
Moreno Airoldi5-Aug-09 23:41 
NewsRe: How would I deal with 10-bit-integer? Pin
Sonhospa6-Aug-09 1:14
Sonhospa6-Aug-09 1:14 
GeneralRe: How would I deal with 10-bit-integer? [modified] Pin
Moreno Airoldi6-Aug-09 1:47
Moreno Airoldi6-Aug-09 1:47 
GeneralRe: How would I deal with 10-bit-integer? Pin
Sonhospa6-Aug-09 9:39
Sonhospa6-Aug-09 9:39 
GeneralRe: How would I deal with 10-bit-integer? Pin
Moreno Airoldi6-Aug-09 23:34
Moreno Airoldi6-Aug-09 23:34 
GeneralRe: How would I deal with 10-bit-integer? [modified] Pin
Moreno Airoldi7-Aug-09 0:06
Moreno Airoldi7-Aug-09 0:06 
GeneralRe: How would I deal with 10-bit-integer? Pin
Sonhospa7-Aug-09 7:39
Sonhospa7-Aug-09 7:39 
GeneralRe: How would I deal with 10-bit-integer? Pin
Moreno Airoldi7-Aug-09 15:08
Moreno Airoldi7-Aug-09 15:08 
AnswerRe: How would I deal with 10-bit-integer? Pin
DidiKunz12-Aug-09 3:40
DidiKunz12-Aug-09 3:40 
GeneralRe: How would I deal with 10-bit-integer? Pin
Sonhospa13-Aug-09 10:01
Sonhospa13-Aug-09 10:01 
GeneralRe: How would I deal with 10-bit-integer? Pin
DidiKunz13-Aug-09 20:15
DidiKunz13-Aug-09 20:15 
GeneralRe: How would I deal with 10-bit-integer? Pin
Sonhospa13-Aug-09 21:47
Sonhospa13-Aug-09 21:47 
GeneralRe: How would I deal with 10-bit-integer? Pin
DidiKunz13-Aug-09 23:38
DidiKunz13-Aug-09 23:38 
GeneralRe: How would I deal with 10-bit-integer? Pin
Sonhospa14-Aug-09 9:44
Sonhospa14-Aug-09 9:44 
NewsRe: How would I deal with 10-bit-integer? [modified] Pin
Sonhospa15-Aug-09 2:08
Sonhospa15-Aug-09 2:08 
GeneralRe: How would I deal with 10-bit-integer? Pin
DidiKunz16-Aug-09 0:59
DidiKunz16-Aug-09 0:59 
GeneralRe: How would I deal with 10-bit-integer? [modified] Pin
Sonhospa16-Aug-09 2:10
Sonhospa16-Aug-09 2:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.