Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to read images other than *.bmp.

Status
Not open for further replies.

HuntsvilleRob

Programmer
Nov 3, 2010
26
0
0
US
Hello. I have written code that loads a bitmap file into a Graphics::TBitmap object.

Graphics::TBitmap* MyBitmap = new Graphics::TBitmap();
MyBitmap->LoadFromFile("mypicture.bmp");

I now need to be able to open other image types like tif and jpg and put them into a Graphics::TBitmap object. Can anyone explain how this can be done? I am using Borland C++ Builder 6. As far as I can see, this compiler only has the ability to read bmp files and no other. Thanks for any help.
-Rob
 
I can't find support for tif images.

There are at least two ways to go back and forth betwixt bitmaps and other image related objects (TImage, TJPEGImage, TGIFImage) depending on whether there is an embedded TBitmap object or a TCanvas object. I always have to fiddle with the syntax, so here goes...

In the header...
Code:
#include <jpeg.hpp>

The actual code...
Code:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	if (OpenDialog1->Execute())
	{
		TJPEGImage *jpegImage = new TJPEGImage;
		Graphics::TBitmap* MyBitmap = new Graphics::TBitmap;
		int iWidth, iHeight;

		try
		{
			jpegImage->LoadFromFile(OpenDialog1->FileName);
			MyBitmap->Width = jpegImage->Width;
			MyBitmap->Height = jpegImage->Height;
			try
			{
				MyBitmap->Canvas->Draw(0, 0, jpegImage);
				iWidth = MyBitmap->Width;
				iHeight = MyBitmap->Height;
			}
			catch (...)
			{
			}
		}
		catch (...)
		{
		}
		delete jpegImage;
		delete MyBitmap;
	}
}

Something to keep in mind; no version before Builder 2009 shipped with support for PNG (you didn't ask for PNGs, but you will be prepared when the day comes). With some effort older Delphi code (especially for Builder 6) can be installed into your IDE to support PNG images.

Steve.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top