Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [UPDATED] convert graphics.image to sfml.graphics.image  (Read 5273 times)

0 Members and 1 Guest are viewing this topic.

renner96

  • Newbie
  • *
  • Posts: 3
    • View Profile
[UPDATED] convert graphics.image to sfml.graphics.image
« on: July 31, 2009, 09:05:14 pm »
Hi,
i want to convert a graphics.image, wich I converted with the following code to a byte array , into a SFML.Graphics.Image.
Code: [Select]

Public Function imageToByteArray(ByVal imageIn As System.Drawing.Image) As Byte()
    Dim ms As MemoryStream = New MemoryStream()
    imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif)
    Return ms.ToArray()
End Function

I hope you can help me. Can i do it without the array?
Thank You
renner96

PS: My English isnĀ“t very good. I`m only on the 7th grade on a German grammar school.


//edit: i tried it with a memorystream, too, but i got an exeption: Failed to load image from memory

//edit2: is there a function to make the image of an graphics.bitmap???

renner96

  • Newbie
  • *
  • Posts: 3
    • View Profile
[UPDATED] convert graphics.image to sfml.graphics.image
« Reply #1 on: July 31, 2009, 10:18:57 pm »
Can somebody change the following code that it could be used with sfml directly


Code: [Select]
   Private Shared Function RotateImageByAngle(ByVal oldBitmap As System.Drawing.Image, ByVal angle As Single) As Bitmap
        Dim newBitmap As Bitmap
        Dim graphics1 As Graphics
        If oldBitmap.Width >= oldBitmap.Height Then
            newBitmap = New Bitmap(oldBitmap.Width * 2, oldBitmap.Width * 2)
        Else
            newBitmap = New Bitmap(oldBitmap.Height * 2, oldBitmap.Height * 2)
        End If
        graphics1 = Graphics.FromImage(newBitmap)
        graphics1.TranslateTransform(CSng(oldBitmap.Width) / 2, CSng(oldBitmap.Height) / 2)
        graphics1.RotateTransform(angle)
        graphics1.TranslateTransform(-CSng(oldBitmap.Width) / 2, -CSng(oldBitmap.Height) / 2)
        graphics1.DrawImage(oldBitmap, New Point(0, 0))
        Return newBitmap
    End Function


PS: the code is the reason, why i wanted to change the image into sfml

rpgmaker

  • Newbie
  • *
  • Posts: 38
    • View Profile
[UPDATED] convert graphics.image to sfml.graphics.image
« Reply #2 on: August 02, 2009, 08:32:01 am »
The Sfml.Image class take a parameter for a stream and the MemoryStream is also valid. So you don't need to use a byte array.