C++ builder 6 как открыть файлы png
В архиве лежит пример и все необходимые файлы
Я либы и хидеры бросил в папку с проектом и все работает
не хотел засорять bilder так как подключен GDI+ который
открывает и png в том числе Позже может сделаю загрузчик
текстур png в opengl
=
=
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
// include the PNGDIB sources (in 'pngdib' folder)
#include "pngdib.h"
// link with the ZLIB library (in 'zlib' folder)
#pragma link "zlib.lib"
// link with the LIBPNG library (in 'lpng108' folder)
#pragma link "libpng.lib"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
if (OpenDialog1->Execute())
{
TCHAR filename[MAX_PATH];
lstrcpyn(filename, OpenDialog1->FileName.c_str(), MAX_PATH);
// declare and clear the PNGD_P2DINFO structure
PNGD_P2DINFO png2dib;
memset(&png2dib, 0, sizeof(PNGD_P2DINFO));
// initialize the structure size and filename
png2dib.structsize = sizeof(PNGD_P2DINFO);
png2dib.pngfn = filename;
// convert from PNG to DIB
if (read_png_to_dib(&png2dib) == PNGD_E_SUCCESS)
{
Graphics::TBitmap* Bitmap = Image1->Picture->Bitmap;
Bitmap->Width = png2dib.lpdib->biWidth;
Bitmap->Height = png2dib.lpdib->biHeight;
HBITMAP hBmp = Bitmap->ReleaseHandle();
HDC hDC = Canvas->Handle;
try
{
//
// TODO: add palette support...
//
// convert from DIB to TBitmap
SetDIBits(
hDC, hBmp, 0,
png2dib.lpdib->biHeight, png2dib.bits,
reinterpret_cast<LPBITMAPINFO>(png2dib.lpdib),
DIB_RGB_COLORS
);
}
catch (...)
{
Bitmap->Handle = hBmp;
GlobalFree(png2dib.lpdib);
}
Bitmap->Handle = hBmp;
GlobalFree(png2dib.lpdib);
}
}
}
//---------------------------------------------------------------------------
=
=
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Buttons.hpp>
#include <Dialogs.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TOpenDialog *OpenDialog1;
TPanel *Panel1;
TSpeedButton *SpeedButton1;
TPanel *Panel2;
TImage *Image1;
void __fastcall SpeedButton1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
=
|