473,394 Members | 1,811 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

New To Imaging

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.
Nov 21 '05 #1
8 1093
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.

Nov 21 '05 #2
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.
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:C5**********************************@microsof t.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.

Nov 21 '05 #3
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
Nov 21 '05 #4
Thanks for the info. I'll check it out now!
"Olaf Rabbachin" <Ol*********@IntuiDev.com> wrote in message
news:uH**************@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

Nov 21 '05 #5
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.
"Olaf Rabbachin" <Ol*********@IntuiDev.com> wrote in message
news:uH**************@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

Nov 21 '05 #6
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.

Nov 21 '05 #7
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
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:95**********************************@microsof t.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.
>
>
>

Nov 21 '05 #8
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.
Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mark Nelson | last post by:
Hi I'm trying to build Imaging 1.1.4 in Solaris 9, I get passwd the first step i.e the building of libImging. However when I execute a python setup.py build I get the following error - gcc...
1
by: mark | last post by:
I feel fairly well versed in getting Tkinter to do what I want, but now I'm venturing into the whole imaging thing, and placing text and graphics over some static background image. I'm trying to...
2
by: Richard | last post by:
In the days of VB6 I would often use the Wang/Kodak Imaging control that ships with Windows to process TIFF files. Drop the ocx on a form and TIFF file manipulation is all very easy. So how do...
0
by: MC | last post by:
Hi, I'm developing an VB.NET app that converts TIFFs to PDFs using Office Imaging 2003 and Adobe Distiller 6.0 in the follwing way: 1. Using automation, I open the TIFF file with Office...
0
by: Stedak | last post by:
My application seems to freeze when Microsoft Office Document Imaging is set as the default for loading images. If the Windows Picture and Fax Viewer is used there is no problem. When I set a break...
3
by: David A. Osborn | last post by:
I currently have a class that has an enumeration of graphics extensions that it supports ie: Public Enum GraphicFormats JPG JPEG BMP TIFF End Enum
2
by: peter.mosley | last post by:
A few weeks ago I asked for advice about which GUI toolkit I should learn, and receved several helpful answers. In the end I went with Tkinter. This was because a) it was already installed on the...
2
by: moishyyehuda | last post by:
can I download Python Imaging Library (PIL) for linux.
5
by: Prateek | last post by:
Hi. I'm creating a web-application using CherryPy 2.2.1. My application needs to process images (JPG/PNG files) to 1) create thumbnails (resize them) 2) overlay them on a custom background (a...
0
by: tavares | last post by:
----------------------------------------------------------------------------------------------------------------------------------------- (Apologies for cross-posting) International Journal of...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.