Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




DLLImport - GDI32.dll - BitBit -


hi,
the Issue is ,

I would like to crop part of image. (I know the rectangle to be cropped from the tiff image). I tried DrawImage. But some Pixel Information is lost.

So I am trying to use BitBit approach.

My Code is ::::::

---------------Declaration - ----------------------

<DllImport("gdi32.dll", EntryPoint:="BitBlt", SetLastError:=True, _
CharSet:=CharSet.Unicode, ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function 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 Int32)
End Function
Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
-----------------------

My function for cropping is
----------------------------
Dim g1 As Graphics = PictureBox1.CreateGraphics()
Dim imgCrop As New Bitmap(200, 200)
Dim g2 As Graphics = Graphics.FromImage(imgCrop)
Dim dc1 As IntPtr = g1.GetHdc()
Dim dc2 As IntPtr = g2.GetHdc()
BitBlt(dc2, 0, 0, 200, 200, dc1, 100, 200, SRCCOPY)
g1.ReleaseHdc(dc1)
g2.ReleaseHdc(dc2)
imgCrop.Save("c:Captured.jpg", ImageFormat.Jpeg)
MsgBox("Finished Saving Image")

------------
Error Msg :::

Unhandled Exception
PInvoke restriction: cannot return variants.


Anyone has idea about where I am doing wrong. Or any better approach for this




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Advantages And Disadvantages Of Using Declare Or DllImport In API Calls?
Hello,

First of all, sorry for my English. I´m an Spanish student trying to make a class to manage serial port communications, I´ve been looking for some documentation about Communication Functions in kernel32.dll and API calls in VB .NET, and this is my conclusion.

There are to ways to declare an API call:

 1. Using Declare sentence
 2. Using DllImport sentence

[Examples]

Code:
' Declare version
    Public Declare Function DeclareBeep Lib "kernel32" Alias "Beep" _
        (ByVal dwFreq As Integer, ByVal dwDuration As Integer) As Integer


Code:
' DllImport version
    <DllImport("kernel32.dll", EntryPoint:="Beep")> _
    Public Shared Function DLLImportBeep(ByVal dwFreq As Integer, _
        ByVal dwDuration As Integer) As Integer
    End Function

    
I would like you to know what are the advantages and disadvantages of they both, and wich one is the most apropiated for my project.

Thank you very much for your attention.

Help With BitBit
Hello,

I am new to the gaming scene. I have picked up a little here and though however. I was wonder how to determine the size of the map window? Uhh...How to make it Show more of the map? The example I am looking at only has a small block, but I want to increase it to view more map at a time. Any suggestions on where to start?

Bitbit Help
hey i am making a character moving using bitblt to bit the character into a picture box
how to i make it so when i move the picture it will not leave the previous picture behind. so it will look like that character is moving.
thanks

BitBit Help
first off, what is Bit Bit, and how do you use it, can someone give me a good place to learn it from, tutorials or something, thanks in advance

Working With BitBit
Hi,

I've just began using BitBit now, so i'm not too good, i'm progressing slightly, but have a small problem...

Anyway, i've began making a square grid based maze game to get used to the functions of BitBit and cant seem to get something right, the game currently in no way resembles a maze, because I haven't started that bit yet...

To move the sprite properly, on a square-based grid i have set up an intXNow value to work with the intX, so that the character only moves so far at a time, by presetting intX to 10, then everytime you press to move, intXNow updates itself to equal intX, then runs the movement part on a timer...


Code:
Do Until intX >= intXNow + 50

-- movement code --

Loop

This works fine, but when you run it the first time he moves, he does four steps, the next time he does 5 steps, so he is no longer in the center of the x-axis grid...

I'm not sure what I have done wrong with this code.

Can somebody please look at my source code and tell me what i have done wrong to cause this uneven movement.

The source is in the zip below...

Your Help Is Greatly Appreciated.

Just Cant Understand BitBit!
Ok, ive tryed to understand this stuff for about 4 hours by now. And i just dont GET IT! I get NO ERRORS at all, but NOTHING HAPPENS either. So i wondered if anyone would post a newbie BitBit program for me.

thx

BitBit Error
When i try to initialize BitBit i get this error:
Help????

BitBit With MSChart
Can you use BitBit to make a realtime MSChart Graph not flicker? I've looked through some of the threads here and they seem to mainly use pictureboxes for gaming. Is the principle the same, if so how would i implemet it?

