-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
k_zeon
I am looking for a small simple usercontrol that i can display a bitmap or jpeg and mask a color. do you know of any such control.
I don't know of any, but it wouldn't be hard for you or someone else to create. I am not interested in creating specific, user-defined controls.
1) TransparentBlt API can draw a bitmap to a device context while masking a color
2) You many not even need a control, consider using a picturebox
If you have any questions regarding what I just mentioned, you should ask those questions in the appropriate forum. Please do not use this thread to continue this topic. This thread is for the Alpha Image Control, not some other control or non-related topics. Thank you.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Please, can you explain how to load picture by code, without "CUSTOM" menu? Thank you.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
In the zip file you downloaded, open the LoadPictureGDIp.RTF file. There are several examples on how to load an image during run time. Also in several of the sample projects, examples exist. The function you will use is called: LoadPictureGDIplus(). During design time, the "Custom" property page is the only way.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
LaVolpe
In the zip file you downloaded, open the LoadPictureGDIp.RTF file. There are several examples on how to load an image during run time. Also in several of the sample projects, examples exist. The function you will use is called: LoadPictureGDIplus(). During design time, the "Custom" property page is the only way.
Oh, Thank you!
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Hey Lavolpe, I am a big fan and thank you so much for your gifts of knowledge!
I have a question, I would like to bring your control to the top of the zOrder but can't seem to. I am limited in knowledge of how this works. Is there a way to bring it to the front and maintain it's transparency appeal?
Just to clarify the reason: I would like to use the control as a button for a slider control or (on the form itself) so code can move it around when you left click on it and drag. So I must be able to load my image with transparency. I know I can place it on a PictureBox but the pictureBox background is square. Seeing the picbox behind the image control is undesirable.
Thank you in advance for replying
Mark
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Mark, thanx for the compliments. This is a windowless control. As such, its ZOrder will never be higher than any windowed control (i.e., button, slider, etc). The ZOrder does work in relation to other windowless controls (i.e., image, line, shape, label). Gotta think in terms of ZOrder, that this control is the same as a label, line, shape, etc.
The control cannot be made windowed and maintain its variable-level transparency. If a control only needed to have simple transparency (either 100% opaque/transparent); then it would be possible with the help of the usercontrol's MaskPicture property. But I won't modify the control for that limited purpose. There are examples of creating shaped usercontrols out & about.
Edited: Here's an idea you may be able to use. I won't discuss it further in this thread, but could address it if I saw it in the appropriate VB or graphics portion of the forums. With Win2K and above, we have the ability to create layered windows that can be shaped from any image. This layered window could be a form in your project. The image for that window can be loaded with my control, or not. By using the APIs SetLayeredWindowAttributes & UpdateLayeredWindow you can create a shaped form that appears when the drag operation begins, move the form while dragging, then unload the form when the drag stops.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Thanks... hmmm, might look into that. I did find a very suitable situation. Using your 32dbb DIB Suite from Planet Source, (which I have been using in the Frame and Button control that created) I use the image classes to create the image and rener it to the UserControl hdc. I sort of rig portions of the control in a modular rect manner like, border area, body, caption area, header, and such... THis has been a great way to deal with images and seems to be quite fast. So I just used that, stretched the image and set the corners to the closest rounded edge that is pretty close (as long as the object is not elliptical) and it works pretty well.
Here is a question that could save me a bunch of research if you would as I do not have the newer Os's? Using that older Dib Suite, should I expect any problems with Win7, Vista, or any other up-coming versions? Also, have you updated that since 2009's version on Planet Source Code?
Thanks you really are a great teacher!
Mark
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Oh, I had to chuckle, I feel like I am chatting with VB Royalty!! I can't begin to really thank you enough for the great work and your willingness to share your knowledge. Just thought I'd put that out there! Thanks!!!
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Mark, the DIB suite is fairly stable. I don't expect it should have any major issues. PSC has the most current version & it won't be updated. This control was based off of that to begin with. The major differences between the two are pretty much enhancements to this control:
- reads more formats; writes to more formats
- handles a few more rarer GDI+ bugs
- based on GDI+ images, DIB suite based on DIBs/GDI but preferred GDI+ for PNG/TIFF
- more graphical options
- the DIB suite was written to support Win95 also; this is really not but can be
- the DIB suite has 1 major advantage over this control and that regards writing PNGs. This control uses GDI+ only; whereas, the suite has code to manually create PNG with various compression algos & more options
Now back to your issue. If your image does not contain significant levels of transparency, i.e., simple transparency mostly, you can mimic what I suggested with already built-in methods, and with very good results:
1. Use a picturebox instead of my control for that floating window. Properties include AutoRedraw=True, BorderStyle=0
2. From the control/image class containing your picture, call the RegionFromImage method to return a windows region
3. Apply that region to the picturebox. Do not destroy the region in this case
Code:
' api you'll need
Private Declare Function SetWindowRgn Lib "user32.dll" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
' shaping the picturebox
:: draw the image onto the picturebox or put my control in the picturebox at 0,0 coords, then...
SetWindowRgn Picture1.hWnd, AlphaImgCtl1.Picture.RegionFromImage(), True
' Image must not be resized. If it must be resized; you'll need to save it first to the new size.
' RegionFromImage uses actual size image only
' should you need to restore picturebox
SetWindowRgn Picture1.hWnd, 0&, True
The 1st parameter of the RegionFromImage method can be adjusted to allow/remove more semi-transparent pixels. See the comments for that function. Those that are allowed will not be semitransparent; they will be converted to 100% opaque. That parameter, whatever setting, ensures variable transparency is treated as simple transparency.
Apologize a bit. Should've thought about this solution earlier; but honestly, I just forgot I added that method to the control a couple versions ago.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Hi Lavolpe!
Happy NEW YEAR for you!!!
when crashing celebration will be over ;), could you tell me how you set up the Interpolation ?
By default it's set on AUTO, but how this AUTO mode is decided ? Because in all my project I have to fix it manually, I'm guessing my kind of project is not standart
Any documentation on this ? Would help me understand, maybe I'm doing something wrong.
regards.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
The ControlProps.rtf that came with your zip should answer your question
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Ok I read....
now got 2 questions...
You're using lvicHighQualityBicubic when sizing is using.
if user is sizing 2 sides (height and width) it make sense.
However, if user size only 1 side (eitheir Height or Width),
lvicHighQualityBicubic is prone to error (I think) because in that case
(when user is sizing only 1 side) the desired effect is probably not
what lvicHighQualityBicubic is doing.
exemple: you got a 1pixel width (many pixel height) using some transparency and you want to make a BORDER of a frame...
in that case, lvicNearestNeighbor would be more appropriate.
Do you think it's worth including this "thinking" into the Auto mode decision ?
I can provide a physical exemple if my speech wasn't understandable.
question 2: Do you got something equivalent to LINE and CIRCLE ? if so, where is the doc about theses functions ? thanks.
(you're still the best, you very much inspired me in 2011 and I'm thinking about releasing my Access Database component in 2012, I just need to buil a website for it)
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
1) Maybe an example could help better describe the problem. Also include the Aspect & AutoSize properties you are using for the control.
2) GDI+ has API calls to draw a line and circle if you wish to draw them via GDI+. But you can also use the WantPrePostEvents property to draw the lines & circles yourself. The custom button sample project is an example of using that property and responding to the PrePaint & PostPaint events. You should also look at that RTF file again for more information on those events
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
1.
http://vbnetmatrix.com/download/lavo...erpolation.zip
You want to check out Middle part (Left Middle, Top Middle, Right Middle and Bottom Middle)
they are the part that are stretched. Corner are not stretched.
2. Will check that out... thanks for the info.
Would GDI+ be Faster ? for drawing line ??
because if I go to all the fuss ans wuzz to Prepaint postpaint and iT's slower, ... no need to reinvent the wheel, do I ?
what do you think ?
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
1. Ok, I see what you are talking about. No, I do not agree the logic needs to be changed. You are stretching an image that is 1 pixel in width or height. Different interpolation algorithms will render different results. The "auto" selection may not be ideal for every possible situation, but it will be for a majority of the cases. Since the control allows you to opt for different interpolations, I think that is good. Keep in mind, most people will not be using this control to stretch a 1 pixel image, they will be using it to display pictures vs. lines
2. Regarding drawing lines or circles. The Pre/PostPaint events really are not slow. When the property is set, a bitmap is created that lasts until WantPrePostEvents is set to false or the control is destroyed. Unless the image is nearly full screen, you shouldn't see any differences in speed.
Now it all depends on the quality you want for your circles and lines. A circle drawn with VB or GDI32 apis will not be alpha blended but are far easier to use. If you want smoother/blended edges for circles and diagonal lines, GDI+ may be ideal. You will still use Pre/PostPaint events, create a GDI+ DC, create a GDI+ brush and/or pen, set the interpolation for that DC, then draw a GDI+ line or circle. Browsing the graphics portion of the forum could be useful if you are not familiar with GDI+. This is one of my favorite GDI+ sites, but it is not really friendly to VB language. If I see questions regarding GDI+, I usually try to help, but won't use this thread for a GDI+ tutorial.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
"Keep in mind, most people will not be using this control to stretch a 1 pixel image"
1. Yeah I know what you mean, that's why I said "changing the logic for that particular case" maybe it wasn't phrased that way but that's what I meant. Most people will not use the control that way, it's true. But thoses who will are expecting that result, right? meaning, a simple test inside control
If (Streched X AND NOT Streched Y) or (Streched Y AND NOT Streched X) then
Interpolation =3
else
Interpolation =0 'Auto
end if
But now that I'm aware of the problematic, it's probably simpler to SET my control in the begining... I'm agreeing with you... But since people using that particular mode of stretching are probably seeking for that kind of effect it seem pertinent to insert the logic...
2. Why hDc of the control is available only at postpaint event ? can't we write directly on the control ??? I failed to find a Gdi Exemple that would allow me to paint directly on the control without hDc. I probably missed something.
and yes, my control is fullscreen, so yes I think best way would be to use GDI... or learn more about creating a png directly using your control...
thanks. I would never say enough how much your control is apreciated.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
VbNetMatrix
2. Why hDc of the control is available only at postpaint event ? can't we write directly on the control ??? I failed to find a Gdi Exemple that would allow me to paint directly on the control without hDc. I probably missed something..
The control is windowless, it gets it DC from its container only during the control's Paint event. During the paint event, it then sends you the DC thru the Pre/PostPaint events if requested. But it really isn't the actual DC because that DC is clipped and offset; so a temporary DC is sent instead that will cause problems if you draw outside of the actual control which is possible if the real DC was sent. There is no DC to draw on directly.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
ok, so if I understand correctly from previous post...
1. the control is windowless because otherwise it wouldn'T allow full transparency
2. a windowless control obviously doesn't have a direct DC
3. if using the dc from pre/post paint event, I draw OUTSIDE the control, it can be dangerous ? like crashing issue ?
4. is there any way to temporary "CreateDc" using GDIpImage and SAVESTRUCT ? (I'm probably just half stupid)
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
1) Yes regarding variable translucency. If GIF-like transparency, no blending, then that can be done a few different ways. But that would remove semi-transparency effects
2) No, it can. But I chose not to for 2 reasons: a) uses less resources, b) I'd still have to get VB to paint the container's bkg to the DC
3) No, crashing is not the issue. When VB sends the control a DC, it is clipped and offset so that 0,0 coords of the DC line up with the control and the width/height of the DC is the 'dirty' area to be painted by the control. The DC is actually the entire container. Now if someone were to mess with the DC and remove or adjust the clipping region contained in it, the entire container becomes the drawing area instead of just the area occupied by the control. Also, it would be possible to inadvertently corrupt the DC. This is the reason I do not send users the actual DC, but I send them an offscreen DC which I then paint to the container
4) Don't understand. Maybe you can describe what you are trying to do that the control isn't allowing you to do
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
2. b) ?? I didn't understood what you meant about the Vb Paint.
3. clever... I like it... it's like when I use a control to Subclass, if it crash in the Subclass only my control crash and not the full app. ;) and I can still Debug...
4.) I need to use direct drawing function like MoveToEx and LineTo (Api)
wich I failed to perform... So I probably misunderstood you properly when you said I could use Gdi+ function... I looked up the web site you gave, but I have no idea where to start my search so unless I read all the 563 pages bible on GDI (Wich is very interesting by the way) I don't know where to look or even what I'm looking for...
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...
one thing that could help was if I had an already prepared Array of pixel like a BitBmp map I could use and only change the part I need to... wich is adding some line...
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...
one possible solution if I can't find another way would be to limit my program to a few different size, and prepare semi transparent background image that I would just load and then make the change (still need to draw line in it) on the fly...
any thought, suggestion, protocol and documentation would be great. You are still the one knowing this control more then anybody...
thanks for all..
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Hi LaVolpe! You are the best programmer I ve ever seen in my life! Thank you and Happy New Year! I have a problem, can you help me, please?
So, I have a module:
vb Code:
Public Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias "ExtractAssociatedIconA" (ByVal hInst As Long, ByVal lpIconPath As String, lpiIcon As Long) As Long
Public Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Public Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
and Form Code:
vb Code:
Private Sub Command1_Click()
CommonDialog1.ShowOpen
Dim sPath As String, hIcon As Long, nIcon As Long
sPath = CommonDialog1.FileName
hIcon = ExtractAssociatedIcon(App.hInstance, sPath, nIcon)
DrawIcon Picture1.hdc, 0&, 0&, hIcon
AlphaImgCtl1.PaintImageAsDrawnToHDC (Picture1.hdc)
DestroyIcon hIcon
End Sub
So, what is wrong in it? Or how can I paint associated icon to AlphaImgCtl1(hdc)? Please, can you help me to correct it? Thanks!
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
canon1995
Or how can I paint associated icon to AlphaImgCtl1(hdc)? Please, can you help me to correct it? Thanks!
Set AlphaImgCtl1.Picture = LoadPictureGDIplus(hIcon)
Edited: P.S. I've already built a routine into the control that will load associated icons. It will be available in the next update which is waiting on DPI awareness code I haven't completed yet
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
LaVolpe
Set AlphaImgCtl1.Picture = LoadPictureGDIplus(hIcon)
Edited: P.S. I've already built a routine into the control that will load associated icons. It will be available in the next update which is waiting on DPI awareness code I haven't completed yet
Understood. Thank you.
Oh, it will be great!
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
canon1995:
I don'T understand why you're using a picturebox ?? You want to Erase the TRANSPARENCY of the Icon ?? You don't need a Picturebox unless that's what you want to do...
see LoadPictureGDIp.rtf, look for:
"Binaries. Binaries such as exe, dll and ocx can contain bitmaps, icons, cursors"
and also check for "Section IV"
can you tell us more what you're trying to do ?
might be easier to extract the icon in ICO file and then Load them from Lavolpe component...
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
sorry Lavolpe, there were no answer when I started writing...
if you got time, can you help me with my last question ?
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Lavolpe:
concerning canon1995 issue, while trying to write him an exemple code, I ran into something strange with an EXE file. If you want to check it out for your next to come
quote:
"built a routine into the control that will load associated icons"
http://vbnetmatrix.com/download/lavolpe/Strange.zip
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
VbNetMatrix
canon1995:
I don'T understand why you're using a picturebox ?? You want to Erase the TRANSPARENCY of the Icon ?? You don't need a Picturebox unless that's what you want to do...
see LoadPictureGDIp.rtf, look for:
"Binaries. Binaries such as exe, dll and ocx can contain bitmaps, icons, cursors"
and also check for "Section IV"
can you tell us more what you're trying to do ?
might be easier to extract the icon in ICO file and then Load them from Lavolpe component...
I dont want to Erase Transparency. This code works to get icon from file to Picture1. It was posible only to get icon to Picture.hdc or Form.hdc, but now it's posible to load it to Lavolpe control.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
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
Quote:
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
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
canon1995
I dont want to Erase Transparency. This code works to get icon from file to Picture1. It was posible only to get icon to Picture.hdc or Form.hdc, but now it's posible to load it to Lavolpe control.
well... picturebox DOESN'T support transparency... that's why we need Lavolpe excellent OCX. If you load ANYTHING inside picture box, you're loosing the transparency. Vb6 Doesn't support it. If you would copy any picture box content to Lavolpe component, you'll never get transparency back.
that's what I meant. Sorry for the confusion.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Lavolpe:
part 1: Excellent, I'll try that...
part 2: no, no... what I meant was that since the Screen size was variable, I would prefer not to use external png file to load because it mean my program might be useless in futur if screen resolution go haywire! (lol) I'm well aware of how to make setting size issue and scalemode and other setting to get back the size... and yes my form is full screen, no border and TopMost
thanks for everything... I'll test the code... and about the warning, I'm taking note of it, but I asked it here because I thought there would be a simple way to do a line in your control using an internal function I didn'T know about... Since you know the component very well, it seem obvious for me to ask if there were such internal function as drawing line... do You think it's worth exploring to add it in the future ? (Since internally you already got the DC ?) Or at least, tell me where to look inside the component to get the DC and I'll try to modify my version of it to make some test ?
thank for everything.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
rofl...
I was using:
Private Type POINTAPI
x As Long
y As Long
End Type
Private Const PS_SOLID = 0
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
lngPenHandle = CreatePen(PS_SOLID, 1, vbRed)
lngRetValue = SelectObject(picGrid.hdc, lngPenHandle)
and MoveToEx and LineTo function...
I didn'T know there where GdiEquivalent... that's all I was missing. Thanks for bringing the light Lavolpe, you're the best.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
VbNetMatrix
... do You think it's worth exploring to add it in the future ? (Since internally you already got the DC ?) Or at least, tell me where to look inside the component to get the DC and I'll try to modify my version of it to make some test ?
I am against modifying the control to make it become a graphics application. It's purpose has always been to display images like an image control, not to act as a Paint application. However, since I foreseen questions like this, I have exposed everything one needs, either directly or indirectly, to draw to the control or the image. This must be done outside the control by the user -- just my rule. As mentioned in post #3, I will not support modifying the control for specific customer needs; nor offer sample code to do so. If you do decide to tweak the control; I will not offer any support in fixing it... you break it, you fix it. Again, just my rules
As mentioned before, you can use Pre/PostPaint events to draw directly to the control since that event passes you a typical hDC that can be used with MoveToEx, BitBlt, LineTo, etc. Any drawing you do is on the control, not the image. You can even use GDI+ APIs to draw blended shapes to the control. That does require you to create a GDI+ hGraphics object from the passed hDC from those events: GdipCreateFromHDC
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
canon1995
Understood. Thank you.
Are you good to go now? Didn't want to lose you in the last volley of replies
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
ok, Here something odd...
'Assign the image to the control & resize the control
Set AlphaImgCtl9 = tGDIpImage
AlphaImgCtl9.AutoSize = lvicSingleAngle
AlphaImgCtl9 size is Changed properly, but property:
AlphaImgCtl9.Width and AlphaImgCtl9.Height
are the OLD size...
normal or not ?
I replaced it with:
aImg.Width = typGDIpImage.Width
aImg.Height = typGDIpImage.Height
Set aImg.Picture = typGDIpImage
2.:
Quote "As mentioned before, you can use Pre/PostPaint events"
how do I fire them ? and what if I need to fire them BEFORE the control is shown ?
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
VbNetMatrix
1. ok, Here something odd...
2. Quote "As mentioned before, you can use Pre/PostPaint events"
1) the control's .Width & .Height values are in the control's container's scalemode. The .ScaleWidth & .ScaleHeight properties are always in pixels and is same as AlphaImgCtl9.Picture.Width & .Height when control is same size as the its image. The typGDIpImage .Width & .Height properties are the actual image's width/height in pixels.
2) Set the WantPrePostEvents property to true. You then have to respond to the PrePaint and/or PostPaint events of the control to draw onto the control. The custom button sample project has an example and the ControlGDIp.rtf file has some documentation. PrePaint fires before image is drawn to control; PostPaint fires after image is drawn but before control is visibly updated
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
1. ok, and in that case, what the height and width represent ?
2. I turned WantPrePostEvents to True, but Prepost doesn't fire... that's why I asked "How do I fire them"
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
LaVolpe
Are you good to go now? Didn't want to lose you in the last volley of replies
All is OK! I understood all.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
VbNetMatrix
1. ok, and in that case, what the height and width represent ?
2. I turned WantPrePostEvents to True, but Prepost doesn't fire... that's why I asked "How do I fire them"
1) depends on the context
AlphaImgCtl1.Width is the width of the control in its container's scalemode
AlphaImgCtl1.ScaleWidth is the width of the control in pixels less border if used
AlphaImgCtl1.Picture.Width is the control's image's width in pixels
2) From that sample you sent me, pick one of the AlphaImgCtrl6 controls; doesn't matter which index. Change WantPrePostEvents to true. Copy and paste this code & you'll see it fires. Look at ControlPropsGDIp.rtf for more info
Code:
Private Sub AlphaImgCtl6_PostPaint(Index As Integer, hDC As Long, Left As Long, TOp As Long, Width As Long, Height As Long, HitTestRgn As Long)
Debug.Print "postpaint for index "; Index
End Sub
Private Sub AlphaImgCtl6_PrePaint(Index As Integer, hDC As Long, Left As Long, TOp As Long, Width As Long, Height As Long, HitTestRgn As Long, Cancel As Boolean)
Debug.Print "prepaint for index "; Index
End Sub
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
1. thanks a lot... crystal clear now... but that doesn'T explain how the container can be smaller then the picture...
2. You're talking about the Icon Bug file I sent you in regard to Canon1995 ?
I don't have anymore the other bug file... oh... the square box thing... I got this one
added: That kind of strange, it wasn't firing on my other project... :(
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
VbNetMatrix
1. thanks a lot... crystal clear now... but that doesn'T explain how the container can be smaller then the picture...
2. You're talking about the Icon Bug file I sent you in regard to Canon1995 ?
I don't have anymore the other bug file... oh... the square box thing... I got this one
added: That kind of strange, it wasn't firing on my other project... :(
1) Sure it can. If you put at 1024x1024 control on a 32x32 container, the control will be bigger than the container, clipped by the container, but bigger. Likewise, an image can be bigger that the control. If not scaled/stretched, it will be clipped
2) No. I was talking about your sample project regarding the Auto-Interpolation issue
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
2. ok got it... made it work... doesn't know what was wrong in my other try though... will check that...
1. Maybe we have different terminology...
for me:
Container: the OCX object that Hold the image.
Control: the image itself I guess in the case of the Lavolpe OCX.
If you put a 1024x1024 control on a 32x32 container, you'll be enable to see only 32x32 of that control, right ? because the rest will be clipped inside...
Now, this is not what is happening with your control.
I got a 1024x1024 image loaded and I see it ALL (Full screen) but when I check the ocx (container) width, I got 512
wich doesn't quite add up to my reality because if the container was "really" smaller, I should only be enable to see as big as the container ?
Where do I not understand ?
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
The control's container is the object where the ocx is placed into: form, picturebox, frame, etc
The control is the ocx
The value of the ocx/control's width is decided by the container's scalemode. If it is returning 512 and you are absolutely positive you can see the entire 1024x1024 image, then I assume your container is using a custom scalemode: Debug.Print Me.ScaleMode (replace Me with whatever the controls' container is)
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
I use Pixel (3) scalemode... I always do in every graphics programs, it's more practical... want my code ?
(oh and YES, I use the "original" Lavolpe, not modified, not broken... just in case)
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
VbNetMatrix
I use Pixel (3) scalemode... I always do in every graphics programs, it's more practical...
Then I have know idea why AlphaImgCtlx.Width would return 512 in your case. You'd have to troubleshoot that. It has nothing to do with the control. A control's .Width property is provided by VB.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
ok, I found the reason to my Size Bug... it was in the code... but I'm not sure it's supposed to react that way...
Part1:
'aImg (Lavolpe component) on the form is 400x400 when form is loaded...
'From Post #328
' sample of creating a blank image
Dim typSaveStruct As SAVESTRUCT
Dim typGDIpImage As GDIpImage
'Create a blank image of desired size & color depth
typSaveStruct.Width = 1024
typSaveStruct.Height = 768
typSaveStruct.ColorDepth = lvicConvert_TrueColor32bpp_ARGB
Set typGDIpImage = New GDIpImage
SavePictureGDIplus Nothing, typGDIpImage, , typSaveStruct
This work:
Part2a
'Assign the image to the control & resize the control
Set aImg = typGDIpImage
aImg.AutoSize = lvicSingleAngle
debug.print aImg.Width '=1024
debug.print aImg.Height '=768
This Strange:
Part2b
'Assign the image to the control & resize the control
Set aImg.Picture = typGDIpImage
aImg.AutoSize = lvicSingleAngle
debug.print aImg.Width '= 400
debug.print aImg.Height '= 400
I know that the default property is Picture, but why specifying picture DIRECTLY is causing a problem in the refresh of the container property ?
is it by design ?
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
LaVolpe, Sorry, but I have a problem again. It concerns my previous post(321). I got icon in AlphaImgCtl1, but now I need to save it to file, but I can't understand how. Sure I have read "SavePictureGDIplus" manual. And is it posible to load it again to control after programm reload automaticaly?
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
canon1995
LaVolpe, Sorry, but I have a problem again. It concerns my previous post(321). I got icon in AlphaImgCtl1, but now I need to save it to file, but I can't understand how. Sure I have read "SavePictureGDIplus" manual. And is it posible to load it again to control after programm reload automaticaly?
If you just want to save the picture to file in the same image format (no format conversions):
SavePictureGDIplus AlphaImgCtl1.Picture, "C:\MyImages\filename.ext", lvicSaveAsCurrentFormat
If you want the image to be part of your program, you will want to do 1 of these 2 things:
1) Add it to an Alpha Image Control during design time via the Custom property page
2) Add it to a resource file and use LoadPictureGDIplus during form_load. The LoadPictureGDIp.rtf has examples of loading image from resource files
If I am not understanding the question correctly, let me know
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
VbNetMatrix
ok, I found the reason to my Size Bug...
This Strange:
Part2b
'Assign the image to the control & resize the control
Set aImg.Picture = typGDIpImage
aImg.AutoSize = lvicSingleAngle
debug.print aImg.Width '= 400
debug.print aImg.Height '= 400
I cannot reproduce the problem. My results are always 1024,768
If Aspect property is not ActualSize then aImg.AutoSize = lvicSingleAngle has no effect because the image is being scaled or stretched to the current control dimensions. Suggest ensuring Aspect & AutoSize properties are reset back to zero before loading a new image into the control; then set those properties as needed?
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
LaVolpe
If you just want to save the picture to file in the same image format (no format conversions):
SavePictureGDIplus AlphaImgCtl1.Picture, "C:\MyImages\filename.ext", lvicSaveAsCurrentFormat
If you want the image to be part of your program, you will want to do 1 of these 2 things:
1) Add it to an Alpha Image Control during design time via the Custom property page
2) Add it to a resource file and use LoadPictureGDIplus during form_load. The LoadPictureGDIp.rtf has examples of loading image from resource files
If I am not understanding the question correctly, let me know
Perfect! I got it. Thank you!
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
canon1995
Perfect! I got it. Thank you!
Until I post an update with the associated icon routines which would allow you to select such an icon during design view, here's yet another option
1) Build simple test project & include Alpha Image Control (AIC) & button
2) In button click event, extract icon, add it to AIC & save it to file
3) In your real project, now you can load it, from the file, within the custom property page
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
LaVolpe
Until I post an update with the associated icon routines which would allow you to select such an icon during design view, here's yet another option
1) Build simple test project & include Alpha Image Control (AIC) & button
2) In button click event, extract icon, add it to AIC & save it to file
3) In your real project, now you can load it, from the file, within the custom property page
I'am doing it the same way. I don't need to load it via custom menu because this icon often changes. I'am waiting for update.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
canon1995
...but now I need to save it to file, but I can't understand how. Sure I have read "SavePictureGDIplus" manual.
Hmmm, just looked at that rtf file. You know, I don't explain anywhere in there how to simply save an image to file or array if you are not going to use any of the image modification/conversion options. Will have to remedy that. Thanx
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
LaVolpe
Hmmm, just looked at that rtf file. You know, I don't explain anywhere in there how to simply save an image to file or array if you are not going to use any of the image modification/conversion options. Will have to remedy that. Thanx
Thats why i can't to understand Save function. So, I'am waiting for next update. Thanks you too.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
alhough not explained per say (I had to dig up a lot) you made an excellent exemple of all saving and conversion in your sample program called: prjSaveAs.vbp
about post 348: I think I found what cause the problem with the size...
I changed the size of the picture while the form was hidden and the size of the component change only after the refresh (Show) of the picture...
is that normal behavior ?
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Quote:
Originally Posted by
VbNetMatrix
about post 348: I think I found what cause the problem with the size...
I changed the size of the picture while the form was hidden and the size of the component change only after the refresh (Show) of the picture...
is that normal behavior ?
Maybe :) ... a bit of tap dancing
The Show event of the usercontrol activates when it is first shown. Well on hidden forms or if the control's visible property is false, then that event won't trigger. The sizing routines of the control occur in the Shown event. I can see where this could be a problem for controls on hidden forms or controls that remain visible=false for whatever reasons. I will modify the control to account for this case, but it will not be automatic. If anyone needs to reference properties of a hidden/invisible control after loading an image, they should load the image, set whatever properties are desired then call the control's .Refresh method.
The Refresh method will need to be modified. Here it is. Just copy & paste to replace. Will be in next update
Code:
... removed. May be a VB bug & will be auto-corrected via code. See post 370 next page for more
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
The modification doesn't seem to work...
here a project exemple...
http://vbnetmatrix.com//download/lav...apDanceBug.zip
also, You didn'T gave confirmation you saw that strange thing on ICON extraction, (just want to know if I can erase the file)
http://vbnetmatrix.com//download/lavolpe/Strange.zip
thanks for everything
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Just download both files. Will get back to you after I've had a chance to review them
Edited; That was easy. Simply call aImg.Refresh after you are done setting properties and before you read the properties:
Code:
....
aImg.AutoSize = lvicSingleAngle
aImg.Refresh ' view the changes <<<< moved this here
If (aImg.Width = 400) Then
Stop 'Not supposed to happen...
End If
I'll look at the other project today or tomorrow... Done.
What is the issue? Are you wondering why there are like several images in a single image? If so, that is not uncommon. What you are looking at is a bitmap that contains several mini-images. The app loads that resource then BitBlt's the image from it that it wants to be used for whatever purposes; probably a toolbar. The shell32.dll does something very similar too. As I said, this is not uncommon. If you tweak your code a bit, you'll see what I'm talking about. The difference with the shell32.dll is that it stored a 32bpp alpha bitmap whereas your depends.exe did not.
Code:
Private Sub Form_Load()
Me.ScaleMode = 3 'Pixel
'LoadIconX App.Path & "\depends.exe"
LoadIconX "C:\windows\system32\shell32.dll"
End Sub
Public Sub LoadIconX(ByVal pstrFileName As String)
Dim objGDIpImage As GDIpImage
' Set objGDIpImage = New GDIpImage
Set objGDIpImage = LoadPictureGDIplus(pstrFileName, True)
objGDIpImage.ImageIndex = 20 ' this is the specific one I was talking about
AlphaImgCtl1.Width = objGDIpImage.Width
AlphaImgCtl1.Height = objGDIpImage.Height
Set AlphaImgCtl1.Picture = objGDIpImage
End Sub
P.S. Please do remove that sample project since it contains an executable & forum policy prohibits that.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
project2:
sorry for the Exe, it was the only way to show you that extract icon on an Exe can something lead to confusion...
I was not wondering why there was several icon...
You mentionned in a post early that you were working on extracting icon function, I was merely showing you an exe that could cause conflict in that area if you were not expecting that kind of result...
Maybe I overthought here, I just wanted to be usefull so you take that particular case into consideration.
download files are removed.
Project1:
Code:
I have trouble following your logic in the last modification:
If (m_RenderFlags And render_Shown) = 0& Then
Call sptSetUserMode
m_RenderFlags = m_RenderFlags Or render_Shown
Call sptGetScaledSizes(False)
m_RenderFlags = (m_RenderFlags And Not render_Shown)
Else
'Previous Code was here
m_RenderFlags = (m_RenderFlags And Not render_NoRedraw)
Call sptGetScaledSizes(False)
UserControl.Refresh
End If
could you explain a bit ? thanks
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Long story short: the m_RenderFlags variable can contain up to 30 values. While the control is in use, several of those values get turned on or off depending on situations within the control. Those values are simply flags. The sptGetScaledSizes function will not resize the control unless the render_Shown flag is turned on. That flag is only turned on during the control's first paint event after the show event fires.
So, what that code is doing is testing to see if that render_Shown flag is set or not. If not, then we set it so the sptGetScaledSizes function will not fail. Then we unset the flag because it isn't really suppose to be set yet per my code's logic. There are a lot of other things going on in that sptGetScaledSizes function & that function can call other functions.
Basically, the Refresh method now knows whether it was called before the show event occurs or not. And fixes the sizing issue if the show event did not occur. But the Refresh method needs to be called by you. This is not unusual. Many controls you find, for whatever reasons, do not necessarily apply the changes you make to them until after you Refresh that control.
And regarding that depends.exe app. That isn't an issue. Extracting an icon from the resources of an executable is not necessarily the same result as extracting the associated icon for that exe.
-
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Excellent information, Thank, that's what I was looking for...
raise a second question though...
if I understood properly the explanation you gave, in my case, the only thing the Refresh will do is Force a Resize...
so code like
Code:
aImgGrid.Width = typGDIpImage.Width
aImgGrid.Height = typGDIpImage.Height
Set aImgGrid.Picture = typGDIpImage
instead of
Code:
Set aImgGrid.Picture = typGDIpImage
aImgGrid.AutoSize = lvicSingleAngle
aImgGrid.Refresh
Would have the same effect ?