运行打开图片控件是总是提示unknown picture file extension(.)解决方案
运行打开图片控件是总是提示unknown picture file extension(.)
我用打开图片控件,运行的时候点取消时总是提示:unknown pictures file extension (.)
打开一个文件的时候不会有提示,但是点击取消的时候会有提示
这个问题怎么解决啊?请求高手们帮忙。。。
代码如下:
//---------------------------------------
#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)
{
opd->Execute();
img->Picture->LoadFromFile(opd->FileName);
}
------解决方案--------------------
我用打开图片控件,运行的时候点取消时总是提示:unknown pictures file extension (.)
打开一个文件的时候不会有提示,但是点击取消的时候会有提示
这个问题怎么解决啊?请求高手们帮忙。。。
代码如下:
//---------------------------------------
#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)
{
opd->Execute();
img->Picture->LoadFromFile(opd->FileName);
}
------解决方案--------------------
- C/C++ code
void __fastcall TForm1::Button1Click(TObject *Sender) { if(opd->Execute()) { AnsiString FileName=opd->FileName; if(FileExists(FileName)) img->Picture->LoadFromFile(); else ShowMessage("图片不存在!"); } }
------解决方案--------------------
img->Picture->LoadFromFile(opd->FileName);
img不支持图片opd->FileName的格式
------解决方案--------------------
opd->Execute()返回true表示选中了文件,否则表示没有选中文件。所以需要判断一下返回值,然后再装载该文件。
- C/C++ code
if (opd->Execute()) img->Picture->LoadFromFile(opd->FileName);
------解决方案--------------------
#include<jpeg.hpp>加上这个头文件
void __fastcall TForm1::Button1Click(TObject *Sender)
{
String picPath=Edit1->Text;
Label2->Caption=Edit1->Text+"目录下所有的jpg文件";
TSearchRec s;
FindFirst(picPath+"\\*.jpg",0,s);
ListBox1->Clear();
while(FindNext(s)==0)
if(s.Attr==32) ListBox1->Items->Add(s.Name);
}
这是显示图片的代码,你参考一下吧。