Thanks

Sean

Transparency, BitBit() And Number Sorting
1. Transparency
Will a gif with a transparent background still have a transparent background on a form? If not then how can i get transparent backgrounds?

2. BitBit()
Unless it is very complicated and hard to explain could you show how to use BitBit() for animation?

3. number sorting
i have this code:

VB Code:
Dim dblAns As String Dim intDig As IntegerDim dbl As StringdblAns = "2856457889" For intNum = 1 To Len(dblAns)      intDig = Mid(dblAns, intNum, 1)                If (intDig Mod 2) = 0 Then          If Len(dbl) Then               dbl = dbl & ", " & Format(intDig)          Else               dbl = Format(intDig)          End If     Else           dbl = dbl & Format(intDig)     End IfNext intNum MsgBox "The numbers are:" & dbl

it splits the number 2856457889 into 2, 85, 6, 457, 8, 89
even numbers start a new number
rather than putting the split numbers into a string and displaying it in a msgbox i want it to load a new txtbox eg. txtNum fo each number.

thnx 4 help and i hope this post is more successful than last time

Make Bitmap Transparent With BitBit
Hi all -
Lets say I have a bitmap with a region that has been marked with a certain color to detone a transparent area - how could I go about BitBit'ing on top of another picture in VB so that the solid color becomes transparent? THanks
-Chris

Fullscreen 640 * 480 Using GDI32
Hi people,

I'm sorry if this has been covered already, but I've been searching for 2 days now and I cannot find exactly what I'm looking for. I am writing a tetris game (my first "real" game). I want the game to run fullscreen mode in 640 * 480. How can I make sure that the resolution of the computer the game is playing on IS 640 * 480, and if not, change it? I am blitting the sprites directly to the form right now; if this needs to change, how do I blit to the fullscreen. Does it have the same handle as the form? Any help here would be GREATLY appreciated.

Thanks
Vorpal

Help!! How Do I Do This??? (GDI32 Problem)
OK my problem is:

i have 2 pictureboxs , one of them serve as templet and one of them is the actual display picturebox

temp: picProcess
display: picDisp

what i have done is , i manipulate the image in the picProcess then copy it to the picDisp. i do this so i can use rectangular selection region, then use bitblt to copy the necessary region to picdisp.

But now i am coding for "Ellipse region", and i have used
createEllipseRgn to create Region, but i donno how to copy the image from PicProcess to picDisp within the desired region! anyone help me??



see attach.
thx to ppl who replies

Need Help Learning GDI32
I'm trying to find information that will give me all the available functions to the gdi32 library. At a minimum I need the prototypes. I'd also like to have some examples.

Any suggestions on where I can get this?

Gdi32 And Bmp Manipulation
i was curious what this dll can all be used for i have seen the getpixel and thats it. i figured someone out there mite be able to tell me what else i will be able to use it for in vb. thanks

edit: i was also curious what other dll's out there are used for bitmap manipulation.

Anybody Played With The GDI32.DLL?
Hiya,

  I'm trying to draw filled polygons on a form and I'm trying to use the GDI32.DLL API to do it.

  My code is pretty straight forward;

CODEPrivate Declare Function PolyPolygon Lib "gdi32.dll" (ByVal hdc As Long, lpPoint As POINTAPI, lpPolyCounts As long, ByVal nCount As Long) As Long

Private Declare Function CreateSolidBrush Lib "gdi32.dll" (ByVal crColor As Long) As Long

Private Type POINTAPI
  x As Long
  y As Long
End Type

hBrush = CreateSolidBrush(RGB(127,127,255))
lngRC = PolyPolygon(frmMain.hdc, arrAPIPoints(0), arrAPINumPoints(0), 1)

Gdi32 StretchBlt
Hey all... New to the forums... Had a (hopefully) quick question about the StretchBlt function in gdi32... I'm trying to resize an image displayed in a PictureBox control... I figured out the API call, and can get it to resize, but have to have two Picture Boxes to do so... A source and a destination... No big deal, I thought... I figured I'd just stick one on the form, and then resize the form so the "before resize" box was hidden...

Not so easy... As far as I can figure out, both PictureBox's have to be displayed and visible on the form in order for the StretchBlt call to work correctly... When I hide the "before resize" one in any way (setting Visible = false, or resizing form so it's not displayed), I get random things from the API call... Sometimes it will show me part of my desktop resized in the destination box... Sometimes part of the image in the before box... Sometimes nothing at all...

I can't figure it out... I figured as long as both handles were valid, that it would function correctly...

The reason I am using a PictureBox and the API to resize is because I need to maintain aspect ratio in the resized picture (which as far as I can tell the Image control will not do... It stretches blindly, without any worry about aspect ratio)...

Does anyone know a way to do what I described? Or *gasp* does anyone know of a better way?

Any help would be greatly appreciated.

Thanks,
Brad

Hmmm....bitbit Seems Easier Than Trying To Do Maps With An Editor?
Hello again,

I got my map working with bitbit, but the things are super small. I can barely see em hehe, anyone got a site that will show the break down of bitbit that what represents what? I had to just play with some and just do a row of numbers and see what I came out with. The last question is, to increase the actual size my bits display at do I need to increase the pixel size?

Thx for any help.

GDI32 Textout / Font
Hi,

I'm using the GDI32 windows API to create a bitmap in memory. I draw lines and rectangles on it and that works fine. I also want to draw text on it. It works well with the textout function. But I also want to be able so set a specific font for the text, fontsize, color and text-options.
Does anyone know how to set this for the bitmap???

thanks
Martin

Dx7 - Dx8 -gdi32 [how Big Is The Speed Difference?]
Dx7 , dx8 and gdi32

how big is the speed difference compared to eachother?
i know dx is faster that gdi but... how big is the difference?

if dx8 is 100%
then dx 7 is what%
and gdi32 is what%

say, making pacman game should be fine?
i'll be probably using it for making 2D games/app

Gdi32 And Font List
i seem to have hit a road block in attempting to make a simple dll, i'm trying to retrieve all the installed system fonts and return them to a ADOR recordset or even an array for use in asp. The problem is all the sample code i've managed to find so far has been for listview or listboxes in applications w/ forms.

any recommendations on how to do this? i'm attempting to avoid using screen.fontcount ( because it's slow as molasses )

been attempting to do this with EnumFontFamilies but everything i've found so far requires a hDC

this is about the cleanest example i've found so far to work from : http://www.answers.com/topic/enumfonts

Thanks in advance

DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never inside the 'loop' " - DreX 2005

Questions: BitBit Moving, Walkmasks And Item Pickups.
Ok, so far have i quickly created a small program where a picture(the guy you control) moves instantly to the location of your click. Theres 3 things i must now:
1. How can i make my guy move slowly to the targeted location? not instantly.

2.How can i create walkmasks? Forexample if i create a tree, and i dont want my guy to walk right through the tree but around it.

3.How can i make my character pick up items? Forexample how can i make my guy get 10 score-points when he moves over an item, which in reality is a picture.

Edit*
I use BitBit.
This is not going to be a real game, iam just testing things out before i start creating a game.
Nothing is animated.

Using Createmetafile Function Of Gdi32 Library
Hi all,
I need to draw some rectangles in a RTF file for that i am using
createmetafile function to get a handle of the file. But it gives me an
error " Entry point in gdi32 not found". For the time being i am giving the
argument as null string.

thanks in advance

girish

Updating A User's GDI32.DLL File
Ok, heres my problem...
I'm now using MSIMG32.DLL in my app, I just love that alphablending, and it works on 99% of user's PCs. The one percent are using windows 98, and My app is saying that MSIMG32.DLL is not found, but yes, its there. According to "Dependancy walker", their GDI32.DLL is lit up red, its older than the one I have. So what do I do? tell them to shutdown to DOS, and replace their old GDI32.DLL with the new one I have. If so, wouldn't that make their GDI.EXE stop working? how safe is it to do this?

Is There A List Of Functions For Dll's Like User32, Kernel32, And Gdi32?
I'm trying to find out what sorts of things are offered through these common dll's but a list of functions is hard to come by.

Drawing Run Time Line Graph Using GDI32.dll Without Flickering
hi,
I am doing a project that needs graph to be shown
at run time ie as values changes.
I have just started using API's, i have tried rotating text usin API
Can i draw a runtime line graph using gdi32.dll
for which values are dynamically supplied suppose
by a scroll bar . Please tell me the API functions
used to do it
Imp : the graph must not flicker
If there are other meathods in VB for runtime graph please inform me , I have tried using MSChart and Excel chart dynamically but not satisfied
Saci.

