![]() |
|
Error when drawing a scaled bitmap |
GudPiggeh
Member #16,492
July 2016
|
I'm trying to load an image that is scaled based on a constant TILESIZE by taking the original image file and loading it to an ALLEGRO_BITMAP then using al_draw_scaled_bitmap to draw it to the final image 193void tile::imageLoad() {
194 std::cout << "Loading " << fileName << std::endl;
195 ALLEGRO_BITMAP *unresizedImage = al_load_bitmap(fileName.c_str());
196 ALLEGRO_BITMAP *prevTarget = al_get_target_bitmap();
197 al_set_target_bitmap(image);
198 int origHeight = al_get_bitmap_height(unresizedImage);
199 int origWidth = al_get_bitmap_width(unresizedImage);
200 int finalHeight = ( (float)origHeight / (float)origWidth * TILESIZE);
201 image = al_create_bitmap(TILESIZE, finalHeight);
202 al_draw_scaled_bitmap(unresizedImage, 0, 0, origWidth, origHeight, 0, 0, TILESIZE, finalHeight, 0);
203 std::cout << "Created Empty Bitmap";
204 al_set_target_bitmap(prevTarget);
205 if (!image) {
206 al_show_native_message_box(display, "Error", "Error", fileName.c_str(), NULL, ALLEGRO_MESSAGEBOX_ERROR);
207 al_destroy_display(display);
208 return;
209 } std::cout << "Loaded " << fileName << std::endl;
210}
but instead it gives Assertion failed: src, file C:\dev\allegro_winpkg\universal\allegro\src\transformations.c, line 32 to the console and aborts. I've confirmed that origWidth, origHeight, and finalHeight have the correct values. The code below succeeds. 182void imageMap::imageLoad() {
183 std::cout << "Loading " << fileName << std::endl;
184 image = al_load_bitmap(fileName.c_str()); //fileName.c_str()
185 if (!image) {
186 al_show_native_message_box(display, "Error", "Error", fileName.c_str(), NULL, ALLEGRO_MESSAGEBOX_ERROR);
187 al_destroy_display(display);
188 return;
189 } std::cout << "Loaded " << fileName << std::endl;
190}
Can anyone help me with this? |
Polybios
Member #12,293
October 2010
|
It seems you're calling al_set_target_bitmap(image) when it still uninitialized, i.e. before image = al_create_bitmap(TILESIZE, finalHeight). |
GudPiggeh
Member #16,492
July 2016
|
Thanks, that worked. |
|