Home All Groups Group Topic Archive Search About
Author
6 Apr 2005 10:56 PM
David Pendrey
Greetings,
     I am new to imaging in applications and wish to create an application
which will draw some images in a Picture Box or similar in Visual Basic in
Visual Studio DOT NET. I have a collection of 8 or so images which will be
drawn in multiple locations kind of like a pac man game. The character has
two pictures (mouth open and mouth closed) and the enemies have two pictures
(when they can kill you and when you can kill them) but are drawn four
times. I have only been able to find examples using DirectX in C# and in a
full screen application so they are of no use. I have tried looking on the
Microsoft website for information on DirectX but that is not of much use
either.

Author
7 Apr 2005 12:13 AM
Dennis
If the pictures are in the form a bitmap or icon you can easily read them in
or include as embedded resources in your application and set the location of
the picture boxes and display them in the picture boxes.  Check out the
PIcture Box Class, .Image property.

Show quoteHide quote
"David Pendrey" wrote:

> Greetings,
>      I am new to imaging in applications and wish to create an application
> which will draw some images in a Picture Box or similar in Visual Basic in
> Visual Studio DOT NET. I have a collection of 8 or so images which will be
> drawn in multiple locations kind of like a pac man game. The character has
> two pictures (mouth open and mouth closed) and the enemies have two pictures
> (when they can kill you and when you can kill them) but are drawn four
> times. I have only been able to find examples using DirectX in C# and in a
> full screen application so they are of no use. I have tried looking on the
> Microsoft website for information on DirectX but that is not of much use
> either.
>
>
>
Author
7 Apr 2005 7:04 AM
David Pendrey
I have done that and the time taken to render a picture 50 times is too
great. I then used another method (using the DrawImage function of the forms
Graphics object) which got the time taken to render 50 images down to about
35milliseconds but that still takes too long. On older PC's it wont run at
all :( I know it can be done on older PCs without too much CPU usage because
an old Windows screensaver had fish pictures moving across the screen
smoothly with little CPU usage. I want smaller graphics with a lower color
depth so it should be easier.


Show quoteHide quote
"Dennis" <Den***@discussions.microsoft.com> wrote in message
news:C5F7368B-6E90-49F9-8812-AA5D15B89E2F@microsoft.com...
> If the pictures are in the form a bitmap or icon you can easily read them
> in
> or include as embedded resources in your application and set the location
> of
> the picture boxes and display them in the picture boxes.  Check out the
> PIcture Box Class, .Image property.
>
> "David Pendrey" wrote:
>
>> Greetings,
>>      I am new to imaging in applications and wish to create an
>> application
>> which will draw some images in a Picture Box or similar in Visual Basic
>> in
>> Visual Studio DOT NET. I have a collection of 8 or so images which will
>> be
>> drawn in multiple locations kind of like a pac man game. The character
>> has
>> two pictures (mouth open and mouth closed) and the enemies have two
>> pictures
>> (when they can kill you and when you can kill them) but are drawn four
>> times. I have only been able to find examples using DirectX in C# and in
>> a
>> full screen application so they are of no use. I have tried looking on
>> the
>> Microsoft website for information on DirectX but that is not of much use
>> either.
>>
>>
>>
Author
9 Apr 2005 2:03 AM
Dennis
You can use BltBit which is a bit more complicated..it's very fast and with
it, you don't need the pictureboxes, you can write directly to the form
graphics objec in the paint event.  Of course, if the pictures are moving,
you will have to save the rectangle you paint a "fish" over so you can
restore it when the fish moves.

Show quoteHide quote
"Dennis" wrote:

> If the pictures are in the form a bitmap or icon you can easily read them in
> or include as embedded resources in your application and set the location of
> the picture boxes and display them in the picture boxes.  Check out the
> PIcture Box Class, .Image property.
>
> "David Pendrey" wrote:
>
> > Greetings,
> >      I am new to imaging in applications and wish to create an application
> > which will draw some images in a Picture Box or similar in Visual Basic in
> > Visual Studio DOT NET. I have a collection of 8 or so images which will be
> > drawn in multiple locations kind of like a pac man game. The character has
> > two pictures (mouth open and mouth closed) and the enemies have two pictures
> > (when they can kill you and when you can kill them) but are drawn four
> > times. I have only been able to find examples using DirectX in C# and in a
> > full screen application so they are of no use. I have tried looking on the
> > Microsoft website for information on DirectX but that is not of much use
> > either.
> >
> >
> >
Author
9 Apr 2005 11:39 PM
David Pendrey
Thank you thank you thank you thank you thank you thank you! This takes the
processing power required down to almost nothing! This is exactly the kind
of thing I've been looking for all along. I thought it wouldn't need DirectX
or anything that complicated :) Thanks again Dennis


