LoginSignup
0
1

More than 5 years have passed since last update.

c++ builder XE4, 10.2 Tokyo > TImage > 画像のファイル拡張子(.png)が不明です

Last updated at Posted at 2016-10-20
動作環境
C++ Builder XE4
RAD Studio 10.2 Tokyo Update 2 (追記: 2017/12/28)

現象

TImageにpngファイルを読込もうとしていた。

Unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    Image1->Picture->LoadFromFile(L"site-logo.png");
}
//---------------------------------------------------------------------------

実行すると

qiita.png

対策

cppファイルに以下のincludeを入れる。
#include <pngimage.hpp>

参考 http://www.gesource.jp/programming/bcb/33.html

Unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include <pngimage.hpp>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    Image1->Picture->LoadFromFile(L"site-logo.png");
}
//---------------------------------------------------------------------------

以下のようにTImage上にpngファイルを読めるようになった。

qiita.png

Jpegの場合

以下を追加する。

#include <Jpeg.hpp>

参考 http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/jpeg_TJPEGImage_Assign.html

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1