Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » saving a bitmap question

This thread is locked; no one can reply to it. rss feed Print
saving a bitmap question
Scooter
Member #16,799
January 2018

Hi again:
I have a question about saving bitmaps. I can save the backbuffer
with no problem. My question is how to save just the bitmap without
saving the complete backbuffer?

temp_image = al_create_bitmap(screen_width, working_screen_height);
al_set_target_bitmap(temp_image);
al_draw_bitmap(al_get_backbuffer(display), 0, 0, 0);

al_save_bitmap("sample.png", temp_image);

al_destroy_bitmap(temp_image);

This will save the complete backbuffer

Thanks for your time!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Scooter
Member #16,799
January 2018

Hi Edgar:
Thanks for the tip. It seems my problem stems from the fact that
I do not know how to get the width and height of the rotated bitmap.
After rotation I use al_get bitmap_width and al_get_bitmap_height and
it returns the width and height of the original bitmap, not the rotated
one. If you could give me a hint on this I believe I could figure the
rest out on my own.

Thanks!

Dizzy Egg
Member #10,824
March 2009
avatar

The concept of saving a rotated bitmap doesn’t really make much sense, all bitmaps are square/rectangle. You could either save a square, which has a height and width of the biggest original w/h (ie, a 320x240 bitmap would be saved as 320x320), or you could add some logic to determine the minimum rectangle size required based on rotation…

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Scooter
Member #16,799
January 2018

Hi Edgar:
After seeing your reply, I know exactly what to do:

I know the 4 corners of the image before rotating. I
can rotate the 4 corners for the new positions. If I
take the 2 extremes I will know the width and height.

Very good! Thanks for the tip!

Go to: