Results 1 to 14 of 14

Thread: question about a code...

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    question about a code...

    PHP Code:
    BitmapData bmData b.LockBits(new Rectangle(00b.Widthb.Height), ImageLockMode.ReadWritePixelFormat.Format24bppRgb);

                
    int stride bmData.Stride;
                
    System.IntPtr Scan0 bmData.Scan0;

                
    unsafe
                
    {
                    
    byte = (byte *)(void *)Scan0;
    .
    .

    what does that red line exactly do? I know it declares a pointer p, but what does the "(void *)" on the right side of the equal sign do?

    also, it accesses p like an array (ie, p[0] ) why is that?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    i see no red line :S
    \m/\m/

  3. #3
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    (*void) if i am not in error that will cast it to a pointer type var and (byte*) will finally cast it to a byte pointer
    \m/\m/

  4. #4

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    aha ok. (yeah it wouldnt let me colorize it for some reason)
    weird though, so you have to convert it to pointer first, then to a byte-pointer? why cant you just convert it directly to a byte-pointer
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  5. #5

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    ok forget about that
    how about my last question?
    why is it accessing it with p[0] like an array?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Coloring doesn't work in PHP tags, use CODE tags instead.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by CornedBee
    Coloring doesn't work in PHP tags, use CODE tags instead.
    aaha ok

    as for the other question I had, I think p[0] just means the pointer at its current location, p[1] would be the next position in the memory... just a guess, because that's how it seems to be working
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Yes, it works the same as in C++.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    umm another question
    how come I can say if (p==null) ...
    but not if (p[2]==null) ...

    it gives this error for the second one
    Operator '==' cannot be applied to operands of type 'byte' and '<null>'
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Because a byte value can never be null, and p[2] is a byte value.
    A pointer however can be null, and p is a pointer.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  11. #11

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by CornedBee
    Because a byte value can never be null, and p[2] is a byte value.
    A pointer however can be null, and p is a pointer.
    hmm so this way the value of p will be (byte)p ?

    also, how would I check to see if p[2] exists or not?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    hmm so this way the value of p will be (byte)p ?
    Huh? (byte)p might compile, but it certainly will not yield anything of any sense.

    also, how would I check to see if p[2] exists or not?
    You can't. The thing of pointers is that they are simply that: pointers. They store a memory address and NOTHING else. Why do you think you can only use them in unsafe areas? To know if accessing p[2] is valid, you need to store the length of the array that is pointed to by p separatly.

    The maximum value you may use inside the square brackets is (Stride * Height) - 1
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  13. #13

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    hmm MrPolite has to study pointers
    last time I used them was probaby 6th grade... and you can probably guess that I didnt really learn anything about them back then


    thanks for the answers
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  14. #14
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Learn plain old-school C and you'll know all about them
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width