Raindrops display picture (Cloud Repost)

zhaozj2021-02-08  215

Raindrops display picture

This example is to display in a stdpicture object, which is then displayed in the Picturebox.

Because we want to display only one picture, I don't want to use another PictureBox to store the original map, then

Draw a further PictureBox, which only uses the stdpicture object to replace the PictureBox (Source Figure)

, But Bitblt draws the word HDC for the purpose of the purpose, and the stdpicture object does not have HDC, which only

A Handle value, in this example, this handle value is a graphic hbitmap value. So we have to use

Memorydc's way, producing a MEMORYDC, putting the Bitmap graph on it, and then use Bitblt to draw. 'Demand a PictureBox (Named Picture2), a Command button)

Option expedition

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 Declare Function CreateCompatibleDC LIB "GDI32" _

(BYVAL HDC As Long) As Long

Private Declare Function SelectObject LIB "GDI32" _

(Byval HDC As Long, BYVAL HOBJECT AS Long) As long

Private Declare Function Deletedc LIB "GDI32" (Byval HDC As Long) AS Long

Const srccopy = & hcc0020

Private Picture1 AS New Stdpicture

Private submmand1_click ()

DIM I as long

DIM J AS Long

Dim Height5 As Long, Width5 As Long

DIM HMEMDC AS Long

The unit of the 'stdpicture object is himetric so you want to convert to Pixel

Height5 = scaley (Picture1.height, Vbhimetric, vbpixels)

IF Height5> Picture2.scaleHeight Then

HEIGHT5 = Picture2.scaleHeight

END IF

Width5 = scalex (Picture1.Width, Vbhimetric, VBPixels)

If Width5> Picture2.scalewidth Then

Width5 = Picture2.scaleWidth

END IF

'CREATE MEMORY DC

HMEMDC = CreateCompatibleDC (Picture2.hdc)

'Specify the Bitmap chart of Picture1 to HMEMDC

Call selectObject (HMEMDC, Picture1.Handle)

For i = height5 to 1 step -1

Call Bitblt (Picture2.hdc, 0, I, Width5, 1, _HMEMDC, 0, I, SRCCPY)

For j = i - 1 to 1 step -1

