C++ builder 6 открытие gif файлов
Можно использовать два класса
первый TOleGraphic встроен в C++ builder 6 нужно добавить
#include <axCtrls.hpp> gif анимацию не воспроизводит открывает первый кадр
простой gif открывает как обычно можно модифицировать и
сохранять в bmp или jpeg bmp-шка получается довольно увесистая
с хорошим разрешением ради этого можно использовать
Второй класс TJPEGImage воспроизводит gif анимацию
Нужно подключать файлы #include "GIFImage.hpp" и
GIFImage.pas оба находятся в папке проекта бросте их
в свою папку с проектом файл GIFImage.pas нужно еще добавить к
проекту через меню билдера Project->Add To Project->GIFImage.pas
Модификация идет на уровне бмпшек через методы канвы у обоих
классов TJPEGImage может сохранять и в gif формате
gif-ки получаются в два раза легче исходных что влияет на качество
Исходник и исполняемый файл здесь
При нажатии на кнопку программа загружает файл 7V.gif
он должен находится в папке с программой далее переводит
gif в bmp рисует на bmp квадрат и сохраняет в текущий каталог как bmp, gif, jpg
=
=
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
TPicture::RegisterFileFormat(__classid(TGIFImage),"gif","Files GIF",
__classid(TGIFImage));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
jp = new TJPEGImage();
// jp->CompressionQuality=60;
Bmp=new Graphics::TBitmap;
fPicture=new TPicture ;
Tgif= new TGIFImage();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
delete Tgif;
delete fPicture;
delete Bmp;
delete jp;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
fs=new TFileStream("7V.gif",fmOpenRead|fmShareDenyNone); //"C:\\File2.gif"
OleGraphic = new TOleGraphic;
OleGraphic->LoadFromStream(fs);
Bmp->Width=OleGraphic->Width;
Bmp->Height= OleGraphic->Height;
Bmp->Canvas->Draw(0,0,OleGraphic);
Image1->Picture->Bitmap->Width=Bmp->Width;
Image1->Picture->Bitmap->Height=Bmp->Height;
/*
Image1->Canvas->Draw(0,0,Bmp) ;
Image1->Canvas->Pen->Color=clRed;
Image1->Canvas->Brush->Style=bsClear;
Image1->Canvas->Rectangle(0,0,100,100);
*/
Image1->Picture->Bitmap->Canvas->Draw(0,0,Bmp) ;
Image1->Picture->Bitmap->Canvas->Pen->Color=clRed;
Image1->Picture->Bitmap->Canvas->Brush->Style=bsClear;
Image1->Picture->Bitmap->Canvas->Rectangle(0,0,100,100);
Image1->Picture->Bitmap->SaveToFile("File23.bmp");
jp->Assign( Image1->Picture->Bitmap ) ;
jp->SaveToFile("File3.jpg") ;
delete OleGraphic;
delete fs;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
Tgif->LoadFromFile("7V.gif");
Image1->Picture->Assign(Tgif);
Tgif->Bitmap->Width=Tgif->Width;
Tgif->Bitmap->Height=Tgif->Height;
Tgif->Bitmap->Canvas->Pen->Width=2;
Tgif->Bitmap->Canvas->Pen->Color=clBlue;
Tgif->Bitmap->Canvas->Rectangle(0,0,100,100);
Tgif->Bitmap->SaveToFile("C:File5.bmp");
fPicture->Bitmap->Width=Tgif->Width;
fPicture->Bitmap->Height=Tgif->Height;
fPicture->Bitmap->Canvas->Draw(0,0,Tgif->Bitmap) ;
Tgif->Assign(fPicture->Bitmap);
Tgif->SaveToFile("C:File7.gif");
fPicture->Assign(Tgif);
Bmp->Width=Tgif->Width;
Bmp->Height=Tgif->Height;
Bmp->Canvas->Draw(0,0,fPicture->Graphic) ;
fPicture->Bitmap->Width=Bmp->Width;
fPicture->Bitmap->Height=Bmp->Height;
fPicture->Bitmap->Canvas->Draw(0,0,Bmp) ;
fPicture->Bitmap->Canvas->Pen->Width=2;
fPicture->Bitmap->Canvas->Pen->Color=clRed;
fPicture->Bitmap->Canvas->Rectangle(0,0,100,100);
Tgif->Assign(fPicture->Bitmap);
Tgif->SaveToFile("C:File5.gif");
}
//---------------------------------------------------------------------------
=
=
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <axCtrls.hpp>
#include <jpeg.hpp>
#include "GIFImage.hpp"
#include <ExtCtrls.hpp>
//#include <graphics.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TImage *Image1;
TButton *Button2;
TButton *Button3;
TLabel *Label1;
TShape *Shape1;
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall Button2Click(TObject *Sender);
void __fastcall Button3Click(TObject *Sender);
private: // User declarations
public: // User declarations
Graphics::TBitmap* Bmp;//
TPicture *fPicture;
TOleGraphic *OleGraphic;
TFileStream *fs;
TJPEGImage *jp;
TGIFImage* Tgif;
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
=
=
|