Passing Bitmaps & Graphics to Subroutines as Arguments
Passing Bitmaps & Graphics to Subroutines as Arguments
Passing Bitmaps & Graphics to Subroutines as Arguments
Passing Bitmaps & Graphics to Subroutines as Arguments
Passing Bitmaps & Graphics to Subroutines as Arguments
Passing Bitmaps & Graphics to Subroutines as Arguments Passing Bitmaps & Graphics to Subroutines as Arguments Passing Bitmaps & Graphics to Subroutines as Arguments Passing Bitmaps & Graphics to Subroutines as Arguments Passing Bitmaps & Graphics to Subroutines as Arguments Passing Bitmaps & Graphics to Subroutines as Arguments Passing Bitmaps & Graphics to Subroutines as Arguments Passing Bitmaps & Graphics to Subroutines as Arguments
Passing Bitmaps & Graphics to Subroutines as Arguments Passing Bitmaps & Graphics to Subroutines as Arguments
Passing Bitmaps & Graphics to Subroutines as Arguments
Go Back  Xtreme Visual Basic Talk > > > Passing Bitmaps & Graphics to Subroutines as Arguments


Reply
 
Thread Tools Display Modes
  #1  
Old 01-22-2011, 05:43 AM
Success_Machine Success_Machine is offline
Regular
 
Join Date: Oct 2003
Posts: 64
Default Passing Bitmaps & Graphics to Subroutines as Arguments


I used to program with Visual Basic 6, so I have alot of old programs that I'm updating, plus I'm learning the new VB2008 methods.

I'm writing a program that replaces the old "BitBlit" function which is no longer supported by Visual Basic 2008. It involves three picture boxes, one holds the sprite bitmap, a second holds the mask (silhouette) of the sprite bitmap, and a third has a background image.

The idea is to:

1. Invert the colors of the 3rd bitmap;
2. Add the mask to the 3rd bitmap;
3. Invert the colors of the 3rd bitmap again;
4. Add the sprite to the 3rd bitmap.

I know I can do this the easy way by selecting a transparent color and drawing the sprite over the 3rd bitmap, but I prefer the mask approach. Why? Well, for example the sprite might contain a patch of graphics that is the same color as the background, but I don't want it to be transparent. That why I prefer the mask-and-bitblit approach.

My problem with VB2008 is that I can't figure out how to pass the bitmaps and graphics objects, as arguments, between different subroutines. I try to break the program into smaller subroutines to make them more manageable. But the program doesn't want to pass bitmaps between subroutines.

For some reason, the bitmaps won't draw. When I use bitmap (bm) and graphics objects (gr) as arguments and pass them to the subroutine with the command:

Call BitBlit(bm1,bm2,bm3, gr1,gr2,gr3)

The program just hangs, doesn't draw anything. Adding a "stop" in the VB2008 editor doesn't seem to work, it doesn't highlight the "stopped" line of code, doesn't try to debug, or update the values of "watch" variables, like it would if it were a number-crunching program. It also doesn't tell me what the error is. It's as if I didn't run the program.

I don't get it. Opinions?
Reply With Quote
  #2  
Old 01-22-2011, 09:36 AM
AtmaWeapon's Avatar
AtmaWeaponPassing Bitmaps & Graphics to Subroutines as Arguments AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

One line of code is not enough to diagnose this problem.

On the other hand, you do know you can still call BitBlt() from VB .NET, right?

If you want to implement your own for fun, unless you want to display the intermediate steps it is a waste to use PictureBox controls at all. Perhaps in VB6 the only way to draw was with pictureboxes, but that limitation does not exist in VB .NET.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 01-22-2011, 11:55 AM
Success_Machine Success_Machine is offline
Regular
 
Join Date: Oct 2003
Posts: 64
Default

Nope. Didn't know that. My understanding of Visual Basic was pretty sketchy in the first place. Learning a new function is often difficult and I don't have much time on my hands these days.

I've whittled my program down to the bare basics to demonstrate the problem I'm having. If you want to test it, create a new windows form project, drop a single picturebox onto the form, and directly copy&paste the code snippet below. Then hit run.

The purpose is to pass the bitmap (bm1) and graphics control (gr1) to a subroutine which paints a new color to each pixel of the bitmap. When the indicated line is "commented", the picturebox will be painted with a red background color. When the line is "uncommented" nothing is painted, not even the background color. It should paint overtop of the background color with a different color.

But it doesn't. The picturebox stays a plain grey color, same as the form background.


*************************************
Option Explicit On

Public Class Form1
Private Sub Vib(ByRef bm1 As Bitmap, ByRef gr1 As Graphics)
gr1.Clear(Color.Red)
Call BitBlit(bm1, gr1)
PictureBox1.Image = bm1
PictureBox1.Refresh()
End Sub

Private Sub BitBlit(ByRef bm1 As Bitmap, ByRef gr1 As Graphics)
Dim x, y As Integer
Dim new_color As Color
new_color = Color.FromArgb(255, 26, 100, 255)
For x = 0 To PictureBox1.Width
For y = 0 To PictureBox1.Height
'bm1.SetPixel(x, y, new_color)
Next y
Next x
End Sub

Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
PictureBox1.BorderStyle = BorderStyle.FixedSingle
Dim bm1 As New Bitmap(cInt(PictureBox1.Width), cInt(PictureBox1.Height))
Dim gr1 As Graphics = Graphics.FromImage(bm1)
Call Vib(bm1, gr1)
End Sub
End Class

***********************************

Last edited by Success_Machine; 01-22-2011 at 12:06 PM. Reason: In line Dim bm1 as New Bitmap, "Int" was changed to "cInt", result has no effect on problem however
Reply With Quote
  #4  
Old 01-22-2011, 02:55 PM
Success_Machine Success_Machine is offline
Regular
 
Join Date: Oct 2003
Posts: 64
Default

Nevermind. Solved the problem.

The bitmap pixel arrays are zero-based. So, the upper bound is equal to the range minus one. The for-next loops should go like this:

for x = 0 to (picturebox1.width - 1)
next x


Now THAT was basic. It wasn't even related to "new" VB2008 syntax. I suck at programming.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Passing Bitmaps & Graphics to Subroutines as Arguments
Passing Bitmaps & Graphics to Subroutines as Arguments
Passing Bitmaps & Graphics to Subroutines as Arguments Passing Bitmaps & Graphics to Subroutines as Arguments
Passing Bitmaps & Graphics to Subroutines as Arguments
Passing Bitmaps & Graphics to Subroutines as Arguments
Passing Bitmaps & Graphics to Subroutines as Arguments Passing Bitmaps & Graphics to Subroutines as Arguments Passing Bitmaps & Graphics to Subroutines as Arguments Passing Bitmaps & Graphics to Subroutines as Arguments Passing Bitmaps & Graphics to Subroutines as Arguments Passing Bitmaps & Graphics to Subroutines as Arguments Passing Bitmaps & Graphics to Subroutines as Arguments
Passing Bitmaps & Graphics to Subroutines as Arguments
Passing Bitmaps & Graphics to Subroutines as Arguments
 
Passing Bitmaps & Graphics to Subroutines as Arguments
Passing Bitmaps & Graphics to Subroutines as Arguments
 
-->