-
Aug 12th, 2015, 05:33 PM
#81
Hyperactive Member
Re: [VB6] GDI+ Usage & Samples
EDIT: Fixed, thanks very much for this!
Here is the final code:
Code:
Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal dwImageType As Long, ByVal dwDesiredWidth As Long, ByVal dwDesiredHeight As Long, ByVal dwFlags As Long) As Long
Private Declare Function DrawIconEx Lib "user32.dll" (ByVal hdc As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
Private Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As Long) As Long
Private Const IMAGE_ICON As Long = 1
Private Const LR_LOADFROMFILE As Long = &H10
Private Const DI_NORMAL As Long = &H3
Private Sub Command1_Click()
Dim hIcon As Long
Picture1.Picture = Nothing
hIcon = LoadImage(0&, App.Path & "\1.ico", IMAGE_ICON, 0&, 0&, LR_LOADFROMFILE)
If hIcon Then
DrawIconEx Picture1.hDC, 0, 0, hIcon, 0&, 0&, 0&, 0&, DI_NORMAL
DestroyIcon hIcon
End If
End Sub
Last edited by MikiSoft; Aug 12th, 2015 at 06:28 PM.
-
Aug 12th, 2015, 06:23 PM
#82
Hyperactive Member
Re: [VB6] GDI+ Usage & Samples
Sorry, this is a bit off-topic, but I'm having another issue now - the PictureBox content erases after I drag some window above it. How can I keep (redraw) the loaded icon?
Last edited by MikiSoft; Aug 12th, 2015 at 06:31 PM.
-
Aug 12th, 2015, 06:31 PM
#83
Re: [VB6] GDI+ Usage & Samples
Picture1.AutoRedraw = True
-
Aug 12th, 2015, 06:32 PM
#84
Hyperactive Member
Re: [VB6] GDI+ Usage & Samples
That was so simple... Thanks again!
-
Aug 12th, 2015, 06:36 PM
#85
Re: [VB6] GDI+ Usage & Samples
You're welcome. GDI+ is overkill for most icon needs and GDI+ doesn't even handle icons as well as it should. Good old fashioned GDI works well enough for simple needs.
-
Aug 29th, 2015, 03:08 PM
#86
Frenzied Member
Re: [VB6] GDI+ Usage & Samples
In " Private Sub pvModifyAttributes() ", If We set m_GrayScale > 0 and m_Lightness <>0, the clrMatrix(1,1) and clrMatrix(2, 2) will conflict ? If so, should we separate them into two Sub or Call GdipSetImageAttributesColorMatrix after new m_GrayScale?
Code:
Private Sub pvModifyAttributes()
If m_GrayScale > attrGrayNone Then ' apply grayscale ratios
'...
' grayscale the image
clrMatrix(0, 0) = R: clrMatrix(1, 0) = R: clrMatrix(2, 0) = R
clrMatrix(0, 1) = G: clrMatrix(1, 1) = G: clrMatrix(2, 1) = G
clrMatrix(0, 2) = B: clrMatrix(1, 2) = B: clrMatrix(2, 2) = B
clrMatrix(3, 3) = CSng((100! - m_Alpha) / 100!) ' global blending; value between 0 & 1
clrMatrix(4, 4) = 1! ' required; cannot be anything else
End If
If m_Lightness <> 0! Then ' add/subtract light intensity
If clrMatrix(4, 4) = 0! Then
clrMatrix(0, 0) = 1!: clrMatrix(1, 1) = 1!: clrMatrix(2, 2) = 1!
clrMatrix(3, 3) = CSng((100! - m_Alpha) / 100!) ' global blending; value between 0 & 1
clrMatrix(4, 4) = 1! ' required; cannot be anything else
End If
clrMatrix(0, 4) = m_Lightness / 100! ' red added/subtracted brightness
clrMatrix(1, 4) = clrMatrix(0, 4) ' same for blue
clrMatrix(2, 4) = clrMatrix(0, 4) ' same for green
End If
'...
End Sub
Last edited by Jonney; Aug 29th, 2015 at 03:27 PM.
-
Aug 29th, 2015, 03:32 PM
#87
Re: [VB6] GDI+ Usage & Samples
Jonney, nope. Notice that clrMatrix(4, 4) is set to non-null when grayscale matrix was created. The lightness matrix section is only filling in those matrix items if clrMatrix(4, 4) is null. That should be the case for all the matrix sections. Only fill in the required items if they haven't already been filled in.
My alpha image control rewrote that logic, but fundamentally, it uses the same checks & balances.
-
Aug 29th, 2015, 04:17 PM
#88
Frenzied Member
Re: [VB6] GDI+ Usage & Samples
Originally Posted by LaVolpe
Jonney, nope. Notice that clrMatrix(4, 4) is set to non-null when grayscale matrix was created. The lightness matrix section is only filling in those matrix items if clrMatrix(4, 4) is null. That should be the case for all the matrix sections. Only fill in the required items if they haven't already been filled in.
My alpha image control rewrote that logic, but fundamentally, it uses the same checks & balances.
I miss the check.
I am troubleshooting why the alpha doesn't work: hGraphics bind to hImage.
Code:
GdipGetImageGraphicsContext hImage, hGraphics
imgAttributesHandle = pvModifyAttributes(Alpha,Lightness, TransColor,GrayScale)
GdipDrawImageRectRectI hGraphics, hImage, 0, 0, imgWidth, imgHeight, 0, 0, imgWidth, imgHeight, UnitPixel, imgAttributesHandle
If imgAttributesHandle Then GdipDisposeImageAttributes imgAttributesHandle
GdipDeleteGraphics hGraphics
Edited:
But this one is OK: hGraphics created by hdc.
Code:
Public Sub 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 srcUnit As GpUnit = UnitPixel)
If hImage <> 0 Then
Dim hGraphics As Long
GdipCreateFromHDC hdc, hGraphics
Dim Attributes As Long 'Testing Code
Attributes = pvModifyAttributes(70, 0, 0, 1) 'Testing Code
GdipDrawImageRectRectI hGraphics, hImage, x, y, Width, Height, srcX, srcY, srcWidth, srcHeight, srcUnit, Attributes
If Attributes <> 0 Then GdipDisposeImageAttributes Attributes
GdipReleaseDC hGraphics, hdc
GdipDeleteGraphics hGraphics
End If
End Sub
Last edited by Jonney; Aug 29th, 2015 at 04:33 PM.
-
Aug 29th, 2015, 04:33 PM
#89
Re: [VB6] GDI+ Usage & Samples
What is TransColor? I assume that is what you are talking about. Remember that most color references in GDI+ are BGR vs RGB
How do you use it in your version of pvModifyAttributes? May need to see that code portion
-
Aug 29th, 2015, 04:37 PM
#90
Frenzied Member
Re: [VB6] GDI+ Usage & Samples
Originally Posted by LaVolpe
What is TransColor? I assume that is what you are talking about. Remember that most color references in GDI+ are BGR vs RGB
How do you use it in your version of pvModifyAttributes? May need to see that code portion
Please refresh the page, I have edited my writing.
I think this rung has problem. They overide each other?
GdipGetImageGraphicsContext hImage, hGraphics
imgAttributesHandle = pvModifyAttributes(Alpha,Lightness, TransColor,GrayScale)
GdipDrawImageRectRectI hGraphics, hImage, 0, 0, imgWidth, imgHeight, 0, 0, imgWidth, imgHeight, UnitPixel, imgAttributesHandle
If imgAttributesHandle Then GdipDisposeImageAttributes imgAttributesHandle
GdipDeleteGraphics hGraphics
my usage is not correct I think. But why others like Lightness and GrayScale work? Only Alpha doesn't take effect.
Do we have to use GdipDrawImageRectRectI to apply the attribute for hImage, any other GDI+ API?
Code:
Private Function pvModifyAttributes(Optional Alpha As Long = 0, Optional ByVal Lightness As Long = 0, Optional ByVal TransColor As OLE_COLOR = 0, Optional ByVal eGrayScale As GrayScaleConstants = 0) As Long
' about attributes.
' The following are added to a GDI+ attributes handle:
' eGrayScale, GlobalTranparency, GlobalLightness, ExtraTransparency
' Mirroring is done inside the GDI+ image itself
' Rotation is done via DC WorldTransformation on-the-fly when rendering
' So to determine if any attributes are in play, 3 variables must be checked:
' Inplay = ((Me.ImageAttributesHandle=0& And Me.Rotation=0! And Me.Mirrored=attrMirrorNone) = False)
Dim Attr As Long
If Alpha <> 0 Or Lightness <> 0 Or TransColor <> 0 Or eGrayScale <> 0 Then
Call GdipCreateImageAttributes(Attr)
Else
Exit Function
End If
Dim clrMatrix(0 To 4, 0 To 4) As Single
Dim r As Single, g As Single, b As Single
Const ColorAdjustTypeBitmap As Long = &H1&
'ColorMatrix ClrMatrix ={
' 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
' 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
' 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
' 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, //Alpha =0.5 (50% Transparency)
' 0.0f, 0.0f, 0.0f, 0.0f, 1.0f };
If eGrayScale > attrGrayNone Then ' apply grayscale ratios
Select Case eGrayScale
Case attrGrayNTSCPAL
r = 0.299: g = 0.587: b = 0.114 ' standard weighted average
Case attrGraySimpleAverage
r = 0.333: g = 0.334: b = r ' pure average
Case attrGrayCCIR709
r = 0.213: g = 0.715: b = 0.072 ' CCIR709
Case attrGrayRedMask
r = 0.8: g = 0.1: b = g ' personal preferences: could be r=1:g=0:b=0 or other weights
Case attrGrayGreenMask
r = 0.1: g = 0.8: b = r ' personal preferences: could be r=0:g=1:b=0 or other weights
Case attrGrayBlueMask
r = 0.1: g = r: b = 0.8 ' personal preferences: could be r=0:g=0:b=1 or other weights
Case attrGrayBlueGreenMask
r = 0.1: g = 0.45: b = g ' personal preferences: could be r=0:g=.5:b=.5 or other weights
Case attrGrayRedGreenMask
r = 0.45: g = r: b = 0.1 ' personal preferences: could be r=.5:g=.5:b=0 or other weights
End Select
' grayscale the image
clrMatrix(0, 0) = r: clrMatrix(1, 0) = r: clrMatrix(2, 0) = r
clrMatrix(0, 1) = g: clrMatrix(1, 1) = g: clrMatrix(2, 1) = g
clrMatrix(0, 2) = b: clrMatrix(1, 2) = b: clrMatrix(2, 2) = b
clrMatrix(3, 3) = CSng((100! - Alpha) / 100!) ' global blending; value between 0 & 1
clrMatrix(4, 4) = 1! ' required; cannot be anything else
End If
If Lightness <> 0! Then ' add/subtract light intensity
If clrMatrix(4, 4) = 0! Then
clrMatrix(0, 0) = 1!: clrMatrix(1, 1) = 1!: clrMatrix(2, 2) = 1!
clrMatrix(3, 3) = CSng((100! - Alpha) / 100!) ' global blending; value between 0 & 1
clrMatrix(4, 4) = 1! ' required; cannot be anything else
End If
clrMatrix(0, 4) = Lightness / 100! ' red added/subtracted brightness
clrMatrix(1, 4) = clrMatrix(0, 4) ' same for blue
clrMatrix(2, 4) = clrMatrix(0, 4) ' same for green
End If
If Alpha <> 0! Then ' add global transparency
If clrMatrix(4, 4) = 0! Then
clrMatrix(0, 0) = 1!: clrMatrix(1, 1) = 1!: clrMatrix(2, 2) = 1!
clrMatrix(3, 3) = CSng((100! - Alpha) / 100!) ' global blending; value between 0 & 1
clrMatrix(4, 4) = 1! ' required; cannot be anything else
End If
End If
If clrMatrix(4, 4) = 1! Then ' create attributes?
If GdipCreateImageAttributes(Attr) = 0& Then
If GdipSetImageAttributesColorMatrix(Attr, ColorAdjustTypeBitmap, 1&, clrMatrix(0, 0), clrMatrix(0, 0), 0&) Then
GdipDisposeImageAttributes Attr
Attr = 0&
End If
End If
End If
If TransColor Then
If Attr = 0& Then Call GdipCreateImageAttributes(Attr)
If Attr Then
If GdipSetImageAttributesColorKeys(Attr, 1&, 1&, TransColor, TransColor) Then ' failure
If clrMatrix(4, 4) = 0! Then
GdipDisposeImageAttributes Attr
Attr = 0&
End If
End If
End If
End If
pvModifyAttributes = Attr
End Function
Last edited by Jonney; Aug 29th, 2015 at 04:57 PM.
-
Aug 29th, 2015, 05:13 PM
#91
Frenzied Member
Re: [VB6] GDI+ Usage & Samples
OK. I expose the return of pvModifyAttributes to my Image Class Public Property: Image.gdpiAttributes so that the attributes can be applied when calling gdipStretchPicture. My Image Class will take care Dispose.
Code:
Public Sub 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 srcUnit As GpUnit = UnitPixel,Optional Byval Attributes As Long =0)
If hImage <> 0 Then
Dim hGraphics As Long
GdipCreateFromHDC hdc, hGraphics
GdipDrawImageRectRectI hGraphics, hImage, x, y, Width, Height, srcX, srcY, srcWidth, srcHeight, srcUnit, Attributes
GdipReleaseDC hGraphics, hdc
GdipDeleteGraphics hGraphics
End If
Last edited by Jonney; Aug 29th, 2015 at 05:22 PM.
-
Aug 29th, 2015, 06:02 PM
#92
Re: [VB6] GDI+ Usage & Samples
I see what you were trying to do by binding it to the image. The reason why the alpha doesn't work is because the pixel data is still on the image. You are rendering semi-transparency over the same image. You can't make an existing image less transparent by rendering something over it. Blending same images on each other, changing only transparency, should result in no change to the image.
It would be like taking a screen capture of the desktop. Then rendering another copy of the desktop over the 1st one, just at 70% transparency. You should see no difference after rendering. However, if the 70% version was rendered on some other image, then you'd see the semi-transparent blended into that other image.
-
Aug 29th, 2015, 06:24 PM
#93
Frenzied Member
Re: [VB6] GDI+ Usage & Samples
Originally Posted by LaVolpe
I see what you were trying to do by binding it to the image. The reason why the alpha doesn't work is because the pixel data is still on the image. You are rendering semi-transparency over the same image. You can't make an existing image less transparent by rendering something over it. Blending same images on each other, changing only transparency, should result in no change to the image.
It would be like taking a screen capture of the desktop. Then rendering another copy of the desktop over the 1st one, just at 70% transparency. You should see no difference after rendering. However, if the 70% version was rendered on some other image, then you'd see the semi-transparent blended into that other image.
I can't get sleep in whole night for this GDI+ matter.
Thanks for this analyst. I learned the lesson.
Thank you Sir.
-
Oct 17th, 2015, 03:47 AM
#94
Hyperactive Member
Re: [VB6] GDI+ Usage & Samples
@LaVolpe: Can you help me again, I need a basic example on how to load and display GIF image, first frame?
Last edited by MikiSoft; Oct 17th, 2015 at 03:58 AM.
-
Oct 17th, 2015, 07:32 AM
#95
Re: [VB6] GDI+ Usage & Samples
First frame is always displayed first. Simply load the image via GDI+ or VB's LoadPicture() which also supports GIF. Not sure I understand the problem.
Last edited by LaVolpe; Oct 17th, 2015 at 08:05 AM.
-
Oct 17th, 2015, 07:44 AM
#96
Frenzied Member
Re: [VB6] GDI+ Usage & Samples
Originally Posted by LaVolpe
Fist frame is always displayed first. Simply load the image via GDI+ or VB's LoadPicture() which also supports GIF. Not sure I understand the problem.
tired with all kinds of strange questions.
-
Oct 17th, 2015, 08:06 AM
#97
Re: [VB6] GDI+ Usage & Samples
Originally Posted by Jonney
tired with all kinds of strange questions.
Gut feeling is that that is not the entire question or not stated completely
-
Oct 17th, 2015, 10:25 AM
#98
Hyperactive Member
Re: [VB6] GDI+ Usage & Samples
I want simple GDI+ API code which will load GIF image and display its first frame in a PictureBox, because LoadPicture loads it in poor quality.
Last edited by MikiSoft; Oct 17th, 2015 at 10:28 AM.
-
Oct 17th, 2015, 10:30 AM
#99
Re: [VB6] GDI+ Usage & Samples
GDIpLoadImageFromFile/GdipLoadImageFromStream will load a properly formatted GIF. VB's LoadPicture will do the same. Both will have the exact same quality at 100% scale. In any case, the 1st frame is always rendered initially.
After reading your edited comment:
You can extract the code from this project to do what you are asking. The steps would look like this:
1. Load image via GDIpLoadImageFromFile
2. Get picturebox DC into GDI+ graphics object via GDIpCreateFromHDC
3. Set bicubic scaling on the graphics object via GdipSetInterpolationMode
4. Get the image bounds via GDIpGetImageBounds
5. Render the image to the graphics object: GDIpDrawImageRectRect or GDIpDrawImageRectRectI
6. Destroy the GDI+ graphics & image objects
Last edited by LaVolpe; Oct 17th, 2015 at 03:26 PM.
-
Jun 7th, 2016, 08:12 AM
#100
Junior Member
Re: [VB6] GDI+ Usage & Samples
Using your topic, I wonder how I can save only one area (x, y, heigh, width) of the image using the code below
Dim bData() As Byte, fn As Integer, bOk As Boolean
Dim tImage() As cGDIpImage
On Error GoTo ExitRoutine
bOk = cImage.SaveAsJPG(bData(), , True)
If bOk = False Then
MsgBox "Failed to save to the desired image format", vbInformation + vbOKOnly
Else
fn = FreeFile()
Open "c:\teste.jpg" For Binary As #fn
Put #fn, 1, bData()
Close #fn
MsgBox "File saved", vbInformation + vbOKOnly
End If
ExitRoutine:
If fn Then
Close #fn
If Err Then MsgBox Err.Description, vbExclamation + vbOKOnly
End If
-
Nov 22nd, 2016, 05:29 PM
#101
PowerPoster
Re: [VB6] GDI+ Usage & Samples
LaVolpe: please correct that link on #1 post. the link isn't working for i see the GDIPlus API functions.
thanks for all
-
Nov 28th, 2016, 10:23 AM
#102
Addicted Member
Re: [VB6] GDI+ Usage & Samples
Lavolpe, I know this post is rather old (and dead) but I needed that routine (bonus code Post #8) to load png simply.
Post #21 as you stated contain a fix, but the solution was incompleted and bugged too (m_Size.nWidth, m_Size.nWidth instead of m_Size.nWidth, m_Size.nHeight) so I decided to provide missing code to make your bonus code fully work.
plz don't flame me. All the credit still go to you, thanks again.
Code:
Option Explicit
Private Const UNIT_PIXEL As Long = &H2&
Private Type GdiplusStartupInput
GdiplusVersion As Long
DebugEventCallback As Long
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End Type
Private Type RECTF
nLeft As Single
nTop As Single
nWidth As Single
nHeight As Single
End Type
Private Declare Function GdiplusStartup Lib "GdiPlus.dll" (Token As Long, inputbuf As GdiplusStartupInput, Optional ByVal outputbuf As Long = 0) As Long
Private Declare Function GdipLoadImageFromFile Lib "GdiPlus.dll" (ByVal mFilename As Long, ByRef mImage As Long) As Long
Private Declare Function GdipDeleteGraphics Lib "GdiPlus.dll" (ByVal mGraphics As Long) As Long
Private Declare Function GdipCreateFromHDC Lib "GdiPlus.dll" (ByVal hDC As Long, hGraphics As Long) As Long
Private Declare Function GdipDrawImage Lib "GdiPlus.dll" (ByVal mGraphics As Long, ByVal mImage As Long, ByVal mX As Single, ByVal mY As Single) As Long
Private Declare Function GdipDisposeImage Lib "GdiPlus.dll" (ByVal Image As Long) As Long
Private Declare Sub GdiplusShutdown Lib "GdiPlus.dll" (ByVal Token As Long)
Private Declare Function GdipGetImageBounds Lib "GdiPlus.dll" (ByVal nImage As Long, srcRect As RECTF, srcUnit As Long) As Long
Private Declare Function GdipDrawImageRectRectI Lib "GdiPlus.dll" (ByVal hGraphics As Long, ByVal hImage As Long, ByVal dstX As Long, ByVal dstY As Long, ByVal dstWidth As Long, ByVal dstHeight As Long, ByVal srcX As Long, ByVal srcY As Long, ByVal srcWidth As Long, ByVal srcHeight As Long, ByVal srcUnit As Long, Optional ByVal imageAttributes As Long = 0, Optional ByVal Callback As Long = 0, Optional ByVal callbackData As Long = 0) As Long
Public Function RenderPNG(FileName As String, hDC As Long, ByVal plngDestX As Long, ByVal plngDestY As Long) As Long
Dim lngRetValue As Long
Dim GDIsi As GdiplusStartupInput
Dim gToken As Long
Dim hGraphics As Long
Dim hBitmap As Long
Dim lngSuccess As Long
Dim typPicSize As RECTF
lngRetValue = 0
On Error Resume Next
GDIsi.GdiplusVersion = 1&
lngSuccess = GdiplusStartup(gToken, GDIsi)
'If Err Then
' Err.Clear
' Exit Function
'ElseIf gToken = 0& Then
' Exit Function
'End If
On Error GoTo 0
If (gToken <> 0) Then
Call GdipCreateFromHDC(hDC, hGraphics)
If hGraphics Then
Call GdipLoadImageFromFile(StrPtr(FileName), hBitmap)
If hBitmap Then
'GdipDrawImage hGraphics, hBitmap, plngDestX, plngDestY
Call GdipGetImageBounds(hBitmap, typPicSize, UNIT_PIXEL)
Call GdipDrawImageRectRectI(hGraphics, hBitmap, plngDestX, plngDestY, typPicSize.nWidth, typPicSize.nHeight, 0, 0, typPicSize.nWidth, typPicSize.nHeight, UNIT_PIXEL, 0&, 0&, 0&)
GdipDisposeImage hBitmap
lngRetValue = 1
End If
GdipDeleteGraphics hGraphics
End If
GdiplusShutdown gToken
End If
RenderPNG = lngRetValue
End Function
calling is something like:
'frmMain.Autorefresh = True
RenderPNG strPath, frmMain.hDC, 0, 0
frmMain.Refresh
-
Sep 15th, 2018, 09:16 PM
#103
Member
Re: [VB6] GDI+ Usage & Samples
PolygonBlt isn't actually drawing a proper polygon, but a parallelogram. How would I draw an image as a polygon using an array of 4 POINTAPIs to set each corner's coordinate (like DrawPolygon, but drawing an image instead of a color). A parallelogram only lets me set 3 of the coordinates and GDI+ guesses the 4th, which is incorrect in my use case.
-
Sep 22nd, 2018, 11:47 AM
#104
Re: [VB6] GDI+ Usage & Samples
What you are asking, I don't believe there is an "easy" solution. Maybe there are free libraries out there that will do what you are asking. Without such a library/class, basically each pixel in the bitmap needs to be "stretched" proportionally to fill a dynamic shape/polygon. GDI+ offers a method of warping points to a polygon, but not a method to warp an image to other than a parallelogram (rectangle or otherwise). If you google "Free Image Transformation", you should see a project on CodeProject site. It isn't written in VB, but offers logic and a sample project. I do think you need an account to download the project.
-
Sep 22nd, 2018, 08:10 PM
#105
Member
Re: [VB6] GDI+ Usage & Samples
Originally Posted by LaVolpe
What you are asking, I don't believe there is an "easy" solution. Maybe there are free libraries out there that will do what you are asking. Without such a library/class, basically each pixel in the bitmap needs to be "stretched" proportionally to fill a dynamic shape/polygon. GDI+ offers a method of warping points to a polygon, but not a method to warp an image to other than a parallelogram (rectangle or otherwise). If you google "Free Image Transformation", you should see a project on CodeProject site. It isn't written in VB, but offers logic and a sample project. I do think you need an account to download the project.
Turns out I was wrong anyway. ParallelBlt worked just fine. Thank you though.
-
Sep 18th, 2019, 07:04 AM
#106
New Member
Re: [VB6] GDI+ Usage & Samples
Hi there, what an amazing piece of code!
Sorry to bother you for this, but I noticed that saving a picture as a gif is not possible.
And for an old VB6 project I specifically need to convert png's to gif's...
Is there a simple way to add this feature to the existing code?
Any help would be greatly appreciated, thanks!
-
Sep 18th, 2019, 07:05 AM
#107
New Member
Re: [VB6] GDI+ Usage & Samples
Hi there, what an amazing piece of code!
Sorry to bother you for this, but I noticed that saving a picture as a gif is not possible.
And for an old VB6 project I specifically need to convert png's to gif's...
Is there a simple way to add this feature to the existing code?
Any help would be greatly appreciated, thanks!
-
Sep 18th, 2019, 07:42 AM
#108
New Member
Re: [VB6] GDI+ Usage & Samples
I was able to change the code a little bit so now it saves the png's to gif's, but how can I preserve transparency?
-
Sep 18th, 2019, 08:25 PM
#109
Re: [VB6] GDI+ Usage & Samples
Not sure what code you are using to convert PNG to GIF. But if using GDI+ to create a GIF, the color format must be 8 byte, paletted image with transparency.
As for preserving transparency. That can be really difficult for PNG to GIF because of alphablending that most PNGs have. Typically, some sort of threshold is set to say if transparency is greater than x percent make the color transparent else make it opaque. One index of the 256 possible color indexes in that 8 byte format would be reserved for transparency. Every transparent pixel will be assigned that index. So you only have 255 possible colors for color reduction (if PNG has more than 255 colors) when transparency exists.
-
Oct 14th, 2020, 03:25 PM
#110
PowerPoster
Re: [VB6] GDI+ Usage & Samples
LaVolpe where can i see the GDIPlus functions declarations for VB6?
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
|