-4

Quick question, is there a way to show an image(ex. bmp) from file using C? It's not in graphics.h apparently, and I can't use Allegro because it does not support Borland(or so I've read). I need to use the very old compiler for a school project. I would like to ask if anyone had any experience of doing this using other libraries? If yes, which library was it? Thanks a lot.

Johan
  • 74,508
  • 24
  • 191
  • 319
berdi9
  • 23
  • 12
  • 2
    Graphics are not part of C; any graphics libraries are specific to a platform. When compiler/environment you are using, or have available, will determine how you might accomplish this, so you'll need to spell them out. – Scott Hunter Mar 15 '14 at 00:59
  • We'll be using Turbo C on Win7. And our little project is plotting points on the world map. We need to have the map image displayed as we plot the points, but we don't know how to display an image. It sounds so dumb, I wish I knew the answer to this. – berdi9 Mar 15 '14 at 01:09
  • @CIB added answer check it out if I miss something comment me ... – Spektre Apr 01 '14 at 07:55
  • btw if you use turbo c++ on w7 (BDS2006) like me then it is worth loking at this http://stackoverflow.com/a/18016392/2521214 will spare you a lot of headaches ... – Spektre Apr 01 '14 at 07:59
  • Don't use TurboC++ in 2017 (or even 2014). Use recent standard conforming compilers (like [GCC](http://gcc.gnu.org/) or [Clang/LLVM](http://clang.llvm.org/)....) for C11 or C++14. – Basile Starynkevitch May 20 '17 at 06:21

1 Answers1

0

I hope you have visual (windows) borland like Borland C++ builder 3++ or turbo C++ not the MS DOS one. in that case it is quite easy because you can use bitmap which is part of VCL so no additional include is needed.

  • here you can find some hints on rendering under borland

now how to visualize picture from file to your window:

// this will create and load your bitmap
Graphics::TBitmap *bmp=new Graphics::TBitmap;
bmp->LoadFromFile("image.bmp");
bmp->HandleType=bmDIB;
bmp->PixelFormat=pf32bit;

// on paint you can draw your image to form,paintbox,another bitmap or whatever...
Form1->Canvas->Draw(0,0,bmp); // also you can use stretch draw or copy rectangle GDI functions

// before exiting delete the bmp
delete bmp;

[Notes]

You can also save image by bmp->SaveToFile("out.bmp"); In case you need jpg then add:

#include <jpeg.hpp>

TJPEGImage *jpg=new TJPEGImage;
jpg->LoadFromFile("image.jpg");
bmp->Assign(jpg);
delete jpg;

this will load jpg to your bmp also you can save jpg as well in the same way. Beware older Borlands has a bug in TJPEGImage and will crash if the jpg resolution is too big**

Community
  • 1
  • 1
Spektre
  • 49,595
  • 11
  • 110
  • 380