Function GetDeviceGammaRamp Lib "gdi32"
The SetGammaRamp api is capable of changing the brightness, gamma and hue of Windows

Here's a popular example of how to use it to darken the screen:


Code:
Private Ramp1(0 To 255, 0 To 2) As Integer
Private Ramp2(0 To 255, 0 To 2) As Integer
Private Declare Function GetDeviceGammaRamp Lib "gdi32" (ByVal hdc As Long, lpv As Any) As Long
Private Declare Function SetDeviceGammaRamp Lib "gdi32" (ByVal hdc As Long, lpv As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

'--------------------------------

Public Function Int2Lng(IntVal As Integer) As Long
CopyMemory Int2Lng, IntVal, 2
End Function

'--------------------------------

Public Function Lng2Int(Value As Long) As Integer
CopyMemory Lng2Int, Value, 2
End Function

'--------------------------------

Private Sub Form_Unload(Cancel As Integer)
SetDeviceGammaRamp Me.hdc, Ramp1(0, 0)
End Sub

'--------------------------------

Private Sub setGamma()
Dim iCtr As Intege, lVal As Long

GetDeviceGammaRamp Me.hdc, Ramp1(0, 0)

For iCtr = 0 To 255
lVal = Int2Lng(Ramp1(iCtr, 0))
Ramp2(iCtr, 0) = Lng2Int(Int2Lng(Ramp1(iCtr, 0)) / 2) ‘r
Ramp2(iCtr, 1) = Lng2Int(Int2Lng(Ramp1(iCtr, 1)) / 2) ‘g
Ramp2(iCtr, 2) = Lng2Int(Int2Lng(Ramp1(iCtr, 2)) / 2) ‘b
Next iCtr

SetDeviceGammaRamp Me.hdc, Ramp2(0, 0)

End Sub
The problem is that I need to use this to change the brightness and color, as well as obtain positive brightness values -that's to say, increase the brightness of the monitor. This code doesn’t do that, but I know for a fact this is all possible with SetGammaRamp.

Also, I’ve tried playing with the numbers –dividing, multiplying, etc- to see if I can get the desired effect but it’s just not working right. I’ve got it to change the colors of the screen practically at random but that’s not going to cut it. I’m looking to make three sliders; one for each gamma ramp.

From what I can tell, there are three “gamma ramps,” each representing the R, G or B display values. (I guess these are "masks," sort of like the gamma graph you see in a lot of video card option dialogs.) A gamma ramp is an array of WORDs with 256 elements, each element having a value of 0 to 65536.

Each value is the “color value” to the power of the “component value.” I have no idea what the “component value” is or how the “color value” is expressed.

I've googled like crazy over the past few days and these two links are all I have to show for it:

This one is in German. If you don't see code, hit the small text toward the bottom of the page. I tried babelfish on it and that wasn't much help.
http://spotlight.de/nzforen/adlp/m/a...1748-6518.html
Also, the code is in Delphi.

And this:
http://www.monkeybreadsoftware.de/re...03_1.shtml#125
I have no idea where that "memoryBlock" object comes from in that guy's code.


If you screw up your gamma settings with this, you’ll have to restart windows.

GDI32 Will Run In P Code But Not Native Code
Does anybody have any idea why this would work when compiled as P code, but when I compile it and run it as Native code it seems to lock up my application.


Code:
Public Declare Function MoveToEx Lib "gdi32" (ByVal hDc As Long, ByVal x As Long, ByVal y As Long, lpPoint As Long) As Long
Public Declare Function LineTo Lib "gdi32" (ByVal hDc As Long, ByVal x As
I have follwing code in a callback. All I am trying to do is draw a simple box:

Code:
Dim hBrush As Long
MoveToEx hDc, 10, 10, 0
LineTo hDc, 100, 10
MoveToEx hDc, 10, 10, 0
LineTo hDc, 10, 100
MoveToEx hDc, 100, 10, 0
LineTo hDc, 100, 100
MoveToEx hDc, 10, 100, 0
LineTo hDc, 100, 100

Copyright © 2005-08 www.BigResource.com, All rights reserved