Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Is it possible to read picturefiles with many pictures in one, and read from pixel x to y when certain conditions are met, and from y to z at other conditions?

 

Hope you understand what im meaning.

Posted

thank you...

Does this code load an image from file?

 

To make a sprite image: How do you load it then?

 

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10

 

here are 10 images in one .bmp file... all the small images are 32x32

how can you load picture 1, into image 1, picture 2 into image 2?

  • *Gurus*
Posted

Dim imgMain As Image = Image.FromFile("C:\mybitmap.bmp")

You shouldn't be loading more Image objects after this. Use the DrawImage method I posted above to draw the individual sprites where they need to go. DrawImage allows you to specify which part of a larger image you want to paint.

Posted

If you're looking to do animation try this:

 

Paste this into a project with Timer and Button controls:

Imports System.Drawing.Image

Public Class Form1
   Inherits System.Windows.Forms.Form

   Private imgAnim As Image
   Private gr As Graphics

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Timer1.Enabled = True
   End Sub

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

       imgAnim = Image.FromFile(Application.StartupPath & "\explosion.bmp")
       gr = Me.CreateGraphics

   End Sub

   Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

       Static iFrame As Byte = 0

       Dim rect As New Rectangle(iFrame * 65, 0, 65, 65)

       gr.DrawImage(imgAnim, 50, 50, rect, GraphicsUnit.Pixel)

       iFrame += 1
       If iFrame = 6 Then iFrame = 0

   End Sub
End Class

Place the attached graphic in the apps folder. Click the button to start the animation.

 

If you're not doing animation the theory is still the same. Use a rectangle to get whichever sprite you want.

explosion.bmp

Here's what I'm up to.
  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...