|
-
Aug 19th, 2003, 12:13 PM
#1
Thread Starter
Addicted Member
BitBlt: Problem converting vb6 to vb.net
this is the API call:
Code:
Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As IntPtr, _
ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal hSrcDC As IntPtr, ByVal xSrc As Long, _
ByVal ySrc As Long, ByVal dwRop As Long) As Long
Public Const SRCCOPY = &HCC0020
Public Const SRCPAINT = &HEE0086
Public Const SRCAND = &H8800C6
which i need to find an equivelent for vb.net.
Code:
RetVal = BitBlt(Form1.Picture1.hDC, XVal_To, YVal_To, Width, Height, Form1.Picture1.hDC, XVal_From, YVal_From, SRCAND)
as you may have guessed, the is Form1 , with Picture1 as a picture box in it.
the property "hDC" in picture1.hDC is removed !!!!!!!!!!
what can i do ???!
well, i tried to use:
Code:
Dim HDC1 as IntPtr
HDC1=Form1.DefInstance.Picture1.CreatGraphics.GethDC
'bla bla bla
is that way right ??
if it is, y it is not working ???
as i have noticed (although not sure of how accurate this notice is)
the thing draw for a second and is erased immediates (probably after re-painting)
well, that doesnot happen in vb6 !!!!!
anyone can help ????
Last edited by ZaidGS; Aug 20th, 2003 at 07:01 PM.
-
Aug 20th, 2003, 04:08 AM
#2
You might try converting all the Longs in Declare Function BitBlt to Integers and declare dwRop as System.Int32. I belive that .NET integers are the same as VB6 Longs. I'm guessing that maybe Longs are also different between .NET and 6.
If that doesn't help, go out and buy ".NET Graphics and Printing" by Peter G. Aitken from Optimax, ISBN 1-931097-04-6. It's got a whole chapter on BitBlt.
www.optimaxpublishinggroup.com
This world is not my home. I'm just passing through.
-
Aug 20th, 2003, 06:45 PM
#3
Thread Starter
Addicted Member
thanks for considering....
ok, i hav changed the api call to:
Code:
Private Declare Function BitBlt Lib "gdi32.dll" Alias "BitBlt" (ByVal _
hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As _
Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal _
hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, _
ByVal dwRop As System.Int32) As Long
as it is found in one of the examples in msdn.
still, did not work out :S
would i be rude if i asked to provide for a link to a free tutorial
site, if u would consider suggesting such a thing ?? 
here is the example i found, if that would help at all:
http://msdn.microsoft.com/library/en...iewingForm.asp
Last edited by ZaidGS; Aug 20th, 2003 at 07:21 PM.
-
Aug 21st, 2003, 05:03 AM
#4
Sorry, can't help any more
I think I've told you everything I know on the subject.
Maybe someone else can pick up from here?
This world is not my home. I'm just passing through.
-
Aug 21st, 2003, 06:44 PM
#5
I wonder how many charact
I don't know why you need to use BitBlt , perhaps, you aren't aware of .Net's graphics abilities.
Open a new windows application, slap on a PictureBox And a button, open the code window, replace it with this code below...
REPLACE the bolded lines with two images files you want to switch between...
VB Code:
Public Class Form1
Inherits System.Windows.Forms.Form
Private flip As Boolean = False
Private g As Graphics
Private c As New ImageList()
+[Windows Form Designer generated code]
''replace the New sub in the windows form generated code with this one
Private Sub New()
MyBase.new()
InitializeComponent()
c.ImageSize = New Size(PictureBox1.Width, PictureBox1.Height)
c.Images.Add(Image.FromFile("[b]C:\documents and settings\Karl\Desktop\owned.bmp[/b]"))
c.Images.Add(Image.FromFile("[b]C:\documents and settings\Karl\Desktop\et.bmp[/b]"))
g = Graphics.FromHwnd(hwnd:=PictureBox1.Handle)
End Sub
'''''''
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If flip Then
g.DrawImage(c.Images(0), 0, 0)
flip = False
Else
g.DrawImage(c.Images(1), 0, 0)
flip = True
End If
End Sub
Protected Overrides Sub Finalize()
g.Dispose()
MyBase.Finalize()
End Sub
End Class
Last edited by nemaroller; Aug 21st, 2003 at 07:33 PM.
-
Aug 22nd, 2003, 08:37 AM
#6
Thread Starter
Addicted Member
things are starting to become clearer
thanks nemaroller, your code helped me a lot.
although it was not what i exactly wanted, but it
helped me for a start 
what i did is similar to:
translating:
Code:
RetVal = BitBlt(PictureBox1.hDC, XVal_To, YVal_To, Width, Height, PictureBox2.hDC, XVal_From, YVal_From, SRCCOPY)
into:
Code:
Dim g as Graphics = PictureBox1.CreateGraphics
Dim srcRect = New Rectangle(XVal_From, YVal_From, Width, Height)
g.DrawImage(PictureBox2.Image, XVal_To, YVal_To, srcRect, GraphicsUnit.Pixel)
i used the overloaded DrawImage so, that it suits the function of BitBlt, as it copies a portion of an image using its orignial size.
(the code you made resizes the whole picture to fit into place)
well, "copies".
BitBlt has three flags, i have solved the first flag "SRCCOPY"
im left helpless translating the flags "SRCAND" , "SRCPAINT"
PLZZZZZZ, help
at least a hint to the function i should use for these two flags.
PS: i have this visual studio .net only two weeks ago, and im having bad time concerning new features
-
Aug 22nd, 2003, 09:27 AM
#7
I wonder how many charact
I guess it would be helpful if you could say what these operations are for? (Program purpose)
BitBlit may not be supported in future Windows OS's since its an unmanaged resource, but then again, its seem to be so prevalent in programs, I couldn't possibly see Microsoft causing major incompatibilities by not including the gdi.dll somewhere. Staying with DrawImage will ensure your program runs on future OS's... windows or others.
Anyway, I will investigate, but I'm not promising anything, I already have two other projects to work on...
You might want to look at the CompositingMode setting of the graphics objects, includes two settings, SourceOVer , SourceCopy
http://msdn.microsoft.com/library/de...cliptopic5.asp
In the meantime, perhaps you can just stick with BlitBit...
take a look here.. http://www.vbdotnetheaven.com/Code/Jul2003/2128.asp
and here... http://www.vb-helper.com/howto_net_g...dow_image.html
Last edited by nemaroller; Aug 22nd, 2003 at 09:53 AM.
-
Aug 22nd, 2003, 01:47 PM
#8
Thread Starter
Addicted Member
well, i'd rather stick to VB.NET graphics stuff, not bitblt,
because bitblt is not working with me at all !!!
although it did in vb6, which is a strange problem.
but, as i said bitblt has three flags:
(1)SRCCOPY: which copies an exact portion from one place to another.
(2)SRCPAINT: which paints OVER current image, which means that
painting red over yellow gives orange, painting black over anything gives black
and painting white over anything dont make any change.
(3)SRCAND: which makes AND operation on the color, ie.
orange && red = red , because orange and red has red in common
(orange is (red OR yellow) )
and produces no difference for black, and paints white when one
of the two colors is white !!
i need these functions for drawing a chess board:
u kno, using a black mask, and paint the piece over
the mask.
so i need to use the three flags.
Last edited by ZaidGS; Aug 22nd, 2003 at 01:54 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|