Groups | Blog | Home
all groups > vb.net > april 2005 >

vb.net : New To Imaging


Dennis
4/6/2005 5:13:04 PM
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.

[quoted text, click to view]
David Pendrey
4/6/2005 10:56:54 PM
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.

David Pendrey
4/7/2005 7:04:22 AM
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.


[quoted text, click to view]

David Pendrey
4/7/2005 10:05:46 AM
Thanks for the info. I'll check it out now!


[quoted text, click to view]

Olaf Rabbachin
4/7/2005 10:07:05 AM
Hi,

[quoted text, click to view]

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,
David Pendrey
4/8/2005 10:37:52 AM
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.


[quoted text, click to view]

Dennis
4/8/2005 7:03:02 PM
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.

[quoted text, click to view]
David Pendrey
4/9/2005 12:00:00 AM
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


[quoted text, click to view]

David Pendrey
4/9/2005 12:00:00 AM
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.

AddThis Social Bookmark Button