-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [13 July 2011]
Quote:
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?
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [13 July 2011]
Thanks. I can see what you're saying. Great control.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [13 July 2011]
Quote:
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
-
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]
Quote:
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.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [13 July 2011]
Quote:
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
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [13 July 2011]
Okay, I'll need to learn how to do that. Sorry to bother you.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [13 July 2011]
Thanks Lavolpe, I liked the clock project.
would be without you see the gray background of the form, thanks again for your help.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [13 July 2011]
Quote:
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.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [13 July 2011]
Hi. I use the control, but found some problem.
please see the attachment.
I read the contact.jpg use GDIpImage.
But I get the different color value in point (x,y) = (0,64) form photoshop or paint.
use GDIpImage, I get
'Red:255;Green:255;Blue:251;Alpha:255
when use photoshop or paint or other soft ,I get
'Red:255;Green:255;Blue:255;Alpha:255
Plese help me see what's wrong?
Thanks!
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [13 July 2011]
Quote:
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
-
1 Attachment(s)
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [13 July 2011]
Hi, LaVolpe,
I found the problem.
It's my mistake, (x, y) should be (y, x).
now, the value is the same with other software.
Thanks!
-
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
-
1 Attachment(s)
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [14 August 2011]
Hi.
When AlphaImgCtl1.WantPrePostEvents = True, then AlphaImgCtl can't resize correct.
//////////////////////////////////////////////////////////////
Option Explicit
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.
Please see the attachment!
Thanks!
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [14 August 2011]
Quote:
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
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [14 August 2011]
Hi
SaveControlAsDrawnToGDIpImage
e.g
///////////////////////////////
Set AlphaImgCtl2.Picture = AlphaImgCtl1.SaveControlAsDrawnToGDIpImage(True)
//////////////////////////////
Above Code is invalid.
And SaveImageAsDrawnToGDIpImage may have the same problem.
Thanks!
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [14 August 2011]
Quote:
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
-
1 Attachment(s)
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [14 August 2011]
Hi.
Please see the attachment, the copy button has no effect.
Thanks!
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [14 August 2011]
Quote:
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)
-
1 Attachment(s)
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [14 August 2011]
Hi.
GDIpImage.Render may have problem.
I want use GDIpImage.Render to draw a jpg's right-bottom corner in a picturebox, but I found there has some Offset.
I didn't know why.
Please see the attachment.
Thanks!
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [14 August 2011]
Quote:
Originally Posted by
mjohnlq
...but I found there has some Offset.
I didn't know why.
Double check the parameter values you are passing. You are trying to render a 400 pixel wide image 30x larger than actual size.
Code:
passing DestWidth & DestHeight as: k.Height * 30, k.Width * 30
If you want to render the bottom right corner, I would suggest setting the SrcX, SrcY, SrcWidth & SrcHeight parameters vs rendering the entire image to some large negative offset.
Bottom line. I don't see anything incorrect with the .Render function at this time. Appears the parameter values are the error.
-
1 Attachment(s)
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [14 August 2011]
Hi.
Thanks for your suggestion.
I want use GDIpImage to enlarge and shrink a picture as photoshop do.
But the problem is still exist.
The method2 is what I did as your suggestion.
Please see the attachment.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [14 August 2011]
Quote:
Originally Posted by
mjohnlq
... but I found there has some Offset.
I didn't know why.
Ignore previous replies, I now see what you are talking about.
I had to change the picturebox's backcolor to dark so the offset was obvious.
I'm looking into it and it isn't an issue with the control; but may be some GDI+ anomaly. Hopefully will know more later.
Follow-up. Increasing the zoom factor also increases the unwanted offset. Obviously a factor of 1 has no offset, where a factor of 50 has quite a big offset. This is definitely GDI+ related, not control related. Still looking...
Update. Figured out I think. The offset you see appears to be directly proportional to the zoom factor. If you are zooming 30x then you'll see an offset of 15 pixels. Haven't played with zoom values < 1 (i.e., .5). This 'bug' also seems to apply only if the X and/or Y coords are less than zero; no offsets seen with X,Y => 0
The following adjusts the X,Y coords by half the zoom & appears to render well. However, flaky in my opinion & not 100% sure it works in all cases. I'll do a bit more research and see if I can find some sort of GDI+ setting that will prevent these offsets.
Code:
Const zoom As Single = 30
Dim X As Long, Y As Long
Dim m_Effects As New GDIpEffects
Dim k As GDIpImage
Set k = LoadPictureGDIplus(App.Path & "\contact.jpg")
Picture1.Cls
X = Picture1.ScaleWidth - k.Width * zoom
Y = Picture1.ScaleHeight - k.Height * zoom
If X < 0& And zoom > 1 Then X = X + zoom / 2
If Y < 0& And zoom > 1 Then Y = Y + zoom / 2
k.Render Picture1.hDC, X, Y, k.Width * zoom, k.Height * zoom, , , , , , m_Effects.AttributesHandle, , 0, RenderInterpolation.lvicNearestNeighbor
Final Update: Ok, I've found what I believe is the answer. There is another GDI+ setting that can be used & appears to solve the problem. No need to adjust X,Y coords based on zoom factor.
1. Add this API declaration to your GDIpImage class, at very top of class after the Option Explicit line
Code:
Private Declare Function GdipSetPixelOffsetMode Lib "gdiplus" (ByVal graphics As Long, ByVal PixOffsetMode As Long) As Long
2. In the GDIpImage.Render method, add call to that API as described below. Note you'll find two places in that routine with identical lines of code. Add the new call to both sections of the code.
Code:
...
Else
Call GdipSetInterpolationMode(hGraphics, Interpolation + 2&)
End If
' insert new call here:
Call GdipSetPixelOffsetMode(hGraphics, SmoothingModeAntiAlias)
This will be added to the latest modifications when I post them this weekend. Need to test a few things first.
-
1 Attachment(s)
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [14 August 2011]
Hi
Thank your very very much.
I has another question.
I found photoshop's cursor can be very large if set the pen's width....
I want change the cursor's size too. But widows's cursor size is fixed to 32 x 32, it' is very bad. I don't know how photoshop can change cursor's size.
I found some other post of you that can use CreateIconFromResourceEx to create a cursor, but it can't change cursor's size too.
Now, I found GDIpImage can save a .ico to .cur, I want set my cursor use the ico, the ico's size is 16 x 16, and i want change it to a 32 x32 cursor.
below is what i do, but has problem.
Please see the attachment.
//////////////////////////////////////////////
Private Sub SetCursor_Click()
Dim k As New GDIpImage
Set k = LoadPictureGDIplus(VB.LoadPicture(App.Path & "\1.ico")) ' (VB.LoadResPicture(101, vbResIcon)).
Dim m As New StdPicture
'I want change the ico's size from 16 x 16 and then set the cursor's hot spot , how can I do?
' k.Width = 32 'I Can't change it
' k.Height = 32 'I Can't change it
SavePictureGDIplus k, m, lvicSaveAs_HCURSOR
Me.MousePointer = MousePointerConstants.vbCustom
Set Me.MouseIcon = m
End Sub
//////////////////////////////////////////////////////
could you help see what's is wrong with me?
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [14 August 2011]
To set a cursor's hotspot, pass a SAVESTRUCT in the last optional parameter of SavePictureGDIplus
Using sample code from your test5 zip
Code:
Dim SS As SAVESTRUCT
SS.CursorHotSpotX = newHorizontalHotSpotValue
SS.CursorHotSpotY = newVerticalHotSpotValue
SS.Width = 32: SS.Height = 32
SavePictureGDIplus k, m, lvicSaveAs_HCURSOR, SS
Edited: Note that because this is being resized, will most likely cause alphablending during resizing. stdPicture object's cannot accept alphablended images and any resized cursor pixels not fully opaque or fully transparent will be turned to fully transparent. This will have the effect of losing some detail in the cursor. To overcome this problem, recommend also setting the SS.AlphaTolerancePct value to 25 which produces good quality complex-to-simple transparency reduction. stdPicture icons/cursors only support simple transparency. The SavePictureGDIp.rtf document included with the project attempts to explain that. The SS.AlphaTolerancePct member was designed for such cases: stdPicture icons/cursors, GIFs, & metafiles
Another option instead of using the SS.AlphaTolerancePct member is to use the SS.RSS.Quality member and set it to lvicNearestNeighbor. But I think the quality of stretching will be less professional than using the SS.AlphaTolerancePct member
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [14 August 2011]
Hi, LaVolpe
Thanks very much.
But I still have questions:
1. If I needn't stretch the icon,
can GDIpImage let me not stretch the 16 * 16 icon , only add the icon size to 32 * 32? because i need show a small cursor as photoshop do.
if stretch the icon, the cursor is twice the size, this is not what i want.
2. If I need stretch the icon,
set SS.Width = 128: SS.Height = 128, the width has no effect.
the width and the height is always 32.
So how Can I show a very big cursor like photoshop?
3. If the Icon is stretch,
SS.CursorHotSpotX = 0
SS.CursorHotSpotY = 0
is not right, it has some offset.
in test5, when the mouse move to the title, the cursor still didn't restore.
Thanks!
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [14 August 2011]
mjohnlq, regarding the offsets when zooming... I found a final solution I believe. See post #204 where I included the patch.
Note: That issue had nothing to do with negative X,Y offsets. What was really the issue, as proven by some of my testing, was using nearest-neighbor interpolation along with stretching/zooming. What GDI+ was doing was pre-sizing the output image size based on bicubic/bilinear interpolation. That means the overall image is expanded by the 1/2 the zoom factor in all directions which is typical for that interpolation model. But when GDI+ rendered the image, it clipped the 'blurred' portion which made it look as though image was rendered offset by a few pixels. It was actually clipped. By providing the new GDI+ setting, the issue no longer exists. Just FYI
And regarding the cursor not staying custom when you move to the titlebar.... The custom cursor only applies to the client area of your form, not the titlebar, menubar, or borders. If you want cursor to apply to entire form, use Screen.MouseIcon instead of Me.MouseIcon
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [14 August 2011]
mjohnlq, regarding cursors sizes....
VB is to blame here.
The icon you provided in your zip contains just one 16x16 icon. However, when you load an icon/cursor into a MouseIcon property, it seems to always come out visually as 32x32 regardless of what its original size is.
But that is just an illusion. VB is doing something behind the scenes. The stdPicture object (Me.MouseIcon) is really 16x16 !!!! Don't believe it, then try this:
Debug.Print ScaleX(Me.MouseIcon.Width, vbHimetric, vbPixels)
Also note that VB and cursors/icons behave slightly different when app is compiled. You may want to test a 16x16 & 32x32 MouseIcon image from a compiled test app.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [14 August 2011]
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [19 August 2011]
Updated version posted today.
Updates are to address issues discovered by mjohnlq. Refer to posts 195-204 for more details.
-
1 Attachment(s)
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [19 August 2011]
hi.
Other software can read cursors in attachment, but GDIpImage can't.
You can use prjTheBasics to test it.
Thanks!
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [19 August 2011]
Quote:
Originally Posted by
mjohnlq
Other software can read cursors in attachment, but GDIpImage can't.
Actually it can read them, but are aborting because they are not formatted correctly.
Those cursors have the height set at zero within the icon directory entry. Not sure if you are well versed on icon file structure. Anyway, zero equates to 256 for icons/cursors & those cursors are 32x32 except one which is 16x16. I have included patches for mal-formatted image data in other image formats; so I'll include a patch for these types of icons/cursors too
I'll tweak the project to handle these situations when possible. Since all icons/cursors are really bitmaps with masks, that bitmap information also has dimensions. I can bounce the bitmap dimensions up against the icon structure dimensions and internally modify the icon structure as needed. Bottom line, with a properly written icon, the icon structure should be correct, but the bitmap data should always override the icon structure info.
Thanx for the sample icons. I don't expect this tweak to be implemented before the weekend & hope that's not an issue for you.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [19 August 2011]
Yes, the format of the cursor files is invalid !
I think it is needn't modify the codes for these invalid format cursor file.
Thanks verh much!
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [19 August 2011]
Quote:
Originally Posted by
mjohnlq
Yes, the format of the cursor files is invalid !
I think it is needn't modify the codes for these invalid format cursor file.
I'll modify the code because Windows has no issues displaying them and I'd like to at least be able to do what Windows does. The modification is relatively simple
-
1 Attachment(s)
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [19 August 2011]
Hi.
I have another two cursor file, their format is valid.
But AlphaImgCtl maybe show incorrect.
in attachment.
1. "See in other soft.png" is when the two cursors show in other software.
2. test6 is test show the cursor files use AlphaImgCtl .
you can see, AlphaImgCtl can't show complete.
Thanks very much!
-
1 Attachment(s)
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [19 August 2011]
Quote:
Originally Posted by
mjohnlq
Hi.
I have another two cursor file, their format is valid.
But AlphaImgCtl maybe show incorrect.
Ok, that's a logic bug. I'll look into it -- gotta be something wrong with my mask processing section
Though... When looking at the icon/image in Windows Explorer or on my desktop, it is displayed like the AlphaImgCtl. If I were to load the cursor into a VB Image control, it is displayed like in your png snapshot. Interesting
Update: I will need to handle black&white cursors/icons a bit differently. I can now render the exact same image as shown in your png snapshot & VB's image control. However, in reality, 1 bit cursors/icons that use an XOR mask (as does your cursor), what you get depends on what the cursor is currently rendered over. See attached. For my control, the assumption for drawing is that cursor will be over a white background.
Attachment 85519
In above image, the top 4 boxes is the same cursor, in VB's Image Control, drawn over colored squares. The bottom image is modified code to handle B&W cursors/icon processing differently, more correct. Modified code not yet posted.
Final update. Had to handle the AND & XOR masks manually to guarantee I could draw the icons exactly correct. I'll include the patch in the next update, expected end of August.
-
Green Screen / ChromaKey
Hello Keith,
I have a feature request:
Would it be possible to add an option for Green Screen removal? Where a photo is taken against a green or blue screen and you can convert the background to transparent?
Lots of controls have the ability to replace a color or make it transparent, but to do true ChromaKey you would need to be able to supply a color and then be able to convert that color in addition to a range of lighter and darker colors to transparent.
Sound like something that is possible?
Also, any thoughts on watermark options? The ability to set a font, color, style, position, transparency and rotation would be really nice addition as well.
Regards,
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [19 August 2011]
Regarding green screen ability -- already there but will make the color 100% transparent throughout. The two properties you'll need to set are: TransaprentColor and TransparentColorMode
For example using vbGreen
AlphaImgCtl1.TransparentColor = vbGreen
AlphaImgCtl1.TransparentColorMode = lvicUseTransparentColor
Not sure if the above is what you truly meant.
Regarding watermarks. They can be done a few ways & I don't intend to build a specific function for that. In fact, the control is already setup for such things
1. To use an image as a watermark, some sample code exists in the AICGlobals.MergePictureGDIplus function
2. A text watermark isn't specifically addressed but not that difficult either if one is comfortable with GDI+. Creating text with a rotated font and whatever attributes you want with GDI+ is simple. The string can be rendered in the control's PostPaint event. Or, if the control is hosting a 24/32bpp image, you can grab an hGraphics object from it's handle (AlphaImgCtl1.Picture.Handle) via the GdipGetImageGraphicsContext API and draw the GDI+ string directly to the image itself. There are other options that come to mind also.
-
2 Attachment(s)
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [19 August 2011]
Well not exactly what I was talking about.
In photography, you can shoot a subject or a product in front of a green-screen then use software to remove the background and make it transparent.
Typically the green-screen is a bright neon green and unlikely the subject will have this color of green.
However, due to shadows and lighting, the green may be a little lighter or a little darker in certain spots. Thus the software allows you to select the base color of green then has a choke value, typically between 0 and 255 that allows you to remove the base green plus shades of the green both lighter and darker.
I have attached an example photo with the green screen and one that has been removed using software to remove the green screen.
The original is of a model taken in front of a green screen in .jpg format, with the green background removed with a choke value of 55 and saved in .png format with all green removed.
As you can see there are some color variations in the green background, this is due to lighting and shadows in the studio.
I also resized the .png file so it would fit the file limits of this forum.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [19 August 2011]
VB_Rocks. though the control isn't directly set up to do what you are suggesting, it can be done outside of the control. Using your JPG source as an example, try this...
1. New form, add AlphaImgCtl and assign your JPG to that control
2. Add a command button to the form & this code
Code:
Private Declare Function GdipCreateImageAttributes Lib "gdiplus.dll" (ByRef imgAttr As Long) As Long
Private Declare Function GdipSetImageAttributesColorKeys Lib "gdiplus.dll" (ByVal mImageattr As Long, ByVal mType As Long, ByVal mEnableFlag As Long, ByVal mColorLow As Long, ByVal mColorHigh As Long) As Long
Private Declare Function GdipDisposeImageAttributes Lib "gdiplus.dll" (ByVal imgAttr As Long) As Long
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 Sub Command1_Click()
Dim hAttributes As Long, hGraphics As Long, tImg As New GDIpImage
Dim lBaseColor As Long, lLow As Long, lHigh As Long, lChannel As Long
Dim SS As SAVESTRUCT
AlphaImgCtl1.BackColor = vbWhite
AlphaImgCtl1.BackStyleOpaque = True
' set up structure for a blank 32bpp image same size as original
SS.ColorDepth = lvicConvert_TrueColor32bpp_ARGB
SS.Width = AlphaImgCtl1.Picture.Width
SS.Height = AlphaImgCtl1.Picture.Height
If SavePictureGDIplus(Nothing, tImg, , SS) = False Then Exit Sub ' create blank image
' now get a handle to its DC (hGraphics)
If GdipGetImageGraphicsContext(tImg, hGraphics) = 0& Then
' assign base color; we'll use top left corner for simple example & ensure in GDI+ color format
lBaseColor = ConvertRGBtoARGB(GetPixelGDIplus(AlphaImgCtl1.Picture, 0, 0))
' create an attributes handle
If GdipCreateImageAttributes(hAttributes) = 0& Then
' adjust the range to 1/8th above & below base color. 1/8th is +/- 32
' assign darker color to lLow & lighter color to lHigh
lLow = &HFF000000: lHigh = lLow
lChannel = (lBaseColor And &HFF&)
If lChannel > 31 Then lLow = lLow Or (lChannel - 32)
If lChannel < 224 Then lHigh = lHigh Or (lChannel + 32) Else lHigh = lHigh Or &HFF&
lChannel = (lBaseColor And &HFF00&) \ &H100&
If lChannel > 31 Then lLow = lLow Or (lChannel - 32) * &H100&
If lChannel < 224 Then lHigh = lHigh Or (lChannel + 32) * &H100& Else lHigh = lHigh Or &HFF00&
lChannel = (lBaseColor And &HFF0000) \ &H10000
If lChannel > 31 Then lLow = lLow Or (lChannel - 32) * &H10000
If lChannel < 224 Then lHigh = lHigh Or (lChannel + 32) * &H10000 Else lHigh = lHigh Or &HFF0000
' create the attributes
If GdipSetImageAttributesColorKeys(hAttributes, 1&, 1&, lLow, lHigh) = 0& Then
' draw source image to new image while applying attributes
AlphaImgCtl1.Picture.Render 0&, , , , , , , , , , hAttributes, hGraphics
Set AlphaImgCtl1.Picture = tImg
End If
GdipDisposeImageAttributes hAttributes ' clean up
End If
GdipDeleteGraphics hGraphics ' clean up
End If
End Sub
Note that the removal of green isn't 100% perfect but I suspect that is more of an issue of using a JPG as a source. JPGs lossy color compression wouldn't be ideal whereas a PNG source would be ideal IMO.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [19 August 2011]
Quote:
Originally Posted by
LaVolpe
VB_Rocks. though the control isn't directly set up to do what you are suggesting, it can be done outside of the control. Using your JPG source as an example, try this...
Note that the removal of green isn't 100% perfect but I suspect that is more of an issue of using a JPG as a source. JPGs lossy color compression wouldn't be ideal whereas a PNG source would be ideal IMO.
Look like the Green part has range e.g.RGB(118,165,110),G(Green) is always bigger than R & B. Can we do pixel by pixel replacement with White (255,255,255) if G is bigger than R and B?
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [19 August 2011]
Quote:
Originally Posted by
Jonney
Look like the Green part has range e.g.RGB(118,165,110),G(Green) is always bigger than R & B. Can we do pixel by pixel replacement with White (255,255,255) if G is bigger than R and B?
I don't think pixel by pixel tweaking is preferred due to lack of speed.
My intention was simply to show a way this can be done even though the control doesn't support it directly. I doubt a JPG would really be used as a source. Saving a JPG over an over again at less than 100% quality will degrade the image to a point where no threshhold will be satisfactory. My opinion of course - JPGs bad choice where original color data is important.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [19 August 2011]
The Alpha Imagen Control is perfect, but i think that have a litte problem, when we assign the control to download an image from the Internet, if the image is too large or the internet connection is very slow, freezes the program control until the image downloads completely.
I think this is a problem, as for example in a project where it is assigned to control download multiple images from the Internet in a form, this would not be shown until control download all ...
Regards...
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [19 August 2011]
DarkOnMatrix. Good point. I'll experiment a bit and update this posting when I know more.
There are callback options available when using APIs to grab internet data. The VB6 usercontrol can do this for us easily but is not unicode compliant & too bad; would've been very easy to provide async data.
Update #1. Very doable to allow async vs sync downloads. The issue is assignment of a GDIpImage object if async is used. The LoadPictureGDIplus function returns a GDIpImage class object containing the picture. But if async is used, the function will return immediately without any image assigned. So, how are you going to know that the image finished downloading? How are you going to be able to abort the download if you wanted to? I'm looking at those scenarios now. An immediate option is to create a new AsyncDownload class that has events. You would pass this class as the SourceImageData parameter of LoadPictureGDIplus. That class would have events that told you whether or not the image downloaded, progress, option to abort, and a few other properties. When finished downloading, then you'd be able to assign a GDIpImage class to the picture. Still thinking this over.... Nah, I think I have a clever way to get around those problems, maybe.
Update #2. Pretty dang close to a solution.
Update #3. Aug 29. Successfully created a multi-threaded asynchronous solution that works in a test executable. Need to test it a bit more & if still successful, will incorporate it into the control.
Side note & logic bugs.
1. InternetCheckConnection used to test net connection & will always fail if going thru proxy. Not reliable
2. INTERNET_OPEN_TYPE_DIRECT flag used in InternetOpen call & will cause failure if going thru proxy. Don't use that flag
3. Only 3 protocols supported: http, ftp, gopher (though I think gopher no longer supported in Vista or Win8). Will add code to support file:\\
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [19 August 2011]
Quote:
Originally Posted by
LaVolpe
Ok, that's a logic bug. I'll look into it -- gotta be something wrong with my mask processing section
Though... When looking at the icon/image in Windows Explorer or on my desktop, it is displayed like the AlphaImgCtl. If I were to load the cursor into a VB Image control, it is displayed like in your png snapshot. Interesting
Update: I will need to handle black&white cursors/icons a bit differently. I can now render the exact same image as shown in your png snapshot & VB's image control. However, in reality, 1 bit cursors/icons that use an XOR mask (as does your cursor), what you get depends on what the cursor is currently rendered over. See attached. For my control, the assumption for drawing is that cursor will be over a white background.
Attachment 85519
In above image, the top 4 boxes is the same cursor, in VB's Image Control, drawn over colored squares. The bottom image is modified code to handle B&W cursors/icon processing differently, more correct. Modified code not yet posted.
Final update. Had to handle the AND & XOR masks manually to guarantee I could draw the icons exactly correct. I'll include the patch in the next update, expected end of August.
Hi. LaVolpe.
The cursor's effect Looks very good!
Thanks very mush!
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [5 Sept 2011]
Control updated today & binary compatibility still maintained.
Fixed icon issues noted in posts 212-216 above
Added async download capability per request. See post 224 above
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [6 Sep 2011]
Hi, I want to let you know about a bug I found while using the control. The control will clip its picture when you set the rotation to -89.1. I can reproduce this every time by putting a 20*400 bitmap into it and setting the correct rotation.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [6 Sep 2011]
Quote:
Originally Posted by
cheesebrother
Hi, I want to let you know about a bug I found while using the control. The control will clip its picture when you set the rotation to -89.1. I can reproduce this every time by putting a 20*400 bitmap into it and setting the correct rotation.
Bug reports always welcomed. Can you provide more details on the control's properties? Besides the Rotation property being -89.1, what is the Aspect and AutoSize properties set to? When I pasted a simple 20x400 image into the control, no clipping appeared. Here are the properties I used
Rotation: -89.1
AutoSize: lvicMultiAngle
Aspect: lvicActualSize
Edited: I think I see what you are talking about, by changing the AutoSize property to lvicSingleAngle
Here is a temporary solution. Haven't tested it yet and need to ensure it doesn't affect other functions relying on this one:
- modCommon.GetScaledCanvasSize
- Replace these 2 lines
Code:
a = (Int(Angle) Mod 360!) + (Angle - Int(Angle))
If a < 0# Then a = a + 360#
- With these few lines
Code:
If Angle < 0! Then
a = 360! + (Angle Mod 360)
Else
a = Angle Mod 360
End If
Also note that original code wouldl break if passing a value outside of +/- 720 degree angles. I'll have to reduce angles internally to max range of +/- 359.9999 to handle all scenarios. In doing so, internally all negative values will also be converted to positive values with addition of 360 degrees. Like I said, the above 'patch' is temporary but may fix both issues.
Also the modCommon.GetScaledImageSizes function will need a similar patch
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [6 Sep 2011]
Yes, I got the problem when the control's AutoSize property was set to IvicSingleAngle and the Aspect was set to IvicActualSize. Thanks for the little fix, I tried it and it works well.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [6 Sep 2011]
Quote:
Originally Posted by
cheesebrother
Yes, I got the problem when the control's AutoSize property was set to IvicSingleAngle and the Aspect was set to IvicActualSize. Thanks for the little fix, I tried it and it works well.
Cool. I'll include the patch later this week. Trick was to do calculations based off of angles rounded up/down as needed vs. actual angle when rotating in fraction of degrees
BTW. While testing, I discovered another minor bug. If image is mirrored both vertically and horizontally, drawing it at angles other than 90 degree increments may fail (believe this to be a GDI+ bug). I do have a fix for that now also & will include it with the patch for the bug you discovered.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [5 Sept 2011]
Quote:
Originally Posted by
LaVolpe
Control updated today & binary compatibility still maintained.
Fixed icon issues noted in posts 212-216 above
Added async download capability per request. See post 224 above
When async downloading, I can't do other things... But I don't worry much because of most of people won't use much of this function.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [5 Sept 2011]
Quote:
Originally Posted by
Jonney
When async downloading, I can't do other things... But I don't worry much because of most of people won't use much of this function.
When downloading asynchronously, you will be able to do other things.
When wanting to download a URL asynchronously ensure you pass the last parameter of LoadPictureGDIplus as False. Otherwise, synchronous downloads will be performed (default behavior).
If you are passing that last parameter as False, then maybe async downloads are not supported. Test the global AsyncDownloadsEnabled property and see if it returns true or false. The control will fall back to sync downloads if that property returns false
Edited: Simple example. You'll see the caption changing while download is occurring. If async download is not enabled, msgbox displays & project unloads
1. Add AlphaImgCtl to form & a timer
2. Copy & paste this code. The image downloaded is one from post #220 above.
Code:
Option Explicit
Private Sub AlphaImgCtl1_AsyncDownloadDone(Success As Boolean, ErrorCode As Long)
Timer1.Enabled = False
If Success Then
Me.Caption = "Done. Success"
Else
Me.Caption = "Error: " & ErrorCode
End If
End Sub
Private Sub Form_Load()
Me.Show
DoEvents
If AsyncDownloadsEnabled = False Then
MsgBox "Async downloads not enabled", vbInformation
Unload Me
Exit Sub
End If
Dim sURL As String: sURL = "http://www.vbforums.com/attachment.php?attachmentid=85501&stc=1&d=1313972675"
Timer1.Interval = 100
Timer1.Enabled = True
AlphaImgCtl1.AutoSize = lvicSingleAngle
Set AlphaImgCtl1.Picture = LoadPictureGDIplus(sURL, , False)
End Sub
Private Sub Timer1_Timer()
Me.Caption = Timer
End Sub
Note: When a modal window is displayed (i.e., a message box), and your project is not compiled, it affects raised events from the control. So, no AlphaImgCtl1_AsyncDownloadDone event is triggered. When ocx is compiled, image will still be displayed while modal window is active, but event not received. When ocx is not compiled, image data is not even processed...
If within your code & you have doubt whether the image was loaded or not during the display of a modal window, you can query the GDIpImage class' AsyncDownloadStatus property after that modal window is closed. Example:
Code:
If AlphaImgCtl1.Picture.AsyncDownloadStatus = lvicAsync_Ok Then
' image assigned
ElseIf AlphaImgCtl1.Picture.AsyncDownloadStatus = lvicAsync_Invalid Then
' failure - reason would have been passed to the AsyncDownloadDone event
else
' any other value indicates download is not complete. lvicAsync_WaitingOnReply may indicate destination not responding
End If
The above will only work when the control is compiled. And here is why it doesn't work when control is not compiled
Step 1: cAsyncClient initiates downloads and is owned by a GDIpImage class
Step 2: When download done, raises event to owner GDIpImage class & passes collected image data
Step 3: GDIpImage class processes image data as needed
Step 4: If GDIpImage class is owned by AlphaImgCtl, then it raises its AsyncDownloadDone event to that control
Step 5: AlphaImgCtl raises its AsyncDownloadDone event to its host (your form) when it gets the GDIpImage event
When modal window is displayed while events are being raised...
a. When control is uncompiled, step 2 is broke due to VB blocking events and Steps 3-5 never get executed
b. When control is compiled but project is not, Step 5 is broke due to VB blocking events
c. When project is compiled, no steps are broke, no workarounds needed
I can see where this could be an issue when designing one's app & insisting on using the uncompiled control. So, I'll include a patch that will know to re-execute Step 2. That patch will be executed with a query to the AsyncDownloadStatus property, similar method as sample code above shows.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [5 Sept 2011]
Quote:
Originally Posted by
LaVolpe
When downloading asynchronously, you will be able to do other things.
When wanting to download a URL asynchronously ensure you pass the last parameter of LoadPictureGDIplus as False. Otherwise, synchronous downloads will be performed (default behavior).
If you are passing that last parameter as False, then maybe async downloads are not supported. Test the global AsyncDownloadsEnabled property and see if it returns true or false. The control will fall back to sync downloads if that property returns false
Thanks. I missed the last parameter of LoadPictureGDIplus.
How about Moving Public Property AsyncDownloadsEnabled to AlphaImgCtl? It looks weird because of this is only Public Property in AICGlobles.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [5 Sept 2011]
Quote:
Originally Posted by
Jonney
How about Moving Public Property AsyncDownloadsEnabled to AlphaImgCtl? It looks weird because of this is only Public Property in AICGlobles.
The async downloads can be done with a GDIpImage class also, not just the Alpha Image Control, i.e., ....
Code:
Private WithEvents myImage As GDIpImage
Private Sub Command1_Click()
Dim sURL As String: sURL = "http://www.vbforums.com/attachment.php?attachmentid=85501&stc=1&d=1313972675"
Set myImage = LoadPictureGDIplus(sURL, , False)
End Sub
Private Sub myImage_AsyncDownloadDone(Success As Boolean, ErrorCode As Long)
If Success Then
Me.Caption = "Done. Success"
Else
Me.Caption = "Error: " & ErrorCode
End If
End Sub
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [9 Sep 2011]
Control updated today.
- Fixes a rotation calculation error. See posts 228-231 above for more info
- Added IDE patch when using uncompiled control & async download events blocked by a modal window you have displayed from your project. See post 233 for more info
- Added 2 new global asynchronous download support functions:
:: AsyncGetDownloadStates returns count of all downloads in progress, waiting on reply, and/or queued
:: AsyncAbortDownloads aborts all active and/or queued downloads
- Added AsyncDownloadURL property to the GDIpImage class. This property available until the class' AsyncDownloadDone event is triggered and exits.
The LoadPictureGDIp.rtf file has a section that discusses async downloads. Suggest reading that too
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [9 Sep 2011]
Found minor logic bug this morning.
Where: modCommon module, CreateSourcelessHandle function
Observation: Converting EMF/WMF to bitmap can result in a single black edge on the right and/or bottom side of the image when there shouldn't be one
Cause: Rendering from single variable-type dimensions to long variable-type dimensions creates rounding error that could result in unwanted black edge(s).
Solution: Use same variable type dimensions. Will upload patch by weekend
-
1 Attachment(s)
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [19 Sep 2011]
Control updated today.
- Fixes rounding error noted in previous post #237
- Added new grayscale property enumeration item: Black and White
About the Black and White grayscale option. It uses luminance to determine pixel color. This method would render a pure black and blue image as all black due the low luminance of both black and blue. This new option uses GDI+ color matrix to generate the colors and no consideration is given to other colors in the image. It is a simple formula, controlled by GDI+, that looks like:
Color = IIF( (redWeight * red + greenWeight * green + blueWeight * blue) >= 127.5, vbWhite, vbBlack)
Note: The above algorithm/formula is common in many graphics programs, including MS Paint, affects any image consisting mostly of Blue, Green and/or Red. Various methods exist to negate this problem, including diffusion and methods similar to the one described below. Any single method for conversion to black and white probably won't be acceptable for every situation; also applies to converting/reducing image colors to 4, 16 or 256 colors
However, if saving the same blue & black image via the SavePictureGDIplus function and passing the SaveStruct.ColorDepth as black and white, luminance is not the decision factor by itself. The function used processes each pixel and the pixel's luminance, in relation to all other pixels in the image, determines pixel color (in this case, blue would become white & black remains black).
So, bottom line, you have two black and white options to choose from. One is immediate via the GrayScale property and is somewhat limited, and the other is available only when saving images using the SaveStruct.ColorDepth member. Both methods can return radically different results as one is based on fixed RGB ratio to white; while the other fixed RGB ratio between darkest & lightest colors in image. Both are completely different algorithms
Additionally, you always have the option of providing your own custom functions by accessing the pixels from the image's GDI+ handle
Within the modCommon module, you'll find the function: CreateGDIpAttributeHandle
In that function is a constant named BWLuminanceRatio which can be modified to adjust the ratio/cutoff between what will be black and what will be white. Recommend setting somewhere between .4 & .5 (smaller value more white & larger value more black). The min/max values are between 0 & 1 inclusively. Can also achieve ratio modifications thru code by adding/removing lightness from the image: LightnessPct property
Example of differences. When image is not mostly a prime color, results are similar; otherwise, can be quite different
Attachment 85888
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [20 Sep 2011]
Minor patch uploaded today.
While playing with inverting black & white images that used the LightnessPct or BlendPct properties, wasn't getting the expected results. Found logic bug in the color matrix calculations when inverting colors. Fixed now, I believe
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [20 Sep 2011]
After your last update, the TransparencyPct property is not working at all. No matter what I type, it behaves as if it was 100.