Show quoteHide quote
"Dennis" <Den***@discussions.microsoft.com> wrote in message
news:9546E464-8400-4A7C-BFF5-F78E84BAAAD7@microsoft.com...
> You can use BltBit which is a bit more complicated..it's very fast and
> with
> it, you don't need the pictureboxes, you can write directly to the form
> graphics objec in the paint event.  Of course, if the pictures are moving,
> you will have to save the rectangle you paint a "fish" over so you can
> restore it when the fish moves.
>
> "Dennis" wrote:
>
>> If the pictures are in the form a bitmap or icon you can easily read them
>> in
>> or include as embedded resources in your application and set the location
>> of
>> the picture boxes and display them in the picture boxes.  Check out the
>> PIcture Box Class, .Image property.
>>
>> "David Pendrey" wrote:
>>
>> > Greetings,
>> >      I am new to imaging in applications and wish to create an
>> > application
>> > which will draw some images in a Picture Box or similar in Visual Basic
>> > in
>> > Visual Studio DOT NET. I have a collection of 8 or so images which will
>> > be
>> > drawn in multiple locations kind of like a pac man game. The character
>> > has
>> > two pictures (mouth open and mouth closed) and the enemies have two
>> > pictures
>> > (when they can kill you and when you can kill them) but are drawn four
>> > times. I have only been able to find examples using DirectX in C# and
>> > in a
>> > full screen application so they are of no use. I have tried looking on
>> > the
>> > Microsoft website for information on DirectX but that is not of much
>> > use
>> > either.
>> >
>> >
>> >
Author
10 Apr 2005 2:31 AM
David Pendrey
I have tried htis and it is MUCH faster, exactly what I wanted however I
have encountered a problem with dynamic images where only a black square is
blitted accross but an image contained within a PictureBox placed onto the
form at design time works fine. The code that works is

    Private Enum TernaryRasterOperations As Integer
        SRCCOPY = &HCC0020       ' dest = source                   */
        SRCPAINT = &HEE0086      ' dest = source OR dest           */
        SRCAND = &H8800C6        ' dest = source AND dest          */
        SRCINVERT = &H660046     ' dest = source XOR dest          */
        SRCERASE = &H440328      ' dest = source AND (NOT dest )   */
        NOTSRCCOPY = &H330008    ' dest = (NOT source)             */
        NOTSRCERASE = &H1100A6   ' dest = (NOT src) AND (NOT dest) */
        MERGECOPY = &HC000CA     ' dest = (source AND pattern)     */
        MERGEPAINT = &HBB0226    ' dest = (NOT source) OR dest     */
        PATCOPY = &HF00021       ' dest = pattern                  */
        PATPAINT = &HFB0A09      ' dest = DPSnoo                   */
        PATINVERT = &H5A0049     ' dest = pattern XOR dest         */
        DSTINVERT = &H550009     ' dest = (NOT dest)               */
        BLACKNESS = &H42         ' dest = BLACK                    */
        WHITENESS = &HFF0062     ' dest = WHITE                    */
    End Enum

    Private Declare Auto Function BitBlt Lib "GDI32.DLL" (ByVal hObject As
IntPtr, ByVal XDest As Integer, ByVal YDest As Integer, ByVal Width As
Integer, ByVal Height As Integer, ByVal ObjSource As IntPtr, ByVal XSrc As
Integer, ByVal YSrc As Integer, ByVal Operation As TernaryRasterOperations)
As Boolean

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

        ' Load image into picture box
        PictureBox1.Image = Image.FromFile("Image.bmp")
        System.Windows.Forms.Application.DoEvents()

        ' Obtain graphics objects
        Dim FormGraphics As Graphics = CreateGraphics(), ImageGraphics As
Graphics = PictureBox1.CreateGraphics
        ' Obtain HDC's
        Dim FormHDC As IntPtr = FormGraphics.GetHdc, ImgHDC As IntPtr =
ImageGraphics.GetHdc

        ' Draw image onto the form
        BitBlt(FormHDC, 0, 0, 50, 50, ImgHDC, 0, 0,
TernaryRasterOperations.SRCCOPY)

        ' Release the HDC's
        FormGraphics.ReleaseHdc(FormHDC)
        ImageGraphics.ReleaseHdc(ImgHDC)

        ' Relase the graphics objects
        FormGraphics.Dispose()
        ImageGraphics.Dispose()
    End Sub

