Drawing a Bitmap

Hi, I'm pretty much new to C++ but i have a general understanding of the basics

At the moment, I'm just trying to find out how to actually draw a bitmap to a window, I'm using the paintlib library.

I'm using the provided examplar code to decode and image and make a bitmap class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  #include "anydec.h"
  #include "winbmp.h"

  // Create a decoder.
  PLAnyPicDecoder Decoder;

  // Create a bitmap object.
  PLWinBmp Bmp;

  // Tell the decoder to fill
  // the bitmap object with data.
  Decoder.MakeBmpFromFile ("foo.jpg", &Bmp);

  // Do something with the bitmap.
  Bmp.Draw (pdc, 0, 0);


What I just wanted to know was whether the Bmp.draw is an actual C++ function, or one within the library, so whether you'd be able to advise me as to how to draw the image from the bitmap object containing decoded data to a window (as i mentioned) or would there be a better command to use,
thanks in advance.
I'm not familiar with the paintlib library, but Bmp.draw() definitely is a function in that library PLWinBmp is the bitmap class which is included in that library. And draw is a method/member function inside that class. Which means that you don't need to know how it works. It should do what it's supposed to do. That's the idea behind encapsulation I mean.

PLAnyDecoder is a class as well and it has a method/member function that is MakeBmpFromFile() which probably means that it will make a bitmap from the file location you entered and store it inside the PLWinBmp variable you created. So you need this to load your bitmap image into the bitmap variable you created I think.

So lets say you have a bitmap image on your computer you want to load. You'd probably do something like.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
PLAnyDecoder myDecoder; // the variable name can be anything
PLWinBmp myBitmap; // variable name can be anything as well

// myBitmap doesn't have any image in it so you want to load the image
// you want to use

/*
     I think this function would decode the image file into bmp file format,
     and place the data needed into myBitmap variable so you can now do
     something with it. So this means that it doesn't matter what kind of
     image file you enter may it be .png file, .jpg file or .gif it will decode it
     and load it into the myBitmap object. Probably not needed if your image
     is already in .bmp format.
*/

myDecoder.MakeBmpFromFile("C:\My Documents\myImage.jpg", &myBitmap);

myBitmap.Draw(pdc, 0, 0);   // probably self explanatory? draws bitmap on screen at x, y position? 


pdc is probably a variable that refers to the device context. I hope that helps explain it a bit more :P
Last edited on
Thanks for the help, but I was just wondering as a side note.
I looked around for a graphics library and fount paintlib, but is this really the 'best' thing to use.
I know there may not be a best library, but I'm aiming to:

1)Display an image from a file into a window(which i've sussed out how to display), the image name being determined by a variable
2) I want to be able to repeat this process, removing the previous image and displaying a new one from a variable that will be changed elsewhere in the script.
3) Also preferably, the images would be .png format.

I've looked around, but I just don't know really where I should start with trying to achieve this and whether paintlib would be the best choice for the task at hand.

I'd be greatful for any advice.
(Sorry about the delayed reply)
Well In my opinion it seems like the paintlib library is pretty good for doing that. Just looking at the example code you posted a while back it's clear the library is using classes which makes it far less confusing I think. Because all the functions that should manipulate the bitmap would already be inside PLWinBmp for certain. You'll just have to read a documentation about all the methods you can use. So like for removing the image there is probably a member function for it inside the PLWinBmp class as well so you'd probably just have to do something like.

 
myBitmap.remove();


or even possibly

 
myBitmap.clear();


That really depends on what methods are inside it though, so you can't really use those examples but it's possible that is has one of those. You really would have to read the documentation to know what methods are available to you for that class, then you'd be able to know how to use it to do what you want to do with the bitmap. ^_^

There are probably others you can use if you want a more procedural approach rather than an object oriented approach.

One would be the allegro game library, it's open source so you can download it for free. You can also try studying opengl or direct x. However that takes a lot longer to get any results at. Because you'll have to learn about setting up the screen resolution, setting up the bits per pixels and other technical stuff which you would have to do manually instead of being handled for you automatically by a game library.
Last edited on
Topic archived. No new replies allowed.