Can Alpha Image Control be used to draw a 8bit transparency image in a transparent form? I'm failing to do it.
I can make the form transparent, but alpha image controls mix the backcolor of the form instead of transparency.
Attachment 171411
Printable View
Can Alpha Image Control be used to draw a 8bit transparency image in a transparent form? I'm failing to do it.
I can make the form transparent, but alpha image controls mix the backcolor of the form instead of transparency.
Attachment 171411
Version 3 is on my list of things to do. Not done yet and don't know when it will get done.
[QUOTE=LaVolpe;4073183]Regarding cropping: Well, you can already do that with existing methods:
Edited yet again. The above code works extremely well if Aspect is actual size; otherwise, it doesn't because resizing the control changes the dimensions of rendered image which means it isn't really designed to crop while stretched or scaled without a lot of extra calculations from you, including drawing in the PrePaint event (or saving the image to a new GDIpImage object with scaled dimensions ahead of time)Code:Option Explicit
' in this example, the control's parent scalemode is pixels
Private Sub AlphaImgCtl1_Click()
CropImage AlphaImgCtl1, 30, 30, 100, 100
End Sub
Private Sub CropImage(theImage As AlphaImgCtl, X As Long, Y As Long, _
Width As Long, Height As Long)
' the AlignCenter property should already be set to False for better runtime visual change
With theImage
.SetRedraw = False
.AlignCenter = False
.AutoSize = lvicNoAutoSize
' ensure X, Y are pixel scalemode
.SetOffsets -X, -Y
' ensure X, Y, Width, Height are appropriate container scalemode
.Move .Left + X, .Top + Y, Width, Height
.SetRedraw = True
End With
End Sub
*********************************************************
Hi Lavolpe I just now try this code for cropping function. It's work very well.
but I have an issue.
:CropImage AlphaImgCtl1, 30, 30, 100, 100:
Now I altered the values to this
CropImage AlphaImgCtl1, 0, 0, AlphaImgCtl1.Picture.Width , AlphaImgCtl1.Picture.Height
After result Image Crop height size is Ok but Image width size is crop to my desktop screen resolution width only.
Selected Image width size is 1800 pixels. After result it crop to my desktop screen resolution (1366) width only
Please help me how to crop an image actual width.
Thanks Advance.:wave:
Replied to your PM. Basically, there are some restrictions made within the code to prevent the AIC from being sized larger than a full screen. The restrictions can be found, and commented out, in sptGetScaledSizes
Dear LaVolpe.
A photo when opened in image editing programs is displayed correctly, however when loaded in Alpha Image Control it is automatically rotated counterclockwise.
Attachment 175171
Attachment 175173
The image is 3456x4608 72 dpi jpg photo from a smartphone.
Any guess about what is happening?
Thank you in advance!
Thank you very much shagratt!!!
I think there is a bug in the SetClipRect method:
'/// sets optional clipping on the rendered image. Border usage is exempt from clipping
Public Sub SetClipRect(ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long, Optional ByVal Refresh As Boolean = True)
Attribute SetClipRect.VB_Description = "Method clips the control's graphic output"
' pass width and/or height as zero to remove clipping rectangle
If (Width Or Height) = 0 Then
SetRect m_ClipRect, 0&, 0&, 0&, 0&
If Refresh Then UserControl.Refresh
ElseIf (Width > 0& And Height > 0&) Then
SetRect m_ClipRect, X, Y, Width + X, Height + X
If Refresh Then UserControl.Refresh
End If
End Sub
It should be Height + Y instead of Height + X
@Zeilo. Yes, should be Hieght + Y
Regarding JPG. To address the camera orientation, the information should exist in the JPG's metadata and if it does exist, auto-orientation can be applied to correct it. Here's how to adapt the AIC for those types of JPGs.
1. In modCommon LoadImage function, find this line: Case lvicPicTypeJPEG
Immediately after that line, insert this: Call pvAutoOrientateJPG(cImageData)
2. At the bottom of modCommon, add the new pvAutoOrientateJPG method
3. Add this new API towards top of modCommonCode:Private Sub pvAutoOrientateJPG(cImageData As cGDIpMultiImage)
Dim lSize As Long, lValue As Long
Dim arrData() As Byte, lOrient As Long
Dim tImageData As cGDIpMultiImage, hBmp As Long
Const PropertyTagOrientation As Long = &H112&
GdipGetPropertyItemSize cImageData.Handle, PropertyTagOrientation, lSize
If lSize = 18& Then
ReDim arrData(0 To lSize - 1&)
If GdipGetPropertyItem(cImageData.Handle, PropertyTagOrientation, lSize, arrData(0)) = 0& Then
CopyMemory lSize, arrData(4), 4&
If lSize = 2& Then
CopyMemory lValue, arrData(8), 4&
If lValue = 3& Then
lOrient = arrData(16) Or arrData(17) * &H100&
Select Case lOrient
Case 2, 4: lOrient = lOrient + 2 ' RotateNoneFlipX, Rotate180FlipX
Case 6, 8: lOrient = lOrient - 5 ' Rotate90FlipNone, Rotate270FlipNone
Case 1, 3: lOrient = lOrient - 1 ' Rotate180FlipNone
Case 5, 7 ' Rotate90FlipX, Rotate270FlipX
Case Else: lOrient = 0& ' invalid value
End Select
End If
End If
End If
End If
If lOrient > 0& Then
GdipImageRotateFlip cImageData.Handle, lOrient
GdipCreateHBITMAPFromBitmap cImageData.Handle, hBmp, -1&
If hBmp <> 0 Then
Set tImageData = New cGDIpMultiImage
pvProcessGDIhandleSource tImageData, hBmp, False
Set cImageData = tImageData
End If
End If
End Sub
With the above changes, all JPGs will be tested for non-standard orientation and auto-corrected. If auto-correction is needed, then the JPG will be converted to a Bitmap and no longer be a JPG. If no auto-correction is needed, no action taken.Code:Private Declare Function GdipImageRotateFlip Lib "GdiPlus.dll" (ByVal pImage As Long, ByVal rfType As Long) As Long
Thank you very much LaVolpe!!!
Great job! Now is working perfectly!
Thank you very much LaVolpe!!!
Great job! Now is working perfectly!
i have new problem for open orginal source.when i want open source just see this error : expersion too complex how can fix that?
Search the code for "Not Not". I don't think I use that code in that project, but am not looking at the code right now. You may have that code in another part of your project somewhere. If so, post the question in the general questions portion of the forum. If you find it in the alpha image control, let me know. I can take a look tomorrow when I get home from work.
Ugh, I see you posted the question several times elsewhere. At least figure out which control is generating the error vs. sending this question to each person that wrote a control you are using, hoping one of them will do your debugging for you.
i find a way for fix this porblem but i think this is not good idea,i unchecked ax-tools code smart 2013 from add in manager and then restart vb and no problem now,i think this porblem is about IDE editor.
but i have a simple question now
i loaded a image from https like as this :
for example this image is 300*300 pixel,now i want save this picture to png format croped to 230*230.Code:Private myloader As AICGlobals
Set myloader = New AICGlobals
'img is alpha image control
Set img.Picture = myloader.LoadPictureGDIplus("https://.... url",,false)
this code workd for me for save just
but how can crop and save?Code:myloader.SavePictureGDIplus img.Picture, SavePath, lvicSaveAsPNG
Cropping? Start on page 7, post 245. Read that one and the next few. There are a couple options & sample code
i used your code :
Code:
With tmpimg
.SetRedraw = False
.AlignCenter = False
.AutoSize = lvicNoAutoSize
' ensure X, Y are pixel scalemode
.SetOffsets -0, -0
' ensure X, Y, Width, Height are appropriate container scalemode
.Move .Left + 0, .Top + 0, .Width - (70 * Screen.TwipsPerPixelX), .Height - (70 * Screen.TwipsPerPixelY)
.SetRedraw = True
End With
myloader.SavePictureGDIplus tmpimg.Picture, SavePath, lvicSaveAsPNG
i changed that line to :
but saved as orginal size alltimes,why?Code:.Move .Left + 0, .Top + 0, Width - 70, Height - 70)
'or
.Move .Left + 0, .Top + 0, 3000, 3000)
i want saved croped image for example from 300*300 orginal pixel to 230*230pixel as png
Try to better understand the control you are using. That code crops the image within the display, it is not editing the image, is it? If you would have did as I asked and read the next few after post #245, you would have seen an example of creating a cropped image that you can save.
i used wia like as this for crop png file (my problem fixed now) :
Code:
Dim img As New WIA.ImageFile
Dim IP As New WIA.ImageProcess
img.LoadFile orginalfilename
IP.Filters.Add IP.FilterInfos!Crop.FilterID
IP.Filters(1).Properties("Left") = 0
IP.Filters(1).Properties("Top") = 0
IP.Filters(1).Properties("Right") = 0
IP.Filters(1).Properties("Bottom") = 70
IP.Filters(1).Properties("FrameIndex") = 0
IP.Apply(img).FileData.ImageFile.SaveFile "path and png file name"
This is a real 32-bit transparent PNG control. It uses dozens of modules and class files. Is there a way to minimize the code?
but it's can zorder on button1,button2
it's only like StdPictureEx.cls
image1.picture=*.png
image2.picture=*.png
Great, amazing and wonderful control. Congratulation!!! :)
Just wondering to know if there is the possibility to change the rotation point.
Currently the rotation of the image pivots exactly in the center; I would be grateful to anybody who could give me an hint or maybe the solution.
Thanks :wave:
how can change this user control to standard exe,i want just use in my exe not like as ocx,i did try for change type to standard exe and so some user definition and public varibales is not worked and i did try for create standard exe and add this user control like as custom user control but same errors about changing classess and variables.
any body can attach standard exe version with this user control
You can try to load the OCX control without registration
Hi Lavolpe ,
How can I get a pixel color for a GIF animated image while it is playing frames ?
Lavolpe shipped a global helper class with the control . It is AICGlobals
It has many methods . One of them is : GetPixelGDIplus .
For animated pictures , use this code in the AnimationFrameChanged eventCode:Form1.BackColor= GetPixelGDIplus (AlphaImgCtl1.Picture , 5 ,5)
I don't know if I'm a layman or not, but I couldn't run the uncompiled project, could anyone help me?
Hi LaVolpe, I have a question. I've been trying to load a transparent PNG for hours, and there's no way to load it at runtime in VB6. How do I load a transparent PNG at runtime? It loads perfectly in design time, but not at runtime?
If you're up for it, I've looked at the whole issue and can't find a solution...
Greetings and sorry for the inconvenience...Attachment 194564
James,
LaVolpe is long gone. He officially gave us his sayonara a couple of years ago now, and hasn't been seen since. IIRC, he took a job that wasn't VB6 related at all, and threw himself into that.
There are several others around here who use this work, but you might do better to post a question about it in the regular Q&A section of these forums, rather than the CodeBank.
Good Luck.
It is a bit nonobvious...
Code:Private mImage As GDIpImage
...
Set mImage = LoadPictureGDIplus("C:\path\to\image.png")
Set AlphaImgCtl1.Picture = mImage
This is genius!!
Has anyone modified this for use as a .ctl?
The public UDTs make it quite a bit of work to change, just wondering if anyone has gone ahead and done it already.