That works very well and is fast enough to have 1000 images running around
the screen at 40 frames per second and taking up very little processing
power. However when i try to use a dynamically generated Image object or
PictureBox object all that gets drawn on the screen is a black box. This is
the code I used:

    Private Enum TernaryRasterOperations As Integer
        SRCCOPY = &HCC0020       ' dest = source                   */
        SRCPAINT = &HEE0086      ' dest = source OR dest           */
        SRCAND = &H8800C6        ' dest = source AND dest          */
        SRCINVERT = &H660046     ' dest = source XOR dest          */
        SRCERASE = &H440328      ' dest = source AND (NOT dest )   */
        NOTSRCCOPY = &H330008    ' dest = (NOT source)             */
        NOTSRCERASE = &H1100A6   ' dest = (NOT src) AND (NOT dest) */
        MERGECOPY = &HC000CA     ' dest = (source AND pattern)     */
        MERGEPAINT = &HBB0226    ' dest = (NOT source) OR dest     */
        PATCOPY = &HF00021       ' dest = pattern                  */
        PATPAINT = &HFB0A09      ' dest = DPSnoo                   */
        PATINVERT = &H5A0049     ' dest = pattern XOR dest         */
        DSTINVERT = &H550009     ' dest = (NOT dest)               */
        BLACKNESS = &H42         ' dest = BLACK                    */
        WHITENESS = &HFF0062     ' dest = WHITE                    */
    End Enum

    Private Declare Auto Function BitBlt Lib "GDI32.DLL" (ByVal hObject As
IntPtr, ByVal XDest As Integer, ByVal YDest As Integer, ByVal Width As
Integer, ByVal Height As Integer, ByVal ObjSource As IntPtr, ByVal XSrc As
Integer, ByVal YSrc As Integer, ByVal Operation As TernaryRasterOperations)
As Boolean

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        ' Load new image
        Dim newImage As Image = Image.FromFile("Image.bmp")
        ' Obtain graphics objects
        Dim FormGraphics As Graphics = CreateGraphics(), ImageGraphics As
Graphics = Graphics.FromImage(newImage)
        ' Obtain HDCs
        Dim FormHDC As IntPtr = FormGraphics.GetHdc, ImgHDC As IntPtr =
ImageGraphics.GetHdc

        ' Draw image onto the form
        BitBlt(FormHDC, 0, 0, 50, 50, ImgHDC, 0, 0,
TernaryRasterOperations.SRCCOPY)

        ' Release the HDC's
        FormGraphics.ReleaseHdc(FormHDC)
        ImageGraphics.ReleaseHdc(ImgHDC)

        ' Relase the graphics objects
        FormGraphics.Dispose()
        ImageGraphics.Dispose()
    End Sub


The only difference between the two is the image object and the creation of
the graphics object. I have tried to draw the image on the graphics object
after it is created but that had no effect. If anyone can help me figure
this out I would appreciate it.
Author
7 Apr 2005 8:07 AM
Olaf Rabbachin
Hi,

David Pendrey wrote:

> I am new to imaging in applications and wish to create an application
> which will draw some images in a Picture Box or similar in Visual Basic in
> Visual Studio DOT NET.
> [...]

I suggest you subscribe to the microsoft.public.dotnet.framework.drawing
newsgroups and also check out the GDI+ FAQ at
www.bobpowell.net/gdiplus_faq.htm.

Cheers,
Olaf
Author
7 Apr 2005 10:05 AM
David Pendrey
Thanks for the info. I'll check it out now!


Show quoteHide quote
"Olaf Rabbachin" <Olaf_NoSpam@IntuiDev.com> wrote in message
news:uHRlOj0OFHA.2788@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> David Pendrey wrote:
>
>> I am new to imaging in applications and wish to create an application
>> which will draw some images in a Picture Box or similar in Visual Basic
>> in
>> Visual Studio DOT NET.
>> [...]
>
> I suggest you subscribe to the microsoft.public.dotnet.framework.drawing
> newsgroups and also check out the GDI+ FAQ at
> www.bobpowell.net/gdiplus_faq.htm.
>
> Cheers,
> Olaf
Author
8 Apr 2005 10:37 AM
David Pendrey
Thanks for the info but noone seems to be talking in the forum and GDI Plus
is too slow. Maybe I have to use DirectX. Thanks anyway.


Show quoteHide quote
"Olaf Rabbachin" <Olaf_NoSpam@IntuiDev.com> wrote in message
news:uHRlOj0OFHA.2788@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> David Pendrey wrote:
>
>> I am new to imaging in applications and wish to create an application
>> which will draw some images in a Picture Box or similar in Visual Basic
>> in
>> Visual Studio DOT NET.
>> [...]
>
> I suggest you subscribe to the microsoft.public.dotnet.framework.drawing
> newsgroups and also check out the GDI+ FAQ at
> www.bobpowell.net/gdiplus_faq.htm.
>
> Cheers,
> Olaf