www.pudn.com > J2KLib.rar > Main.cpp
//--------------------------------------------------------------------------- #include#pragma hdrstop #include "Main.h" #include "J2kClass.h" #include //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "CSPIN" #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { TMemoryStream *mStm = new TMemoryStream; TJPEGImage *jp = new TJPEGImage(); jp->CompressionQuality = CSpinEdit1->Value; try { jp->Assign(Image1->Picture->Bitmap); jp->SaveToStream( mStm ); //多此一举主要是想获得Jpeg图像的大小 Label2->Caption = String( "格式:Jpeg 400 X300 ,压缩质量:" ) + jp->CompressionQuality + ",字节:" + mStm->Size + ",压缩比:" + (360054.0/mStm->Size) + "倍"; mStm->Position = 0; jp->LoadFromStream( mStm ); Image2->Picture->Assign(jp); } __finally { delete jp; } TJ2kCoder J2kCoder; double CompressionQuality = CSpinEdit2->Value;; Graphics::TBitmap *Bitmap = new Graphics::TBitmap(); mStm->Size = 0; J2kCoder.Encode( Image1->Picture->Bitmap, mStm, CompressionQuality ); //多此一举主要是想获得J2K图像的大小 Label3->Caption = String( "格式:J2k 400 X300 ,压缩质量:" ) + CompressionQuality + ",字节:" + mStm->Size + ",压缩比:" + (360054.0/mStm->Size) + "倍"; mStm->Position = 0; try { J2kCoder.Decode( mStm, Bitmap ); mStm->Position = 0; Image3->Picture->Assign(Bitmap); } __finally { delete Bitmap; } delete mStm; } //---------------------------------------------------------------------------