-
Oct 13th, 2020, 07:52 AM
#1
Thread Starter
New Member
[RESOLVED] Save 3 different PNG files into 1 PNG ARGB
Hi
i am definitely out of my comfort zone here, i am trying to save 3 different PNG images into 1 image,
image 1 into R channel
image 2 into G channel
image 3 into B channel
i suppose you could call it channel packing, does anyone have any pointers or documentation on how i may achieve this?
thank you in advance
Kev
-
Oct 13th, 2020, 08:10 AM
#2
Re: Save 3 different PNG files into 1 PNG ARGB
Please remember next time...elections matter!
-
Oct 13th, 2020, 08:37 AM
#3
Thread Starter
New Member
-
Oct 13th, 2020, 10:03 AM
#4
Re: Save 3 different PNG files into 1 PNG ARGB
Something went wrong with that attachment.
My usual boring signature: Nothing
-
Oct 13th, 2020, 10:14 AM
#5
Thread Starter
New Member
Re: Save 3 different PNG files into 1 PNG ARGB
-
Oct 15th, 2020, 09:45 AM
#6
Thread Starter
New Member
Re: Save 3 different PNG files into 1 PNG ARGB
I have almost got this but not quite right my code is awful and needs optimising, the RGB values are where i am failing :
Code:
Public Class FRMxSurface
Dim AObmp, GLOSSbmp, METALbmp, SURFACEbmp As Bitmap
Dim clrAO, clrAOTemp, clrGLOSS, clrGLOSSTemp, clrMETAL, clrMETALTemp, clrSURFACE, clrSURFACETempR, clrSURFACETempG, clrSURFACETempB As Color
Private Sub PBsurfaceMap_Click(sender As Object, e As EventArgs) Handles PBsurfaceMap.Click
End Sub
Dim intR, intG, intB, intTemp As Integer
Private Sub BTNCreate_Click(sender As Object, e As EventArgs) Handles BTNCreate.Click
'test for images
If PBaoMap.Image Is Nothing Then
Exit Sub
ElseIf PBglossMap.Image Is Nothing Then
Exit Sub
ElseIf PBmetalMap.Image Is Nothing Then
Exit Sub
End If
PBTempIMAGE.Image = PBglossMap.Image
Dim xao, yao, xg, yg, xm, ym, xs, ys As Integer
AObmp = New Bitmap(PBaoMap.Image)
GLOSSbmp = New Bitmap(PBglossMap.Image)
METALbmp = New Bitmap(PBmetalMap.Image)
For xao = 0 To AObmp.Width - 1
For yao = 0 To AObmp.Height - 1
clrAO = AObmp.GetPixel(xao, yao)
clrAOTemp = Color.FromArgb(clrAO.R, clrAO.G, clrAO.B)
Next
Next
For xg = 0 To GLOSSbmp.Width - 1
For yg = 0 To GLOSSbmp.Height - 1
clrGLOSS = GLOSSbmp.GetPixel(xg, yg)
clrGLOSSTemp = Color.FromArgb(clrGLOSS.R, clrGLOSS.G, clrGLOSS.B)
Next
Next
For xm = 0 To METALbmp.Width - 1
For ym = 0 To METALbmp.Height - 1
clrMETAL = METALbmp.GetPixel(xm, ym)
clrMETALTemp = Color.FromArgb(clrMETAL.R, clrMETAL.G, clrMETAL.B)
Next
Next
SURFACEbmp = New Bitmap(PBglossMap.Image)
For xs = 0 To SURFACEbmp.Width - 1
For ys = 0 To SURFACEbmp.Height - 1
clrSURFACETempR = Color.FromArgb(clrAOTemp.R, clrAOTemp.G, clrAOTemp.B)
clrSURFACETempG = Color.FromArgb(clrGLOSSTemp.R, clrGLOSSTemp.G, clrGLOSSTemp.B)
clrSURFACETempB = Color.FromArgb(clrMETALTemp.R, clrMETALTemp.G, clrMETALTemp.B)
clrSURFACE = Color.FromArgb(clrSURFACETempR.R, clrSURFACETempG.G, clrSURFACETempB.B)
SURFACEbmp.SetPixel(xs, ys, clrSURFACE)
Next
Next
PBsurfaceMap.Image = SURFACEbmp
MsgBox("All Done", vbOKOnly, "Result")
End Sub
-
Oct 15th, 2020, 02:48 PM
#7
Re: Save 3 different PNG files into 1 PNG ARGB
My usual boring signature: Nothing
-
Oct 16th, 2020, 03:08 AM
#8
Thread Starter
New Member
Re: Save 3 different PNG files into 1 PNG ARGB
-
Oct 16th, 2020, 03:12 AM
#9
Thread Starter
New Member
Re: Save 3 different PNG files into 1 PNG ARGB
here is the revised code, i am sure i will work it out but does anyone see anything obvious ??
Code:
Public Class FRMxSurface
Dim AObmp, GLOSSbmp, METALbmp, SURFACEbmp As Bitmap
Dim clrAO, clrAOTemp, clrGLOSS, clrGLOSSTemp, clrMETAL, clrMETALTemp, clrSURFACE, clrSURFACETemp, clrSURFACETempR, clrSURFACETempG, clrSURFACETempB As Color
Dim xao, yao, xg, yg, xm, ym, xs, ys As Integer
Dim AOColor, GLOSSColor, METALColor As Integer
Private Sub PBsurfaceMap_Click(sender As Object, e As EventArgs) Handles PBsurfaceMap.Click
End Sub
Dim intR, intG, intB, intTemp As Integer
Private Sub BTNCreate_Click(sender As Object, e As EventArgs) Handles BTNCreate.Click
'test for images
If PBaoMap.Image Is Nothing Then
Exit Sub
ElseIf PBglossMap.Image Is Nothing Then
Exit Sub
ElseIf PBmetalMap.Image Is Nothing Then
Exit Sub
End If
PBTempIMAGE.Image = PBglossMap.Image
Dim xao, yao, xg, yg, xm, ym, xs, ys As Integer
AObmp = New Bitmap(PBaoMap.Image)
GLOSSbmp = New Bitmap(PBglossMap.Image)
METALbmp = New Bitmap(PBmetalMap.Image)
Using fp As New FastPix(AObmp)
For xao = 0 To AObmp.Width - 1
For yao = 0 To AObmp.Height - 1
clrAO = fp.GetPixel(xao, yao)
clrAOTemp = Color.FromArgb(clrAO.R, clrAO.G, clrAO.B)
Next
Next
End Using
Using fp As New FastPix(GLOSSbmp)
For xg = 0 To GLOSSbmp.Width - 1
For yg = 0 To GLOSSbmp.Height - 1
clrGLOSS = fp.GetPixel(xg, yg)
clrGLOSSTemp = Color.FromArgb(clrGLOSS.R, clrGLOSS.G, clrGLOSS.B)
Next
Next
End Using
Using fp As New FastPix(METALbmp)
For xm = 0 To METALbmp.Width - 1
For ym = 0 To METALbmp.Height - 1
clrMETAL = fp.GetPixel(xm, ym)
clrMETALTemp = Color.FromArgb(clrMETAL.R, clrMETAL.G, clrMETAL.B)
Next
Next
End Using
SURFACEbmp = New Bitmap(PBTempIMAGE.Image)
Using fp As New FastPix(SURFACEbmp)
For xs = 0 To SURFACEbmp.Width - 1
For ys = 0 To SURFACEbmp.Height - 1
clrSURFACE = fp.GetPixel(xs, ys)
clrSURFACETemp = Color.FromArgb(clrAO.R, clrGLOSS.G, clrMETAL.B)
fp.SetPixel(xs, ys, clrSURFACETemp)
Next
Next
End Using
PBsurfaceMap.Image = SURFACEbmp
MsgBox("All Done", vbOKOnly, "Result")
End Sub
-
Oct 16th, 2020, 10:06 AM
#10
Re: Save 3 different PNG files into 1 PNG ARGB
You are looping through all the pixels in AObmp reading the colour of each pixel, but not doing anything with it. The same for GLOSSbmp and METALbmp.
What you end up with is clrAo, clrGLOSS and clrMETAL holding the colour of the very last (bottom right) pixel in each of the respective images, and using just those 3 colours to set every pixel in the output image. Hence the uniform colour.
What you probably want is a single loop that, on each iteration of the loop, reads the colour of a single pixel from each of the 3 input images and uses the necessary parts of those 3 colours to set the corresponding pixel colour in the output image.
-
Oct 16th, 2020, 10:24 AM
#11
Thread Starter
New Member
Re: Save 3 different PNG files into 1 PNG ARGB
Thank you, i will try and figure that out thankfully all source images are exactly the same size (power of 2).
so as i get a pixel i need to set a pixel on the output image ? the single loop how would i set that up so that i could setpixel at same time ?
sorry for being dumb
-
Oct 16th, 2020, 10:38 AM
#12
Re: Save 3 different PNG files into 1 PNG ARGB
Originally Posted by KevanH
thankfully all source images are exactly the same size (power of 2).
That's a good job :-p
So you can get the width and height from any of the 3 images and loop over all the pixel columns and rows as you are already doing.
Read the pixel at (x,y) from each of the three input images and create a new colour from the required component channels. Then use the chimera colour to set the colour of the pixel at (x,y) in the output image. Something like this (untested):
Code:
AObmp = New Bitmap(PBaoMap.Image)
GLOSSbmp = New Bitmap(PBglossMap.Image)
METALbmp = New Bitmap(PBmetalMap.Image)
SURFACEbmp = New Bitmap(PBTempIMAGE.Image)
Using fpAO As New FastPix(AObmp),
fpGLOSS As New FastPix(GLOSSbmp),
fpMETAL As New FastPix(METALbmp),
fpSurface As New FastPix(SURFACEbmp)
For x = 0 To AObmp.Width - 1
For y = 0 To AObmp.Height - 1
clrAO = fpAO.GetPixel(x, y)
clrGLOSS = fpGLOSS.GetPixel(x, y)
clrMETAL = fpMETAL.GetPixel(x, y)
clrSURFACE = Color.FromArgb(clrAO.R, clrGLOSS.G, clrMETAL.B)
fpSurface.SetPixel(x, y, clrSURFACE)
Next
Next
End Using
-
Oct 16th, 2020, 11:02 AM
#13
Thread Starter
New Member
-
Oct 19th, 2020, 06:49 AM
#14
Thread Starter
New Member
Re: [RESOLVED] Save 3 different PNG files into 1 PNG ARGB
Hi i am back LOL,
this solution is working perfectly, however some of the textures are in DDS format, can anyone recommend a library or wrapper for vb.net to open/save DDS files.
One with samples would be better if possible, i have had a quick look at freeimage but its C# so do not know where to start
-
Oct 19th, 2020, 07:35 AM
#15
Re: [RESOLVED] Save 3 different PNG files into 1 PNG ARGB
The best friend of any programmer is a search engine
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
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
|