Click here to Skip to main content
15,888,454 members
Home / Discussions / Visual Basic
   

Visual Basic

 
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 
AnswerResolved: How would I deal with 10-bit-integer? Pin
Sonhospa16-Aug-09 6:53
Sonhospa16-Aug-09 6:53 
With some strong support I figured out the necessary changes. Here they are for others who might be interested:

1. The displayImage function has to be slightly changed: The former function 'MakePixelArray' has been replaced by a function that returns a byte array, holding 3 bytes for each pixel (RGB). As a consequence, the PixelFormat has to be adapted:
Public Sub DisplayImage(ByVal PicFile As FileInfo, ByVal ImageOffset As UInteger, ByVal Width As UInteger, ByVal Height As UInteger)
        Dim arrayImage() As Byte = MakeRGBArray(PicFile, ImageOffset)                           <--- changed routine
        Dim gch As GCHandle = GCHandle.Alloc(arrayImage, GCHandleType.Pinned)
        Dim pBuf As IntPtr = gch.AddrOfPinnedObject

        PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
        PictureBox1.Image = New Bitmap(Width, Height, 3 * Width, Imaging.PixelFormat.Format24bppRgb, pBuf)      <--- changed pixel format
        gch.Free()
    End If
End Sub

2. MakeRGBArray reads a UInteger for each Pixel and swaps the bytes first. With a bit-mask and a bit-shifting operation, the padding of the Uinteger (32 bits for 3 * 10 bits RGB) is eliminated, the 10-bit-values read and converted to 8-bit:
Private Function MakeRGBArray(ByVal PicFile As FileInfo, ByVal ImageOffset As UInteger) As Array
    Dim ft As FileStream = New FileStream(PicFile.FullName, FileMode.Open)
    Dim brh As BinaryReader = New BinaryReader(ft)

    ft.Position = ImageOffset          ' start with first pixel after the header

    Dim RGBArray(CInt((PicFile.Length - ft.Position) / 4 * 3) - 1) As Byte
    For i = 0 To (RGBArray.Length - 1) Step 3
        Dim buff As UInt32 = SwapDWORD(brh.ReadUInt32)
        ' bit-shifting operation
        RGBArray(i) = (buff And &HFFC) >> 4
        RGBArray(i + 1) = (buff And &H3FFFFC) >> 14
        RGBArray(i + 2) = (buff And &HFFFFFFFC) >> 24
    Next i

    ft.Close()
    brh = Nothing
    ft = Nothing

    Return RGBArray
End Function

Maybe it helps someone else. Special thanks to Moreno for the basic idea and perfect offline support! Thumbs Up | :thumbsup:
QuestionClearing Datagridview when combobox item is changed [modified] Pin
Dambod5-Aug-09 22:31
Dambod5-Aug-09 22:31 
AnswerRe: Clearing Datagridview when combobox item is changed Pin
dan!sh 5-Aug-09 22:53
professional dan!sh 5-Aug-09 22:53 
GeneralRe: Clearing Datagridview when combobox item is changed Pin
Dambod6-Aug-09 3:59
Dambod6-Aug-09 3:59 
GeneralRe: Clearing Datagridview when combobox item is changed Pin
dan!sh 6-Aug-09 8:55
professional dan!sh 6-Aug-09 8:55 
GeneralRe: Clearing Datagridview when combobox item is changed Pin
Dambod7-Aug-09 20:30
Dambod7-Aug-09 20:30 
QuestionThe "ResolveComReference" task failed unexpectedly. Pin
Nanda_MR5-Aug-09 20:51
Nanda_MR5-Aug-09 20:51 
AnswerRe: The "ResolveComReference" task failed unexpectedly. Pin
Johan Hakkesteegt5-Aug-09 21:55
Johan Hakkesteegt5-Aug-09 21:55 
QuestionE-Mail Monitor Pin
Anubhava Dimri5-Aug-09 20:01
Anubhava Dimri5-Aug-09 20:01 
AnswerRe: E-Mail Monitor Pin
dan!sh 5-Aug-09 20:41
professional dan!sh 5-Aug-09 20:41 
AnswerRe: E-Mail Monitor Pin
Adam R Harris6-Aug-09 11:47
Adam R Harris6-Aug-09 11:47 
QuestionOne Number after Decimal Point ? Pin
Bob Beaubien5-Aug-09 17:33
Bob Beaubien5-Aug-09 17:33 
AnswerRe: One Number after Decimal Point ? Pin
Christian Graus5-Aug-09 17:58
protectorChristian Graus5-Aug-09 17:58 
GeneralRe: One Number after Decimal Point ? Pin
Bob Beaubien6-Aug-09 1:48
Bob Beaubien6-Aug-09 1:48 
GeneralRe: One Number after Decimal Point ? Pin
Johan Hakkesteegt6-Aug-09 3:17
Johan Hakkesteegt6-Aug-09 3:17 
GeneralRe: One Number after Decimal Point ? Pin
Bob Beaubien6-Aug-09 3:36
Bob Beaubien6-Aug-09 3:36 
GeneralRe: One Number after Decimal Point ? Pin
Johan Hakkesteegt9-Aug-09 20:14
Johan Hakkesteegt9-Aug-09 20:14 
QuestionMake a directory tree from a list of paths [modified] Pin
User 58422375-Aug-09 3:23
User 58422375-Aug-09 3:23 

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.