c++ builder XE4, 10.2 Tokyo > TImage > 読込む画像サイズに合わせてTImageサイズを変更する
4433 ワード
動作環境
C++ Builder XE4
RAD Studio 10.2 Tokyo Update 2 (追記: 2017/12/28)
関連 http://qiita.com/7of9/items/9edf309c5f58cec126ff
関連 http://qiita.com/7of9/items/bce8dab6226cec14dc3a
pngやjpg画像を読込むとき、Stretchを使うと画像が粗くなる。これを回避する方法として、元画像のサイズのまま読込む方法を調べた。
参考 http://stackoverflow.com/questions/15209076/how-to-get-dimensions-of-image-file-in-delphi
一旦TPicture型で読込んで、そのWidth, Heightプロパティを使うという方法。
Unit1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <pngimage.hpp>
//#include <Jpeg.hpp>
#include <memory>
#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->Stretch = true;
String filename = L"site-logo.png";
std::unique_ptr<TPicture> pict(new TPicture);
pict->LoadFromFile(filename);
Image1->Width = pict->Width;
Image1->Height = pict->Height;
Image1->Picture->LoadFromFile(filename);
}
//---------------------------------------------------------------------------
画像のサイズそのままが使われるようになった。
Author And Source
この問題について(c++ builder XE4, 10.2 Tokyo > TImage > 読込む画像サイズに合わせてTImageサイズを変更する), 我々は、より多くの情報をここで見つけました https://qiita.com/7of9/items/fe038ede23f829a1a451著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .