|
-
Dec 8th, 2015, 08:12 AM
#1
Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation
You have to use the actual height along with the srcY for partial renderring
Using pixels for example. Let's say the image was 300 pixels in height and you wanted to render 200 of the 300
SrcY = ActualHeight - SrcY i.e., SrcY = 300 - 200
I see you have this in a class and are manually converting to/from himetrics. But I'll use ScaleX & ScaleY for easier reading & assume all the parameters are passed in pixels.
Code:
.Render (hDC), destX, destY, destWidth, destHeight, _
srcX, .Height - ScaleY(SrcY, vbPixels, vbHimetric), SrcWidth, -SrcHeight, ByVal 0&
To prevent unexpected consequences, I'd recommend validating passed source parameters at a minimum & also ensure destination parameters are within reason. Maybe one of the following proves invalid?
- SrcY + SrcHeight cannot be less than 0 and cannot be > ActualHeight
- SrcX + SrcWidth cannot be less than 0 and cannot be > ActualWidth
- SrcHeight & SrcWidth must be between 0 and actual dimensions
Last edited by LaVolpe; Dec 8th, 2015 at 08:45 AM.
-
Dec 8th, 2015, 07:47 PM
#2
Frenzied Member
Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation
 Originally Posted by LaVolpe
You have to use the actual height along with the srcY for partial renderring
Using pixels for example. Let's say the image was 300 pixels in height and you wanted to render 200 of the 300
SrcY = ActualHeight - SrcY i.e., SrcY = 300 - 200
I see you have this in a class and are manually converting to/from himetrics. But I'll use ScaleX & ScaleY for easier reading & assume all the parameters are passed in pixels.
Code:
.Render (hDC), destX, destY, destWidth, destHeight, _
srcX, .Height - ScaleY(SrcY, vbPixels, vbHimetric), SrcWidth, -SrcHeight, ByVal 0&
The above code is the same with #27.
I want to Render stdPicture on a Grid Cell, the Cell has 16 types of alignments, from what I tested, implement Vertical partial paint has difficulties. For example, I want to paint "RightBottom"(or LeftBottom or CenterBottom), With Cell height reducing, the picture should moving up as well, until Top of picture is covered. With the above code, if the cell height is smaller than picture actual height, the picture just disappear. I have tried many combinations, but still hard to do so,though my GDI+ render code works for all scenarios.
Code:
Public Enum AlignmentEnum
GeneralGeneral = 0 'Horizontal Default; Vertical Default. 'Left Center
GeneralTop = 1 'Horizontal Default; Vertical Top. 'Left Top
GeneralCenter = 2 'Horizontal Default; Vertical Center. 'Left Center
GeneralBottom = 3 'Horizontal Default; Vertical Bottom. 'Left Bottom
LeftGeneral = 4 'Horizontal Left; Vertical Default. 'Left Center
LeftTop = 5 'Horizontal Left; Vertical Top. 'Left Top
LeftCenter = 6 'Horizontal Left; Vertical Center. 'Left Center
LeftBottom = 7 'Horizontal Left; Vertical Bottom. 'Left Bottom
CenterGeneral = 8 ' Horizontal Center; Vertical Default. 'Center Center
CenterTop = 9 'Horizontal Center; Vertical Top. 'Center Top
CenterCenter = 10 'Horizontal Center; Vertical Center. 'Center Center
CenterBottom = 11 ' Horizontal Center; Vertical Bottom. 'Center Bottom
RightGeneral = 12 ' Horizontal Right; Vertical Default. 'Right Center
RightTop = 13 'Horizontal Right; Vertical Top. 'Right Top
RightCenter = 14 'Horizontal Right; Vertical Center. 'Right Center
RightBottom = 15 'Horizontal Right; Vertical Bottom. 'Right Bottom
End Enum
Code:
Friend Function Render(ByVal hdc As Long, _
Optional ByVal DestX As Long, Optional ByVal DestY As Long, _
Optional ByVal DestWidth As Long, Optional ByVal DestHeight As Long, _
Optional ByVal srcX As Long, Optional ByVal srcY As Long, _
Optional ByVal srcWidth As Long, Optional ByVal srcHeight As Long) As Boolean
Render = gdipStretchPicture(hdc, DestX, DestY, DestWidth, DestHeight, m_hImage, srcX, srcY, srcWidth, srcHeight)
End Function
Public Function gdipStretchPicture(ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal Width As Long, ByVal Height As Long, hImage As Long, ByVal srcX As Long, ByVal srcY As Long, ByVal srcWidth As Long, ByVal srcHeight As Long, Optional ByVal gdipAttributes As Long, Optional ByVal srcUnit As GpUnit = UnitPixel) As Boolean
Dim lR As Long
lR = -1
If hImage <> 0 Then
Dim hGraphics As Long
lR = GdipCreateFromHDC(hdc, hGraphics)
lR = GdipDrawImageRectRectI(hGraphics, hImage, x, y, Width, Height, srcX, srcY, srcWidth, srcHeight, srcUnit, gdipAttributes)
GdipReleaseDC hGraphics, hdc
GdipDeleteGraphics hGraphics
End If
If lR = 0 Then gdipStretchPicture = True
End Function
Last edited by Jonney; Dec 8th, 2015 at 07:58 PM.
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
|