Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

VB.net Pixel Format "DontCare" (rendering example)


RyokuHasu
 Share

Recommended Posts

So I've been working with the GDI+ for VB.NET (a built-in version of EO's graphic dependencies). and I finnaly got it to do dynamic cropping and masking color as well as RENDERING instead of loading!!!!! I did this in class while the rest were going over what a sub and a function is. LOL

The thing is that there is a  Pixel Format called "DontCare" and I thought that was kinda funny lol

Anyway here is a basic example of rendering with VB.net

I know it might look a bit inefficient but it's just to show the basics of the graphic rendering of VB.net for any willing to go in that direction.

Also, the bmp files are loaded from the same folder in this example.

```
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

        'Create a new Bitmap image and load the first image to it (a background)
        Dim myBitmap As New Bitmap(System.AppDomain.CurrentDomain.BaseDirectory() + "2.bmp")

        'Create an image object at the location you want it to render
        Dim g As Graphics = picDraw.CreateGraphics

        'Draw the loaded image to the object
        g.DrawImage(myBitmap, 1, 1)

        'load the second image to the bitmap image (an EO Character sprite)
        myBitmap = New Bitmap(System.AppDomain.CurrentDomain.BaseDirectory() + "1.bmp")

        'Get the masking color from the top left pixel
        myBitmap.MakeTransparent(myBitmap.GetPixel(1, 1))

        'Declare a rectangle of what you want to crop out of the image (dynamically)
        Dim crop As New Rectangle(1, 1, (myBitmap.Width / 4), (myBitmap.Height / 4))

        'load a cropped copy of the bitmap to the bitmap itself
        myBitmap = myBitmap.Clone(crop, Imaging.PixelFormat.DontCare)

        'Draw the image on top of the current image
        g.DrawImage(myBitmap, 1, 1)

        'Load the character sprite again for another crop
        myBitmap = New Bitmap(System.AppDomain.CurrentDomain.BaseDirectory() + "1.bmp")

        'Get the mask
        myBitmap.MakeTransparent(myBitmap.GetPixel(1, 1))

        'set a rectangle for the crop of the Left Facing, step1 frame(again dynamically)
        crop = New Rectangle((myBitmap.Width / 4), (myBitmap.Height / 4), (myBitmap.Width / 4), (myBitmap.Height / 4))

        'set the image as the cropped clone
        myBitmap = myBitmap.Clone(crop, Imaging.PixelFormat.DontCare)

        'Draw the image ontop of the existing, beside the first crop of the character
        g.DrawImage(myBitmap, (myBitmap.Width / 4), 1)

    End Sub

```
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...