|
-
Apr 8th, 2001, 05:05 PM
#1
Thread Starter
Hyperactive Member
Would it be possible to get a certain area to be a picture object/property of another object? I mean, like:
Code:
Picture1.Picture = Region(Picture2.Picture, 20, 20, 50, 50)
So that it would take the region from Picture2.Picture starting @ x20, y20 with width 50 and height 50. Anyone know how to do this? PaintPicture won't do, it has to be the .Picture property that changes.
-JR-
"Blessed are we who can laugh at ourselves for we shall never cease to be amused"
- Unknown
-
Apr 8th, 2001, 05:21 PM
#2
Use the BitBlt API function.
-
Apr 8th, 2001, 05:22 PM
#3
Thread Starter
Hyperactive Member
How would I use it (little experience with API)?
-JR-
"Blessed are we who can laugh at ourselves for we shall never cease to be amused"
- Unknown
-
Apr 8th, 2001, 05:35 PM
#4
Add to a Form with 2 PictureBoxes and a CommandButton.
Code:
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Sub Command1_Click()
Picture1.AutoRedraw = True
BitBlt Picture1.hDC, 0, 0, 32, 32, Picture2.hDC, 10, 10, vbSrcCopy
Picture1.Refresh
Picture1 = Picture1.Image
End Sub
This example will copy 32x32 pixels of Picture2 (starting at pixels 10,10) to Picture1.
-
Apr 8th, 2001, 05:57 PM
#5
Thread Starter
Hyperactive Member
Doesn't seem to be working, gives some windows background and something that IS on screen but not in the picture box. Should I mention that the source picture box is hidden?
-JR-
"Blessed are we who can laugh at ourselves for we shall never cease to be amused"
- Unknown
-
Apr 8th, 2001, 06:46 PM
#6
Frenzied Member
Solution 1: Set the AutoRedraw property to True.
Solution 2: Bitblit the picture into a memory DC before hiding:
Code:
'Declarations in Module
Public hDC1 As Long 'local copy
Public hPrevWorkAreaBitmap As Long
Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As DRopEnum) As Long
Enum DRopEnum
SRCAND = &H8800C6 ' (DWORD) dest = source AND dest
SRCCOPY = &HCC0020 ' (DWORD) dest = source
SRCERASE = &H440328 ' (DWORD) dest = source AND (NOT dest )
SRCINVERT = &H660046 ' (DWORD) dest = source XOR dest
SRCPAINT = &HEE0086 ' (DWORD) dest = source OR dest
NOTSRCCOPY = &H330008 ' (DWORD) dest = (NOT source)
NOTSRCERASE = &H1100A6 ' (DWORD) dest = (NOT src) AND (NOT dest)
MERGECOPY = &HC000CA ' (DWORD) dest = (source AND pattern)
MERGEPAINT = &HBB0226 ' (DWORD) dest = (NOT source) OR dest
DSTINVERT = &H550009 ' (DWORD) dest = (NOT dest)
WHITENESS = &HFF0062 ' (DWORD) dest = WHITE
BLACKNESS = &H42 ' (DWORD) dest = BLACK
End Enum
Public Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Public Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Public Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Public Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
'Create Memory DC - Form_Load()
hDC1 = CreateCompatibleDC(picSet.hdc)
hBitmap = CreateCompatibleBitmap(picSet.hdc, picture2.height, picture2.width)
hPrevWorkAreaBitmap = SelectObject(hDC1, hBitmap)
picture2.visible=true
bitblt hdc1, 0, 0, picture2.height, picture2.width, picture2.hdc, 0, 20
picture2.visible=false
'Delete memory DC - Form_Unload
hBitmap = SelectObject(hDC1, hPrevWorkAreaBitmap)
DeleteDC hDC1
DeleteObject hBitmap
Now you could bitblt like Megatron, except replace picture2.hdc with hdc1.
MicroBasic
Dragon Shadow Trainer
There is no good or evil in the world...only programmers and fools .
-
Apr 9th, 2001, 09:25 PM
#7
Thread Starter
Hyperactive Member
So how would I adapt this code to take an area of 336 pixels in width and 425 in height, starting @ x 0 and y 123 and put it to the destination? LoadedSkin.Picture would be the source and LoadedSkinTrans.Picture is the destination. So this is the code that I have so far (and doesn't seem to be working...):
Code:
'This is inside an appropriate WITH block
.LoadedSkinTrans.AutoRedraw = True
BitBlt .LoadedSkinTrans.hDC, 0, 0, 336, 425, .LoadedSkin.hDC, 0, 123, vbSrcCopy
.LoadedSkinTrans.Refresh
.LoadedSkinTrans = .LoadedSkinTrans.Image
"Blessed are we who can laugh at ourselves for we shall never cease to be amused"
- Unknown
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
|