-
Jan 2nd, 2012, 06:32 AM
#321
New Member
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!
Last edited by canon1995; Jan 2nd, 2012 at 07:15 AM.
-
Jan 2nd, 2012, 11:15 AM
#322
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
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
Last edited by LaVolpe; Jan 2nd, 2012 at 11:22 AM.
-
Jan 2nd, 2012, 11:36 AM
#323
New Member
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
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!
-
Jan 2nd, 2012, 11:53 AM
#324
Addicted Member
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...
-
Jan 2nd, 2012, 11:55 AM
#325
Addicted Member
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 ?
-
Jan 2nd, 2012, 12:03 PM
#326
Addicted Member
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
-
Jan 2nd, 2012, 12:26 PM
#327
New Member
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
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.
-
Jan 2nd, 2012, 12:34 PM
#328
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
Originally Posted by VbNetMatrix
I need to draw a New GdiIpImage that is 1024x768 (screen size) in size
with transparency. So unless I figure out how to perform that many SetPixelGDIplus in less then 3 second, I need to find another way...
Drawing onto the full-size image is possible but requires a bit more forethought. You can get a DC related to the actual image and draw directly to it. That does permanently change the image. Here's some sample code that will create a full screen image and draw a diagonal, blended, line from top left to bottom right. For future questions about these GDI+ APIs and other ones you may be interested in, you should post those questions in the VB or graphics portion of the forum. This is because you are now entering a different topic area that isn't directly related to the control.
You'll need a DC to the control's image after you create the full screen image. Then you'd set the interpolation on that DC and draw your lines & circles
Code:
' apis for this exercise
Private Declare Function GdipGetImageGraphicsContext Lib "GdiPlus.dll" (ByVal pImage As Long, ByRef graphics As Long) As Long
Private Declare Function GdipDeleteGraphics Lib "GdiPlus.dll" (ByVal mGraphics As Long) As Long
Private Declare Function GdipDrawLineI Lib "GdiPlus.dll" (ByVal graphics As Long, ByVal pen As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long
Private Declare Function GdipCreatePen1 Lib "GdiPlus.dll" (ByVal pColor As Long, ByVal nWidth As Single, ByVal unit As Long, ByRef pen As Long) As Long
Private Declare Function GdipDeletePen Lib "GdiPlus.dll" (ByVal pen As Long) As Long
Private Declare Function GdipSetInterpolationMode Lib "GdiPlus.dll" (ByVal hGraphics As Long, ByVal Interpolation As Long) As Long
Private Const UnitPixel As Long = 2&
' sample of creating a blank image
Dim ss As SAVESTRUCT, tGDIpImage As GDIpImage
' change ss.Width/Height as needed
ss.Width = Screen.Width \ Screen.TwipsPerPixelX
ss.Height = Screen.Height \ Screen.TwipsPerPixelY
ss.ColorDepth = lvicConvert_TrueColor32bpp_ARGB
' create a blank image of desired size & color depth
Set tGDIpImage = New GDIpImage
SavePictureGDIplus Nothing, tGDIpImage, , ss
' assign the image to the control & resize the control
Set AlphaImgCtl9 = tGDIpImage
AlphaImgCtl9.AutoSize = lvicSingleAngle
' sample of drawing a line on the actual image
Dim hGraphics As Long, hPen As Long
' get the DC for the image
If GdipGetImageGraphicsContext(AlphaImgCtl9.Picture.Handle, hGraphics) = 0 Then ' ok
' create a blue pen, 2 pixels in width
If GdipCreatePen1(ConvertRGBtoARGB(vbBlue), 2, UnitPixel, hPen) = 0 Then ' ok
' set interpolation mode.
' Note that if using my RenderInterpolation enum, you need to add 2.
' DO NOT use .lvicAutoInterpolate
GdipSetInterpolationMode hGraphics, RenderInterpolation.lvicHighQualityBicubic + 2
' draw the line & clean up
GdipDrawLineI hGraphics, hPen, 0, 0, AlphaImgCtl9.ScaleWidth - 1, AlphaImgCtl9.ScaleHeight - 1
GdipDeletePen hPen
End If
GdipDeleteGraphics hGraphics
End If
AlphaImgCtl9.Refresh ' view the changes
Originally Posted by VbNetMatrix
now the problem lie in the fact that I don't know the Size Screen of all client and it's possible it would not always be 1024x768...
That's easy enough:
screenCx = Screen.Width\Screen.TwipsPerPixelX
screenCy = Screen.Height\Screen.TwipsPerPixelY
Note that you probably won't get full screen anyway. Any taskbars take away from the available screen size. If your form is not borderless, then your form's borders, titlebar, menubar take size away too. If you want to get the total available size your maximized form will display, use this instead. Form's scalemode must be twips else use ScaleX/ScaleY as needed
maxWidth = Me.ScaleWidth\Screen.TwipsPerPixelX
maxHeight = Me.ScaleHeight\Screen.TwipsPerPixelY
Last edited by LaVolpe; Jan 2nd, 2012 at 12:49 PM.
-
Jan 2nd, 2012, 12:45 PM
#329
Addicted Member
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
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.
-
Jan 2nd, 2012, 12:54 PM
#330
Addicted Member
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.
-
Jan 2nd, 2012, 12:59 PM
#331
Addicted Member
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.
-
Jan 2nd, 2012, 01:04 PM
#332
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
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
Last edited by LaVolpe; Jan 2nd, 2012 at 01:08 PM.
-
Jan 2nd, 2012, 01:26 PM
#333
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
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
-
Jan 2nd, 2012, 01:37 PM
#334
Addicted Member
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 ?
-
Jan 2nd, 2012, 01:45 PM
#335
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
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
-
Jan 2nd, 2012, 01:53 PM
#336
Addicted Member
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"
-
Jan 2nd, 2012, 01:56 PM
#337
New Member
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
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.
-
Jan 2nd, 2012, 03:00 PM
#338
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
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
-
Jan 2nd, 2012, 03:44 PM
#339
Addicted Member
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...
Last edited by VbNetMatrix; Jan 2nd, 2012 at 03:52 PM.
-
Jan 2nd, 2012, 04:04 PM
#340
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
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
-
Jan 2nd, 2012, 04:47 PM
#341
Addicted Member
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 ?
-
Jan 2nd, 2012, 05:02 PM
#342
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)
-
Jan 2nd, 2012, 09:39 PM
#343
Addicted Member
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)
-
Jan 2nd, 2012, 09:56 PM
#344
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
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.
-
Jan 2nd, 2012, 11:59 PM
#345
Addicted Member
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 ?
-
Jan 3rd, 2012, 07:20 AM
#346
New Member
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?
Last edited by canon1995; Jan 3rd, 2012 at 07:26 AM.
-
Jan 3rd, 2012, 08:48 AM
#347
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
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
-
Jan 3rd, 2012, 08:55 AM
#348
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
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?
Last edited by LaVolpe; Jan 3rd, 2012 at 09:07 AM.
-
Jan 3rd, 2012, 09:30 AM
#349
New Member
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
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!
-
Jan 3rd, 2012, 09:34 AM
#350
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
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
-
Jan 3rd, 2012, 09:50 AM
#351
New Member
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
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.
-
Jan 3rd, 2012, 10:00 AM
#352
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
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
-
Jan 3rd, 2012, 10:26 AM
#353
New Member
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
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.
-
Jan 3rd, 2012, 12:51 PM
#354
Addicted Member
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 ?
-
Jan 3rd, 2012, 02:32 PM
#355
Re: [vb6]Alpha Image Control (PNG, AniGIFs, TIFF, & more) [26 Nov 2011]
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
Last edited by LaVolpe; Jan 5th, 2012 at 09:35 AM.
-
Jan 3rd, 2012, 05:55 PM
#356
Addicted Member
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
-
Jan 3rd, 2012, 06:41 PM
#357
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.
Last edited by LaVolpe; Jan 3rd, 2012 at 07:13 PM.
-
Jan 3rd, 2012, 08:42 PM
#358
Addicted Member
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
-
Jan 3rd, 2012, 09:36 PM
#359
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.
-
Jan 3rd, 2012, 09:57 PM
#360
Addicted Member
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 ?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|