You cannot. That was mentioned in the comments/feedback section of that link. That control was designed for users of custom drawn controls (i.e., buttons, grid controls, image controls, etc) where the image is not assigned to a property, but drawn manually on the control. Hope that answers your question. I've stopped supporting all code on PSC when I left PSC. I won't be making any changes to that project nor re-creating it.
Insomnia is just a byproduct of, "It can't be done"
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [1 June 2011]
Updated 1 Jun 2011
- Added support for creating animated GIFs
- Added support for creating multi-image icons/cursors
- Added support for creating PNG-embedded icons/cursors (Vista and above can read these)
See the comments/examples in AICGlobals.SavePictureGDIplus class and also the SavePictureGDIp.rtf file
Insomnia is just a byproduct of, "It can't be done"
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [2 June 2011]
Hi Folks,
I recently recieved a requiriment that should be addressed with rotated transparent text in different angles even with different font sizes and colors.
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [2 June 2011]
Originally Posted by Bigweld
...I recently recieved a requiriment that should be addressed with rotated transparent text in different angles even with different font sizes and colors.
Does anyone has ideas on how to accomplish that? ...
Please do not post questions here not directly related to my project. Your question should be posted in the graphics or vb portion of the forums. Thank you.
Insomnia is just a byproduct of, "It can't be done"
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [2 June 2011]
Don't worry about it. It'll serve as a reminder for others. I think I read somewhere that the 'privilege' of deleting your posts was tied to some magic number of overall posts one has made as a forum member. Anyway, here's the "how to" if you are enabled to.
Insomnia is just a byproduct of, "It can't be done"
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [2 June 2011]
Hi Lavolpe
I'm trying to present images using AlphaImgCtl controls dynamically generated.
The last dynamically created image should be presented at the top in the zOrder but I could not get it.
Regardless the ZOrder I set, the firt presented image remains at the top and the rest are presented behind it.
There is the code that I made:
a) This is the part that dynamically creates the set of images to be used. This set is not visible to the user while the program runs.
Code:
Sub LoadDeck()
Dim f As Byte
Dim Lavolpe(51) As AlphaImgCtl
For f = 0 To 51
Set Lavolpe(f) = Controls.Add("LaVolpeAlphaImg.AlphaImgCtl", "Lavolpe" & CStr(f))
Lavolpe(f).Picture = LoadPictureGDIplus(CARD_BASE_PATH & CStr(f) & PNG_EXTENSION)
Next
End Sub
b) This is the part that uses the previous generated controls and then sets the image according the desired index when necessary.
Code:
Sub ShowCard(OffsetMultiplier As Byte)
Static z As Byte
Dim a As AlphaImgCtl
Set a = Controls.Add("LaVolpeAlphaImg.AlphaImgCtl", "c" & CStr(z), Me)
With a
.Top = CARD_INITIAL_POSY - (POSY_CARD_OFFSET * OffsetMultiplier)
.Left = 527
.Width = 180
.Height = 270
Set .Picture = Lavolpe(m.CardID).Picture
.ZOrder z
.Enabled = True
.Visible = True
End With
z = z + 1
End Sub
Would you like to take a look to it, please?
Not sure if there is an issue of the AlphaImgCtl or mine
Thanks in advance
B.
PS: Its seems like the 'delete post' option is not avalible. I see just the 'edit post' option while trying to remove my previous post. Sorry.
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [2 June 2011]
You have to understand the ZOrder method. Your z variable is useless. The only two values allowed for the ZOrder method are: vbSendToBack or vbBringToFront.
Edited: Has nothing to do with the Alpha Image Control. The ZOrder method is one that all VB controls have, including usercontrols created with VB. The control itself does not process that, VB does for the control.
Last edited by LaVolpe; Jun 4th, 2011 at 09:57 PM.
Insomnia is just a byproduct of, "It can't be done"
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [12 June 2011]
FYI: Small enhancement added today... The Interpolation property.
By default the image quality is always highest possible. It will render with high-quality bicubic interpolation whenever the image is rotated or scaled to a different size than the original. There may be cases when a lower quality rendering is desired. Basically lower quality means faster renders, while higher qualities mean slower renders. Now you have that option to render at any of the other 5 quality settings offered.
Insomnia is just a byproduct of, "It can't be done"
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [12 June 2011]
A question came up recently how one can use rotation to animate a "knob" manually. Here's one idea.
1. Add an AlphaImgCtl to your form
2. Assign that control a nice picture of a knob or something circular
3. If the picture is not circular
-- change the control's .AutoSize property to lvicMultiAngle & control will resize itself
-- change the control's .AutoSize property to lvicNoAutoSize & adjust size as needed
-- set the control's .Rotation property to several settings at 45 degree intervals to ensure image is not cropped at those angles
-- if image is cropped at a certain angle, enlarge your control size a bit & repeat previous 2 steps
4. Paste this code in your form
Code:
Private m_StartAngle As Single
Private Sub AlphaImgCtl1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
With AlphaImgCtl1
' want zero degrees due North, so passing an offset of -90
m_StartAngle = CalculateAngle(X - .ScaleWidth \ 2, Y - .ScaleHeight \ 2, -90)
End With
End If
End Sub
Private Sub AlphaImgCtl1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
' want zero degrees due North, so passing an offset of -90
X = CalculateAngle(X - AlphaImgCtl1.ScaleWidth \ 2, Y - AlphaImgCtl1.ScaleHeight \ 2, -90)
Y = (X - m_StartAngle)
If Y Then
AlphaImgCtl1.Rotation = AlphaImgCtl1.Rotation + Y
m_StartAngle = X
' perform whatever action the knob would do: change sound volume, rotate some other image, etc
End If
End If
End Sub
Private Function CalculateAngle(ByVal X As Single, ByVal Y As Single, _
Optional AngleOffset As Single, Optional AngleStep As Single = 1!) As Single
' returns a Degree vs Radian usable for properties that require angles in degrees vs. radians
' X & Y must be offset from a reference point
' -- the reference point is usually the center of whatever you want rotated
' -- So X may be: X - CenterPoint
' and Y may be: Y - CenterPoint
' AngleOffset is used to change what 0 degrees is relative to
' -- by default, 0 degrees is due West
' -- if you want due North to be 0 degrees, then pass AngleOffset as -90
' -- Why -90? If 0 is really due West then due North is 90 (clockwise rotation),
' so to make due North zero, we need to subtract 90
' AngleStep is used to restrict returned degrees to a fixed step value
' -- If you want the degrees to be returned in increments of 10, then pass 10
' -- If AngleStep is 10, then degrees < 10 will be returned as zero, < 20 returned as 10, etc
Dim Radian As Single
Dim xDiff As Single
Dim yDiff As Single
Dim Angle As Single
Const PI As Single = 3.14159265358979
xDiff = -X
yDiff = -Y
If Abs(xDiff) < 0.00000001 Then xDiff = 0!
If Abs(yDiff) < 0.00000001 Then yDiff = 0!
If xDiff <> 0! Then
Radian = Atn(yDiff / xDiff)
If xDiff < 0 Then Radian = Radian + PI
Else
If yDiff < 0 Then
Radian = 3! * PI / 2! '90
Else
Radian = PI / 2! '270
End If
End If
If Radian < 0! Then Radian = Radian + PI * 2!
Angle = Radian * (180! / PI) + AngleOffset
If Angle < 0! Then Angle = Angle + 360!
' restrict rotation to n degree increments
If AngleStep Then
CalculateAngle = Int((Angle \ AngleStep) * AngleStep)
Else
CalculateAngle = Angle
End If
End Function
5. Now run your form, hold mouse down on the control and start rotating it.
Edited: Using above code, you will notice that sensitivity to changes is greater while mouse is closer to center of control and less sensitive the further away the mouse is from that center.
Edited yet again. For those that use the above logic, the assumption is that the image is rendered center of control. If image is rendered top left, adjust the center point in MouseDown & MouseMove
If you get an error saying .ScaleWidth & .ScaleHeight are not supported, you are using a previous version of the control.
Last edited by LaVolpe; Jun 29th, 2011 at 08:01 AM.
Insomnia is just a byproduct of, "It can't be done"
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [12 June 2011]
Originally Posted by LaVolpe
A question came up recently how one can use rotation to animate a "knob" manually. Here's one idea.
1. Add an AlphaImgCtl to your form
2. Assign that control a nice picture of a knob or something circular
3. If the picture is not circular
-- change the control's .AutoSize property to lvicMultiAngle & control will resize itself
-- change the control's .AutoSize property to lvicNoAutoSize & adjust size as needed
-- set the control's .Rotation property to several settings at 45 degree intervals to ensure image is not cropped at those angles
-- if image is cropped at a certain angle, enlarge your control size a bit & repeat previous 2 steps
4. Paste this code in your form
5. Now run your form, hold mouse down on the control and start rotating it.
Edited: Using above code, you will notice that sensitivity to changes is greater while mouse is closer to center of control and less sensitive the further away the mouse is from that center.
Good algorithm (CalculateAngle) for rotation using 'knob' manually. But we can resize AIC & rotate pic at the same time with a bit of modification of CalculateAngle (using xDiff and center position of AIC to determine the zoom changes).
One annoying thing is GDI+ doesn't draw Anti-aliasing for two edges of a rotated pictures.
Last edited by Jonney; Jun 29th, 2011 at 01:03 AM.
Reason: resize AIC & rotate pic at the same time
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [12 June 2011]
Another nice routine.
version 1.1 of GDI+ library has some niffty effects but not available to v1.0 of GDI+. One such effect is a blur. v1.1 has a true gaussian blur routine. If you want a blur routine for v1.0, the following may be useful. It is not a true blur but produces good results.
You'll need these 2 GDI+ API delcarations
Code:
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
1. On a new form, add 2 AlphaImgCtl controls and 1 command button
2. Add an image to AlphaImgCtl1
3. Make the AlphaImgCtl2 same size as AlphaImgCtl1
4. Copy & paste following code. Run project & click on the button. Play with different blur depths
Code:
Private Sub Command1_Click()
' modified from this source: http://www.autohotkey.net/~tic/Gdip.ahk
Dim tImg As GDIpImage
Dim SS As SAVESTRUCT, hGraphics As Long
' create a new blank image same size as source image & place in 2nd image control
SS.ColorDepth = lvicConvert_TrueColor32bpp_pARGB
SS.Width = AlphaImgCtl1.Picture.Width
SS.Height = AlphaImgCtl1.Picture.Height
Set tImg = New GDIpImage
SavePictureGDIplus Nothing, tImg, , SS
Set AlphaImgCtl2.Picture = tImg
' create new temp blank image a fraction size of source image
' change the percentage to smaller values for greater effect & higher for lesser effect
SS.Width = AlphaImgCtl1.Picture.Width * 0.33
SS.Height = AlphaImgCtl1.Picture.Height * 0.33
If SS.Width = 0 Or SS.Height = 0 Then
MsgBox "Blur depth is too great"
Exit Sub
End If
Set tImg = New GDIpImage
SavePictureGDIplus Nothing, tImg, , SS
' render the source image onto temp image at fraction of size
GdipGetImageGraphicsContext tImg.Handle, hGraphics ' function only works for 24bpp & above
AlphaImgCtl1.Picture.Render 0&, , , SS.Width, SS.Height, , , , , , , hGraphics, , lvicHighQualityBicubic
GdipDeleteGraphics hGraphics
' render temp image to full size and update 2nd control
GdipGetImageGraphicsContext AlphaImgCtl2.Picture.Handle, hGraphics
tImg.Render 0&, , , AlphaImgCtl1.Picture.Width, AlphaImgCtl1.Picture.Height, , , , , , , hGraphics, , lvicHighQualityBicubic
GdipDeleteGraphics hGraphics
AlphaImgCtl2.Refresh
Set tImg = Nothing
End Sub
Insomnia is just a byproduct of, "It can't be done"
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [12 July 2011]
FYI. Updated version posted today.
- Fixed couple minor errors in ICO & GIF creation routines
- Added ability to load image from Base64 encoded string
- Added AlphaMask & RenderSkewed functions to GDIpImage class (see class comments)
- Updated couple sample projects using newly added functions (see Change History on post #1)
Insomnia is just a byproduct of, "It can't be done"
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [13 July 2011]
WOW lavolpe
Good day
Very good and interesting your project, excuse my question, is there any way to remove the rest of the form and only leave the control and also encourage you, thank you for your answer
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [13 July 2011]
astronald, welcome to the forums.
The zip file containing the control. Unzip it to a folder and open the .vbp file. Compile it. It will become a stand-alone OCX that you can add to your toolbox whenever you want. Should I update the control and you re-download, be sure to compile future revisions with binary compatibility. There is a link in post #1 I point people to, to better understand binary compatibility if this is a new topic to you.
The zip file containing the sample projects are there just for educational purposes. They have no bearing on the actual control.
Insomnia is just a byproduct of, "It can't be done"
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [13 July 2011]
I have a memory leak in my project which is loading and unloading alpha image controls in a control array. It seems as though every time I add another object to the array it will add two gdi objects however when I unload an object either one or no gdi objects will go away. I’ve attached a simple project which shows the problem.
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [13 July 2011]
Originally Posted by cheesebrother
I have a memory leak in my project which is loading and unloading alpha image controls in a control array...
Edited: For others reading this post. If you read my "Memory Leak FAQ", linked in my signature below, you'll know what we are talking about, regarding GDI counts.
I can't reproduce the problem. Well, I can sort of
1. My baseline GDI count is 513 let's say. That's the count before running the project
2. I run the project (ensuring no other VB MDI child widows open). Count = 525
3. I add 5 new controls & count rises to 534
4. I then remove those 5 controls & count drops to 529
It does appear 1 leak per object. But it isn't & here's why:
5. Close form normally. Count now reads: 513
When VB loads DLLs/OCXs. It doesn't exactly clean up memory right away when the instance of it is removed. I can't tell you the intricacies of how VB's garbage collection works because I don't know. However, the fact that the GDI count did not change from starting the project to ending the project, indicates no leaks. Agreed?
Last edited by LaVolpe; Jul 29th, 2011 at 10:45 AM.
Insomnia is just a byproduct of, "It can't be done"
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [13 July 2011]
Originally Posted by cheesebrother
Thanks. I can see what you're saying. Great control.
You're welcome & thanks for the compliment.
FYI: Using your sample code, you can reduce memory usage. Add this before making your control visible
Code:
Set object(object.UBound).Picture = object(object.LBound).Picture
When you dynamically load a control that already contains a picture, that picture's data & GDI+ objects are replicated not shared. You can verify this by printing out the object(object.UBound).Picture.Handle property. Using the above tweak, all is shared. However, in post #3 back on page #1, read the gotchas about sharing multi-image formats
Insomnia is just a byproduct of, "It can't be done"
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [13 July 2011]
Hello
I've been using LaVolpeAlphaImg.
To become a better control
I hope the following features are added.
1. picturebox, grid control with the features that happens when you come to a top layer
2. Png in the form to apply full-screen window (like the splash window)
Pay as you think, if this feature has to pay.
Have a nice day.
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [13 July 2011]
There is one other thing that i've been trying to do. Is there a way to have vb compile the alpha image control pictures without putting them in a resource file? I tried running my program on another computer and got an error that said "Component 'LaVolpeAlphaImg3.ocx' or one of its dependancies not correctly registered: A file is missing or invalid."
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [13 July 2011]
Originally Posted by shaneshock@nate.com
To become a better control
I hope the following features are added.
1. picturebox, grid control with the features that happens when you come to a top layer
2. Png in the form to apply full-screen window (like the splash window)
#1. Have no idea what you are suggesting. Are you asking for a picturebox control version of the Alpha Image Control? If so, won't happen. This control cannot be made to be a container of other controls, especially windowed controls.
#2. Not sure what you meant there either. If you want the control & image to size to the form, simply change the control's dimensions in the form's resize event. Also set the Aspect & AlignCenter properties for the stretching/alignment of the contained image, as desired.
Insomnia is just a byproduct of, "It can't be done"
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [13 July 2011]
Originally Posted by cheesebrother
There is one other thing that i've been trying to do. Is there a way to have vb compile the alpha image control pictures without putting them in a resource file? I tried running my program on another computer and got an error that said "Component 'LaVolpeAlphaImg3.ocx' or one of its dependancies not correctly registered: A file is missing or invalid."
The pictures assigned to a control during design time are stored in the hosting form's .frx file & compiled within your app when app is compiled. That isn't the reason for your error. You can't just copy the ocx to another pc and expect it to work, the ocx needs to be registered on that other pc. Suggest creating a proper install setup.exe for your application
Insomnia is just a byproduct of, "It can't be done"
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [13 July 2011]
Originally Posted by astronald
Thanks Lavolpe, I liked the clock project.
would be without you see the gray background of the form, thanks again for your help.
If you are asking how to make something like a clock widget that would show up on the desktop and without a form's background showing thru, that is a project all in itself. I'll give you these hints. But for assistance you should post your questions in the graphics or VB6 portion of the forums, not here in the codebank or in this thread. This is all the help I'll provide since your question isn't related to how my project works.
1. Use SetLayeredWindowAttributes & UpdateLayeredWindow APIs to draw your clock on a transparent form. The form should be made an owned window to the desktop if clock is to appear on the desktop
2. This usercontrol cannot be used as is because of how UpdateLayeredWindow works. But you can still draw the clock parts to the form every second (if second hand is displayed) or every minute if no second hand used. The usercontrol's PaintImageAsDrawnToHDC function would be helpful here or accessing the Picture property's .Render function directly.
Search the forums for examples of the 2 APIs I mentioned. Good luck.
Insomnia is just a byproduct of, "It can't be done"
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [13 July 2011]
Originally Posted by mjohnlq
Hi. I use the control, but found some problem.
please see the attachment.
Forgot the attachment. If you include the jpg, also tell me whether the control is showing the image actual size or not. Also show the code you are using the extract the color
Insomnia is just a byproduct of, "It can't be done"
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [14 August 2011]
Updated control. See 1st post
- Can now create animated PNG
- Prevented control from trying to process 64bit binaries for images
- GDIpImage.AnimationLoops property returns animated PNG loop count
- New control method Animate2 is class-based version of older Animate method
- Added ability to do a screen capture to 24bpp bitmap
Edited: To test animated PNGs without using my control, use FireFox to open the animated PNG file
Last edited by LaVolpe; Aug 14th, 2011 at 09:57 PM.
Insomnia is just a byproduct of, "It can't be done"
Private Sub Form_Load()
AlphaImgCtl1.WantPrePostEvents = True
End Sub
Private Sub Form_Resize()
AlphaImgCtl1.Move Me.ScaleLeft, Me.ScaleTop, Me.ScaleWidth, Me.ScaleHeight
End Sub
///////////////////////////////////////////////////////////////
Above code can't run correct, if AlphaImgCtl1.WantPrePostEvents = false then it is correct.
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [14 August 2011]
Originally Posted by mjohnlq
Hi.
When AlphaImgCtl1.WantPrePostEvents = True, then AlphaImgCtl can't resize correct.
Thanx for the bug report. An undiscovered bug that's persisted through last several versions.
I think I know what is happening and will look into it. In the mean time, setting WantPrePostEvents in the property sheet instead of form_load will have expected results
Update: Figured out the problem... logic error. I never coded for scenario where WantPrePostEvents without an image assigned to the control - not enough foresight there. Requires tweaks in 2 routines & will upload patch by Aug 17th after a bit more testing
Last edited by LaVolpe; Aug 15th, 2011 at 11:16 AM.
Insomnia is just a byproduct of, "It can't be done"
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [14 August 2011]
Originally Posted by mjohnlq
Set AlphaImgCtl2.Picture = AlphaImgCtl1.SaveControlAsDrawnToGDIpImage(True)
Above Code is invalid.
Can you be more specific? What's invalid about it? If the following resolves the issue, please let me know also
If AlphaImgCtl2 isn't showing the complete image, try this:
Code:
AlphaImgCtl2.AutoSize = lvicSingleAngle
Set AlphaImgCtl2.Picture = AlphaImgCtl1.SaveControlAsDrawnToGDIpImage(True)
Also note that AlphaImgCtl1 must be visible
Edited: If there is no image assigned to the usercontrol, there is a check for that to abort the routine. I can see where this may not be desirable. I'll include that modification also. Simply remove the following line from the usercontrol's SaveControlAsDrawnToGDIpImage function: If m_Image.Handle = 0& Then Exit Function
The same scenario for SaveImageAsDrawnToGDIpImage does not apply. That function relates to the loaded image only, not any background graphics. Therefore if no image loaded, SaveImageAsDrawnToGDIpImage will abort
Last edited by LaVolpe; Aug 16th, 2011 at 11:03 AM.
Insomnia is just a byproduct of, "It can't be done"
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [14 August 2011]
Originally Posted by mjohnlq
Please see the attachment, the copy button has no effect.
Now I understand. Thanx for the example. Need to think this over a bit.
AlphaImgCtl1 is user-drawn in that example. The PrePaint event draws the image itself then tells the control to not draw its copy. So, that does explain why no graphics were returned to AlphaImgCtl2 since AlphaImgCtl1 was told not to draw the image
I'll be considering this. The following scenarios are possible along with what I consider commonsense responses
I. If WantPrePostEvents is True then graphics may or may not be user-drawn
a. If the control is told to abort painting by passing the PrePaint event's Cancel parameter as True
-- SaveControlAsDrawnToGDIpImage has no choice but to return the graphics as drawn by the user since the control will not be drawing the image. This will include any background fill/graphics since the user dictates everything
b. If the control is NOT told to abort painting then
-- SaveControlAsDrawnToGDIpImage should function as intended
II. If WantPrePostEvents is False then no user-drawn graphics to worry about
-- SaveControlAsDrawnToGDIpImage should function as intended
III. The SaveImageAsDrawnToGDIpImage function is not affected. It uses the control's image and any image properties (i.e., rotation, grayscaling, etc)
Insomnia is just a byproduct of, "It can't be done"