0

我写了一个读写PPM文件的类(别问,我没选这种格式)。我希望它成为TBitmap加载/保存系统的一部分。

有谁知道我可以如何添加这种支持?我真的必须编写/安装完整的编解码器吗?

解决方案:

通过 Remy Lebeau 的帖子,我设法编写并注册了一个编解码器。然而,所有需要的功能都没有记录,所以它需要一些试验/错误才能让它工作。

要注册新的编解码器,您需要使用这样的静态RegisterBitmapCodecClass成员TBitmapCodecManager

TBitmapCodecManager::RegisterBitmapCodecClass(".ppm","portable pixmap",true,__classid(TMyCodec));

编解码器需要定义这些函数:

class TMyCodec : public TCustomBitmapCodec {

    public:
        bool __fastcall LoadFromStream(System::Classes::TStream* const AStream, Fmx::Surfaces::TBitmapSurface* const Bitmap);
        bool __fastcall LoadFromFile(const System::UnicodeString AFileName, Fmx::Surfaces::TBitmapSurface* const Bitmap);

        bool __fastcall SaveToFile(const System::UnicodeString AFileName, Fmx::Surfaces::TBitmapSurface* const Bitmap, const PBitmapCodecSaveParams SaveParams = (PBitmapCodecSaveParams)(0x0));
        bool __fastcall SaveToStream(System::Classes::TStream* const AStream, Fmx::Surfaces::TBitmapSurface* const Bitmap, const System::UnicodeString Extension, const PBitmapCodecSaveParams SaveParams = (PBitmapCodecSaveParams)(0x0));

        __classmethod System::Types::TPointF __fastcall GetImageSize(const System::UnicodeString AFileName);
        __classmethod bool __fastcall IsValid(System::Classes::TStream* const AStream);

        bool __fastcall LoadThumbnailFromFile(const System::UnicodeString AFileName, const float AFitWidth, const float AFitHeight, const bool UseEmbedded, Fmx::Surfaces::TBitmapSurface* const Bitmap);
};

该类Fmx::Surfaces::TBitmapSurface没有任何文档痕迹,但 IDE 为我提供了可用的功能。我认为该Pixels[x][y]数组用于读取/写入像素。

注册课程后,您可以像往常一样读取新的图像类型TBitmap->LoadFromFile("");

享受!

PS。那些投票结束这个的人,请评论为什么?如果我们不知道自己犯了什么错误,我们如何改进?

4

1 回答 1

1

您需要从TCustomBitmapCodecvirtualLoadFrom...()SaveTo...()方法派生一个新类并实现它,然后在应用程序启动时使用TBitmapCodecManager::RegisterBitmapCodecClass() 注册该类。

于 2014-05-31T15:25:40.560 回答