Call Bitblt (Picture2.hdc, 0, J, Width5, 1, _

HMEMDC, 0, I, SRCCOPY

NEXT J

NEXT

Call deletedc (HMEMDC)

End Sub

Private sub flow_load ()

DIM I as long

Picture2.scalemode = 3 'Sets into Pixel metrics

'Setting up to DISPLAY

SET PICTURE1 = LoadPicture ("C: / Windows / Sui.BMP")

'^^^^^^^^^^^^^^^^^^^^^^

'Loading the picture we want to show

End Sub

return

SHRINKING ICONS Down to SIZE

Abstract

You can use the windows Application Programming Interface (API)

Bitblt function to modify the size of an icon. This article explains

How to enlarge or shrink an icon.

Modifying an icon's size

You can use the windows Application Programming Interface (API)

Bitblt function to create an icon trians smaller or larger Than THE

Original icon. The Bitblt Function Copies a Memory Device Context To

ANOTHER MEMORY Device Context. (a Memory Device Context Is A Block of

Memory That Repesents a display surface, Such as an image or picture

Box Control. See Tip 31: "Creating The Windows Wallpaper Effect for A

Complete explanation of the bitblt function.)

In The Example Program Below, We First Load An icon INTO An Image

Control. Then we modify the Image Control's Height and Width

Properties So The icon Becomes 75 Percent Smaller Than ITs Original

Size. The bitblt function is kiln used to copy the icon stores

Image Control to the Picture Box Contro.

EXAMPLE Program

..........................

2. Add The Following Constant and Declare Statements to the General

Declarations Section of Form1 (Note That The Declare Statement

Must Be Typed As a Single Line Of Code): Private Declare Function Bitblt LIB "GDI" (Byval HDestDC AS Integer,

Byval x askIDEGER, BYVAL Y AS INTEGER, BYVAL NWIDTH AS INTEGER,

Byval nheight as integer, byval hsrcdc as in

Byval xsrc as integer, byval ysrc as in

BYVAL DWROP As long) AS Integer

Const srccopy = & hcc0020

3. Add A Command Button Control To Form1. Command1 IS CREATED BY

DEFAULT. SET ITS CAPTION Property to "shrink icon".

4. Add the folowing code to the click Event for Command1:

Private submmand1_click ()

DIM X as integer

DIM Y AS Integer

DIM W AS INTEGER

DIM H AS INTEGER

DIM RET AS INTEGER

Image1 = loadingPicture ("c: /vb/icons/misc/binoculr.ico")

Image1.width = 0.75 * image1.width

Image1.height = 0.75 * image1.height

Picture1.width = image1.width

Picture1.height = image1.height

X = Image1.left / Screen.twipsPerpixelx

Y = image1.top / screen.twipsperpixely

W = Picture1.Width / Screen.twipsPerpixelx

H = Picture1.height / Screen.TwipsPerpixely

Ret = Bitblt (Picture1.HDC, 0, 0, W, H, Form1.HDC, X, Y, SRCCOPY)

Picture1.refresh

End Sub

5. Add an image control to form1. Image1 is create by default. Set

ITS Stretch Property to True.

6. Add A Picture Box Control To Form1. Picture1 IS CREATED BY

DEFAULT. SET ITOREDRAW Property to True.

return

Get information on bitmap file

Add a Picture control and a CommandButton control in the Form, add a bitmap file in the Picture control, add the following code:

Private Declare Function GetObject Lib "GDI32" Alias ​​"getObjecta" _

(Byval Hobject As Long, ByVal Ncount As long, lpobject as any) _

As long

Private Declare Function GetBitMapBits LIB "GDI32" (Byval Hbitmap As Long, _

Byval dwcount as long, lpbits as any) As long

Private Type Bitmap

BMTYPE AS Long

BMWIDTH AS long

Bmheight as long

BMWIDTHBYTES AS Long

BMPLANES AS INTEGER

BMBITSPIEL AS INTEGER

BMBITS As Long

End Type

Private submmand1_click ()

Dim Hbitmap As Long

DIM RES as long

DIM BMP as Bitmap

Dim Byteary () as Byte

DIM TOTBYTE As Long, i as long

Hbitmap = Picture1.Picture.handle

Res = getObject (HbitMap, Len (BMP), BMP) 'gets the structure of Bitmap

Totbyte = bmp.bmwidthbytes * bmp.bmheight 'How much is the total of Byte to save

Redim Byteary (Totbyte - 1)

'Saves information in Picture1 to Byteary

Res = getBitmapbits (Hbitmap, Totbyte, Byteary (0))

Debug.print "Total Bytes Copied:"; RES

Debug.print "bmp.bmbits"; bmp.bmbits

Debug.print "bmp.bmbitspixel"; bmp.bmbitspixel '

Debug.print "bmp.bmheight"; bmp.bmheight 'with prefacious image height

Debug.print "bmp.bmplanes"; bmp.bmplanes

Debug.print "bmp.bmtype"; bmp.bmtype

Debug.print "bmp.bmwidth"; bmp.bmwidth 'with a graphical width

Debug.print "bmp.bmwidthbytes"; bmp.bmwidthbytes' each scan line length of byte calculation

End Sub

return

Place a "transparent" picture

In VB, if you try to put a bird's picture on a tree on the background, you will find the tree to cover a rectangular area (ie the picture rectangle of the bird). We can transparently transparently transparently transparently transparently transparent to other parts of the picture:

We can use a WinAPI function Bitblt to make a series of bitctions to graphics to achieve this.

Function declaration:

Declare Function BitBlt Lib "gdi32" Alias ​​"BitBlt" (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

Parameter explanation:

Target environment: hDestDC - target equipment environment; X-upper corner; y - top; nwidth - wide; NHEIGHT - high

Source environment: hsrcdc - source device environment; XSRC - source left corner; YSRC - source top;

DWROP - bit processing operation, such as VBSRCAND; VBSRCCopy; VBSRCERase; VBSRCINVERT, etc. (target environment or source environment can only be Picture, Form or Printer object. Each unit is pixel.)

Before processed, we need to process the bird's picture: copy one of the same graphics, set it to black (bird's background) to black (set this picture as SPIC), then do the following Processing: Where you want to copy (bird) is set to black, the remaining place setting (bird's background) is white (set this picture as Mask).

The graphic of the tree is named DPIC.

Finally, please add the following code:

R = Bitblt (DPIC.HDC, 0, 0, Spic.width, Spic.height, Mask.hdc, 0,0, Vbscrcopy)

R = Bitblt (DPIC.HDC, 0, 0, SPIC.Width, Spic.height, SPIC.HDC, 0, 0, VBScrinVert)

postscript:

1, the PaintPicture method in VB provides similar functions, but the speed is not as good as this method;

2, in this method, add some code slightly, it is not difficult to implement the display of animation.

3. This method is used in CallDLLS in the VB example.

转载请注明原文地址:https://www.9cbs.com/read-2710.html

New Post(0)