SaveFileDialog - Picturebox.Color

  • VB.NET

Es gibt 15 Antworten in diesem Thema. Der letzte Beitrag () ist von TomTheCoder15.

    SaveFileDialog - Picturebox.Color

    Hallo,

    Ich habe eine Form gebastelt bei der in deine Picturebox Farben gepackt werden.
    Ich habe :

    Picturebox1, Picturebox2, Picturebox3, Picturebox4, Picturebox5 die jeweils 100x100 px groß sind.

    Ich habe in den Pictureboxen keine Bilder sondern Farben.
    Und möchte nun aus den 5 einzelnen Pictureboxen ein Bild machen.

    Hoffe mein Problem ist klar geschildert.
    Danke im Vorraus für eure Hilfe

    Gruß

    TomTheCoder15 schrieb:

    Hoffe mein Problem ist klar geschildert.
    Nö.
    Was hat das ganze mit SaveFileDialog zu tun?
    Was soll hinterher rauskommen?
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    @TomTheCoder15 Soll das so was wie Paint werden?
    Über welche Programmiererfahrung verfügst Du?
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Naja ich benutze VB 2010 schon seid 2014. Kenne mich einigermaßen aus. Jedoch würde ich die Anforderungen nicht zu hoch setzen :D
    Und nein es soll nicht wie Paint werden es soll so sein, dass ich 5 Pictureboxen habe denen ich einzelnd eine Farbe zuweisen kann.
    Bsp.

    Picturebox1 ist Rot und Picturebox2 ist Blau.
    Dann möchte ich, dass diese beiden Pictureboxen sozusagen aneinander gereiht werden und als Bild gespeichert werden.
    Ist das Möglich oder zu kompliziert ?
    Man könnte ja auch einen screenshot von dem ganzen machen lassen oder ?
    @TomTheCoder15 Das Zusammensetzen der Bilder zu einem Bitmap ist kein Problem.
    Dieser Code setzt 3 Images aus den PictureBoxen 1, 2, 3 der Größe 64 x 64 zusammen und speichert sie ab:

    VB.NET-Quellcode

    1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    2. Using bmp = New Bitmap(64 * 3, 64)
    3. Dim g = Graphics.FromImage(bmp)
    4. g.DrawImage(PictureBox1.Image, New Point(0 * 64, 0))
    5. g.DrawImage(PictureBox2.Image, New Point(1 * 64, 0))
    6. g.DrawImage(PictureBox3.Image, New Point(2 * 64, 0))
    7. bmp.Save("c:\Temp\test.png", Imaging.ImageFormat.Png)
    8. End Using
    9. End Sub
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    *Vollzitat entfernt*

    RodFromGermany schrieb:

    g.DrawImage(PictureBox1.Image, New Point(0 * 64, 0))


    Bei dieser Zeile bekomme ich beim Debuggen die Meldung : Wert darf nicht NULL sein. Parametername : Image :/

    Edit by ~blaze~:
    *Vollzitat entfernt*

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „~blaze~“ ()

    @TomTheCoder15 Klar. die Image-Property der PictureBoxen ist bei Dir Nothing.
    Bilder
    • test.png

      13,21 kB, 192×64, 324 mal angesehen
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    @TomTheCoder15 Oder Du malst Deine bunten Rechtecke und befüllst die Image-Property der PictureBoxen:

    VB.NET-Quellcode

    1. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    2. Dim bmp = New Bitmap(64, 64)
    3. Dim g = Graphics.FromImage(bmp)
    4. g.Clear(Color.Red)
    5. PictureBox1.Image = bmp
    6. Dim bmp2 = New Bitmap(64, 64)
    7. g = Graphics.FromImage(bmp2)
    8. g.Clear(Color.Green)
    9. PictureBox2.Image = bmp2
    10. Dim bmp3 = New Bitmap(64, 64)
    11. g = Graphics.FromImage(bmp3)
    12. g.Clear(Color.Blue)
    13. PictureBox3.Image = bmp3
    14. End Sub
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Aaah :) Vielen Dank. Das sollte mein Problem lösen :)

    Edit: Jetzt habe ich allerdings ein weiteres Problem. Habe zum speichern nun deinen Code verwendet und bekomme nachdem ich die Farben als Bild malen lassen hab und speichern möchte den Fehler :

    bmp.Save("c:\Desktop\test.jpg", Imaging.ImageFormat.Jpeg) <-- Allgemeiner Fehler in GDI+

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „TomTheCoder15“ ()

    TomTheCoder15 schrieb:

    Allgemeiner Fehler in GDI+
    ist etwas zu allgemein.
    Kannst Du mal den kompletten Code posten?
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!

    VB.NET-Quellcode

    1. Public Class Form1
    2. Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
    3. ColorDialog1.ShowDialog()
    4. End Sub
    5. Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
    6. ColorDialog2.ShowDialog()
    7. End Sub
    8. Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
    9. ColorDialog3.ShowDialog()
    10. End Sub
    11. Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click
    12. ColorDialog4.ShowDialog()
    13. End Sub
    14. Private Sub PictureBox5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox5.Click
    15. ColorDialog5.ShowDialog()
    16. End Sub
    17. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    18. PictureBox1.BackColor = ColorDialog1.Color
    19. PictureBox2.BackColor = ColorDialog2.Color
    20. PictureBox3.BackColor = ColorDialog3.Color
    21. PictureBox4.BackColor = ColorDialog4.Color
    22. PictureBox5.BackColor = ColorDialog5.Color
    23. PictureBox6.BackColor = ColorDialog6.Color
    24. Panel1.BackColor = ColorDialog6.Color
    25. Panel2.BackColor = ColorDialog6.Color
    26. Panel3.BackColor = ColorDialog6.Color
    27. Panel4.BackColor = ColorDialog6.Color
    28. Panel5.BackColor = ColorDialog6.Color
    29. PictureBox7.BackColor = ColorDialog6.Color
    30. If TrackBar1.Value = 0 Then
    31. Panel2.Location = New Point(116, 0)
    32. Panel3.Location = New Point(232, 0)
    33. Panel4.Location = New Point(348, 0)
    34. Panel5.Location = New Point(464, 0)
    35. Panel1.Height = 110
    36. Panel1.Width = 110
    37. PictureBox1.Location = New Point(5, 5)
    38. Panel2.Height = 110
    39. Panel2.Width = 110
    40. PictureBox2.Location = New Point(5, 5)
    41. Panel3.Height = 110
    42. Panel3.Width = 110
    43. PictureBox3.Location = New Point(5, 5)
    44. Panel4.Height = 110
    45. Panel4.Width = 110
    46. PictureBox4.Location = New Point(5, 5)
    47. Panel5.Height = 110
    48. Panel5.Width = 110
    49. PictureBox5.Location = New Point(5, 5)
    50. Panel6.Width = 575
    51. Panel6.Height = 110
    52. PictureBox6.Visible = False
    53. End If
    54. If TrackBar1.Value = 2 Then
    55. Panel6.Width = 492
    56. Panel6.Height = 100
    57. End If
    58. End Sub
    59. Private Sub ColorSwitch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorSwitch.Click
    60. ColorDialog6.ShowDialog()
    61. End Sub
    62. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    63. Using bmp = New Bitmap(100 * 5, 100)
    64. Dim g = Graphics.FromImage(bmp)
    65. g.DrawImage(PictureBox1.Image, New Point(0 * 100, 0))
    66. g.DrawImage(PictureBox2.Image, New Point(1 * 100, 0))
    67. g.DrawImage(PictureBox3.Image, New Point(2 * 100, 0))
    68. g.DrawImage(PictureBox4.Image, New Point(3 * 100, 0))
    69. g.DrawImage(PictureBox5.Image, New Point(4 * 100, 0))
    70. bmp.Save("c:\Desktop\test.png", Imaging.ImageFormat.Png)
    71. End Using
    72. End Sub
    73. Private Sub PictureBox9_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox9.MouseEnter
    74. PictureBox9.Visible = False
    75. End Sub
    76. Private Sub ColorSwitch_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorSwitch.MouseLeave
    77. PictureBox9.Visible = True
    78. End Sub
    79. Private Sub PictureBox8_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox8.MouseEnter
    80. PictureBox8.Visible = False
    81. End Sub
    82. Private Sub PictureBox10_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox10.MouseLeave
    83. PictureBox8.Visible = True
    84. End Sub
    85. Private Sub PictureBox10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox10.Click
    86. TrackBar1.Value += 1
    87. '1
    88. If TrackBar1.Value = 0 Then
    89. Panel2.Location = New Point(119, 28)
    90. Panel3.Location = New Point(235, 28)
    91. Panel4.Location = New Point(351, 28)
    92. Panel5.Location = New Point(467, 28)
    93. Panel1.Height = 110
    94. Panel1.Width = 110
    95. PictureBox1.Location = New Point(5, 5)
    96. Panel2.Height = 110
    97. Panel2.Width = 110
    98. PictureBox2.Location = New Point(5, 5)
    99. Panel3.Height = 110
    100. Panel3.Width = 110
    101. PictureBox3.Location = New Point(5, 5)
    102. Panel4.Height = 110
    103. Panel4.Width = 110
    104. PictureBox4.Location = New Point(5, 5)
    105. Panel5.Height = 110
    106. Panel5.Width = 110
    107. PictureBox5.Location = New Point(5, 5)
    108. End If
    109. '2
    110. If TrackBar1.Value = 1 Then
    111. Panel2.Location = New Point(Panel2.Location.X - 9, Panel2.Location.Y + 0)
    112. Panel3.Location = New Point(Panel3.Location.X - 18, Panel3.Location.Y + 0)
    113. Panel4.Location = New Point(Panel4.Location.X - 27, Panel4.Location.Y + 0)
    114. Panel5.Location = New Point(Panel5.Location.X - 36, Panel5.Location.Y + 0)
    115. End If
    116. '3
    117. If TrackBar1.Value = 2 Then
    118. Panel2.Location = New Point(Panel2.Location.X - 9, Panel2.Location.Y + 0)
    119. Panel3.Location = New Point(Panel3.Location.X - 18, Panel3.Location.Y + 0)
    120. Panel4.Location = New Point(Panel4.Location.X - 27, Panel4.Location.Y + 0)
    121. Panel5.Location = New Point(Panel5.Location.X - 36, Panel5.Location.Y + 0)
    122. Panel1.Height = 100
    123. Panel1.Width = 100
    124. PictureBox1.Location = New Point(0, 0)
    125. Panel2.Height = 100
    126. Panel2.Width = 100
    127. PictureBox2.Location = New Point(0, 0)
    128. Panel3.Height = 100
    129. Panel3.Width = 100
    130. PictureBox3.Location = New Point(0, 0)
    131. Panel4.Height = 100
    132. Panel4.Width = 100
    133. PictureBox4.Location = New Point(0, 0)
    134. Panel5.Height = 100
    135. Panel5.Width = 100
    136. PictureBox5.Location = New Point(0, 0)
    137. If CheckBox1.Checked = True Then
    138. PictureBox6.Visible = False
    139. Else
    140. PictureBox6.Visible = True
    141. End If
    142. End If
    143. If TrackBar1.Value = 3 Then
    144. TrackBar1.Value = 0
    145. End If
    146. End Sub
    147. Private Sub PictureBox11_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox11.MouseEnter
    148. PictureBox11.Visible = False
    149. End Sub
    150. Private Sub PictureBox12_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox12.MouseLeave
    151. PictureBox11.Visible = True
    152. End Sub
    153. Private Sub PictureBox12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox12.Click
    154. If CheckBox1.Checked = True Then
    155. CheckBox1.Checked = False
    156. Panel1.BackColor = Color.Black
    157. Panel2.BackColor = Color.Black
    158. Panel3.BackColor = Color.Black
    159. Panel4.BackColor = Color.Black
    160. Panel5.BackColor = Color.Black
    161. Else
    162. CheckBox1.Checked = True
    163. Panel1.BackColor = Color.Transparent
    164. Panel2.BackColor = Color.Transparent
    165. Panel3.BackColor = Color.Transparent
    166. Panel4.BackColor = Color.Transparent
    167. Panel5.BackColor = Color.Transparent
    168. End If
    169. End Sub
    170. Private Sub PictureBox13_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox13.MouseEnter
    171. PictureBox13.Visible = False
    172. End Sub
    173. Private Sub PictureBox14_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox14.MouseLeave
    174. PictureBox13.Visible = True
    175. End Sub
    176. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    177. Dim bmp = New Bitmap(100, 100)
    178. Dim g = Graphics.FromImage(bmp)
    179. g.Clear(PictureBox1.BackColor)
    180. PictureBox1.Image = bmp
    181. Dim bmp2 = New Bitmap(100, 100)
    182. g = Graphics.FromImage(bmp2)
    183. g.Clear(PictureBox2.BackColor)
    184. PictureBox2.Image = bmp2
    185. Dim bmp3 = New Bitmap(100, 100)
    186. g = Graphics.FromImage(bmp3)
    187. g.Clear(PictureBox3.BackColor)
    188. PictureBox3.Image = bmp3
    189. Dim bmp4 = New Bitmap(100, 100)
    190. g = Graphics.FromImage(bmp4)
    191. g.Clear(PictureBox4.BackColor)
    192. PictureBox4.Image = bmp4
    193. Dim bmp5 = New Bitmap(100, 100)
    194. g = Graphics.FromImage(bmp5)
    195. g.Clear(PictureBox5.BackColor)
    196. PictureBox5.Image = bmp5
    197. 'Dim scr As Bitmap
    198. 'Dim w As Integer = Me.Width
    199. 'Dim h As Integer = Me.Height
    200. 'scr = New Bitmap(w, h)
    201. 'Me.DrawToBitmap(scr, Rectangle.FromLTRB(0, 0, w, h))
    202. 'SaveFileDialog1.ShowDialog()
    203. 'If SaveFileDialog1.FileName = "" Then
    204. ' SaveFileDialog1.ShowDialog()
    205. 'Else
    206. ' scr.Save(SaveFileDialog1.FileName)
    207. 'End If
    208. End Sub
    209. Private Sub PictureBox15_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox15.MouseEnter
    210. PictureBox15.Visible = False
    211. End Sub
    212. Private Sub PictureBox16_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox16.MouseLeave
    213. PictureBox15.Visible = True
    214. End Sub
    215. Private Sub PictureBox16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox16.Click
    216. 'PictureBox1.BackColor = Color.White
    217. 'PictureBox2.BackColor = Color.White
    218. 'PictureBox3.BackColor = Color.White
    219. 'PictureBox4.BackColor = Color.White
    220. 'PictureBox5.BackColor = Color.White
    221. 'Panel1.BackColor = Color.Black
    222. 'Panel2.BackColor = Color.Black
    223. 'Panel3.BackColor = Color.Black
    224. 'Panel4.BackColor = Color.Black
    225. 'Panel5.BackColor = Color.Black
    226. 'Panel6.BackColor = Color.Black
    227. ColorDialog1.Color = Color.White
    228. ColorDialog2.Color = Color.White
    229. ColorDialog3.Color = Color.White
    230. ColorDialog4.Color = Color.White
    231. ColorDialog5.Color = Color.White
    232. ColorDialog6.Color = Color.Black
    233. End Sub
    234. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    235. ColorDialog1.Color = Color.Lime
    236. ColorDialog2.Color = Color.White
    237. ColorDialog3.Color = Color.Lime
    238. ColorDialog4.Color = Color.White
    239. ColorDialog5.Color = Color.Lime
    240. End Sub
    241. End Class
    @TomTheCoder15
    1. Pack den Code bitte in einen
      Spoiler
      Spoiler

    2. poste bitte noch die Form1.Designer.vb
    =============

    VB.NET-Quellcode

    1. bmp.Save("c:\Desktop\test.png", Imaging.ImageFormat.Png)
    Kann es sein, dass es bei Dir das Verzeichnis c:\Desktop\ nicht gibt?
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „RodFromGermany“ ()

    bmp.Save("c:\Desktop\test.png", Imaging.ImageFormat.Png)
    -> Sieht der Desktop Pfad nicht normalerwiese irgend wie so in der Richtung aus C:\Users\Name\Desktop ?
    "Gib einem Mann einen Fisch und du ernährst ihn für einen Tag. Lehre einen Mann zu fischen und du ernährst ihn für sein Leben."

    Wie debugge ich richtig? => Debuggen, Fehler finden und beseitigen
    Wie man VisualStudio nutzt? => VisualStudio richtig nutzen