|
-
Jan 2nd, 2012, 12:34 PM
#11
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
 Originally Posted by VbNetMatrix
I need to draw a New GdiIpImage that is 1024x768 (screen size) in size
with transparency. So unless I figure out how to perform that many SetPixelGDIplus in less then 3 second, I need to find another way...
Drawing onto the full-size image is possible but requires a bit more forethought. You can get a DC related to the actual image and draw directly to it. That does permanently change the image. Here's some sample code that will create a full screen image and draw a diagonal, blended, line from top left to bottom right. For future questions about these GDI+ APIs and other ones you may be interested in, you should post those questions in the VB or graphics portion of the forum. This is because you are now entering a different topic area that isn't directly related to the control.
You'll need a DC to the control's image after you create the full screen image. Then you'd set the interpolation on that DC and draw your lines & circles
Code:
' apis for this exercise
Private Declare Function GdipGetImageGraphicsContext Lib "GdiPlus.dll" (ByVal pImage As Long, ByRef graphics As Long) As Long
Private Declare Function GdipDeleteGraphics Lib "GdiPlus.dll" (ByVal mGraphics As Long) As Long
Private Declare Function GdipDrawLineI Lib "GdiPlus.dll" (ByVal graphics As Long, ByVal pen As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long
Private Declare Function GdipCreatePen1 Lib "GdiPlus.dll" (ByVal pColor As Long, ByVal nWidth As Single, ByVal unit As Long, ByRef pen As Long) As Long
Private Declare Function GdipDeletePen Lib "GdiPlus.dll" (ByVal pen As Long) As Long
Private Declare Function GdipSetInterpolationMode Lib "GdiPlus.dll" (ByVal hGraphics As Long, ByVal Interpolation As Long) As Long
Private Const UnitPixel As Long = 2&
' sample of creating a blank image
Dim ss As SAVESTRUCT, tGDIpImage As GDIpImage
' change ss.Width/Height as needed
ss.Width = Screen.Width \ Screen.TwipsPerPixelX
ss.Height = Screen.Height \ Screen.TwipsPerPixelY
ss.ColorDepth = lvicConvert_TrueColor32bpp_ARGB
' create a blank image of desired size & color depth
Set tGDIpImage = New GDIpImage
SavePictureGDIplus Nothing, tGDIpImage, , ss
' assign the image to the control & resize the control
Set AlphaImgCtl9 = tGDIpImage
AlphaImgCtl9.AutoSize = lvicSingleAngle
' sample of drawing a line on the actual image
Dim hGraphics As Long, hPen As Long
' get the DC for the image
If GdipGetImageGraphicsContext(AlphaImgCtl9.Picture.Handle, hGraphics) = 0 Then ' ok
' create a blue pen, 2 pixels in width
If GdipCreatePen1(ConvertRGBtoARGB(vbBlue), 2, UnitPixel, hPen) = 0 Then ' ok
' set interpolation mode.
' Note that if using my RenderInterpolation enum, you need to add 2.
' DO NOT use .lvicAutoInterpolate
GdipSetInterpolationMode hGraphics, RenderInterpolation.lvicHighQualityBicubic + 2
' draw the line & clean up
GdipDrawLineI hGraphics, hPen, 0, 0, AlphaImgCtl9.ScaleWidth - 1, AlphaImgCtl9.ScaleHeight - 1
GdipDeletePen hPen
End If
GdipDeleteGraphics hGraphics
End If
AlphaImgCtl9.Refresh ' view the changes
 Originally Posted by VbNetMatrix
now the problem lie in the fact that I don't know the Size Screen of all client and it's possible it would not always be 1024x768...
That's easy enough:
screenCx = Screen.Width\Screen.TwipsPerPixelX
screenCy = Screen.Height\Screen.TwipsPerPixelY
Note that you probably won't get full screen anyway. Any taskbars take away from the available screen size. If your form is not borderless, then your form's borders, titlebar, menubar take size away too. If you want to get the total available size your maximized form will display, use this instead. Form's scalemode must be twips else use ScaleX/ScaleY as needed
maxWidth = Me.ScaleWidth\Screen.TwipsPerPixelX
maxHeight = Me.ScaleHeight\Screen.TwipsPerPixelY
Last edited by LaVolpe; Jan 2nd, 2012 at 12:49 PM.
Tags for this Thread
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
|