Mintoris

Author Topic: Understanding Bitmaps and Screens  (Read 2732 times)

barryem

  • Full Member
  • ***
  • Posts: 17
Understanding Bitmaps and Screens
« on: Aug 12, 2012, 11:15 AM »
I wonder if I could get some discussion of the way bitmaps and portions of bitmaps and screen size and scale work together.

I'm trying to write a little program that breaks a bitmap image into segments and scrambles them and then let's me swap pieces to re-assemble the image.  Everything I try seems to work okay but I'm having a lot of trouble understanding how to put pieces just where I want them.  I can do it by playing with the coordinates till things fit and that's workable but not graceful and it changes when I try it on a different device.  By using setscale and setting it to the screen size of the device the program is currently running on it smooths out but I don't want to have to do that unless I just have to.

I'd like to have some understanding of the relationship between SetScale, DrawBitmap and CopyBitmap and how the cropping parameters of CopyBitmap relate to SetScale when only a portion of the bitmap is copied, and of how that relates to the scale factor of DrawBitmap.

Also have I overlooked any functions closely related to these?

I realize this is a confused bunch of questions but that's only because I'm confused.  I first decided to wait before asking about this until I can frame a coherent question but I just don't seem to be able to get to that point.

Any explanations and tips will be greatly appreciated.
Barry

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Understanding Bitmaps and Screens
« Reply #1 on: Aug 12, 2012, 07:03 PM »
I remember having trouble phrasing the SetScale command documentation.

The SetScale command was added to simplify writing graphics programs for any screen size. All the math required to scale graphics is done automatically when you use SetScale correctly.

What you do is decide what resolution you are going to work in and then all screens become that size.

For simple graphics I may use:

SetScale 100,200

This way when I program I can think of the screen coordinates in percentage (sort of). SetScale 100,200 assumes that the screen is (very) roughly twice as tall as wide. Point 50,100 will always put a point at the center of the screen.

The problem with doing all the math internally is that I had to make some scaling decisions for you.  It is easy enough to scale 100 to 480 and 200 to 800, but I had to find a way to scale circles, text and bitmaps that did not skew them.  A special diagonal ratio is calculated to scale circles, text and bitmaps.

  diagonal ratio = actual diagonal screen length in pixels / SetScale diagonal length

The diagonal ratio is then used to scale the circle radius, text font size and Bitmaps (both x and y).

This system works fairly well, but it is not pixel perfect.

For pixel perfect graphics you might have to not use the SetScale command at all and do all the math yourself from the ScreenX() and ScreenY() functions.

Also, if you try to load a bitmap that is larger than the screen, it will be scaled down to the current screen size.  This is required to prevent out of memory errors.  This feature also allows you to load and display very large bitmaps that would not normally be possible.
« Last Edit: Aug 12, 2012, 07:13 PM by Chuck »

barryem

  • Full Member
  • ***
  • Posts: 17
Re: Understanding Bitmaps and Screens
« Reply #2 on: Aug 12, 2012, 07:30 PM »
Thanks.  That's helpful information and good to know.

So when I load a bitmap it's either it's original size or scaled in some way to fit within the screen if it's larger than the screen?  Is it scaled using the screen diagonal compared with it's own diagonal?  I'd like to understand this in more detail if that's possible.

What about the CopyBitmap command?  Let's say I copy portions of a bitmap into 16 smaller bitmaps to create a 4x4 grid which, together, make up the full bitmap.  That's something like what I plan to do.  How do I know the size of the portions?  When I use GetBitmapWidth() and GetBitmapHeight() functions do I get the the actual physical size of one of the small bitmaps in memory or as it will appear on the screen?  Is that affected by SetScale?

I think either the documentation doesn't specify just what the numbers mean or I'm missing it.  The same with the other bitmap commands.  When I set the scale do I change the size of the bitmaps?

I feel a little silly asking this stuff because it seems like I should be able to figure it out but I haven't been able to so I'm left with asking.

Thanks,
Barry



Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Understanding Bitmaps and Screens
« Reply #3 on: Aug 12, 2012, 08:02 PM »
When you are getting the width and height and copying a bitmap you will always be using the actual bitmap dimensions.  SetScale only affects the drawing surface (usually the screen). Bitmaps are definitely not changed by a SetScale command. They get scaled to the screen during the draw, but the bitmap in memory never gets changed.

When copying, the image being copied is cropped to the target bitmap dimensions. So if you do a copy and part of the image being copied is outside the target bitmap it is cropped.

And yes, I use the same diagonal scaling (ratio = physical screen diagonal / image diagonal) when loading a bitmap that is too big. It just works so well. In fact the ratio is used to determine if scaling is needed. If ratio < 1 (image is bigger than the screen) the image will be scaled using that ratio.
« Last Edit: Aug 12, 2012, 08:23 PM by Chuck »

barryem

  • Full Member
  • ***
  • Posts: 17
Re: Understanding Bitmaps and Screens
« Reply #4 on: Aug 15, 2012, 07:25 AM »
Thanks.  That helps a bit.

I've been playing with doing different things with bitmaps and I think I'm beginning to understand it now.  I think what was throwing me was that I wasn't considering bitmap scale, not SetScale.  Things are starting to fall into place a bit now.

Barry

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: Understanding Bitmaps and Screens
« Reply #5 on: Aug 15, 2012, 12:50 PM »
Let me know where the documentation could be improved.  I've been going over bitmaps and graphics trying to clarify a few things.

-Chuck
« Last Edit: Aug 15, 2012, 12:53 PM by Chuck »