Ejemplo n.º 1
0
static void MobiSaveImage(const WCHAR *filePathBase, size_t imgNo, ImageData *img)
{
    // it's valid to not have image data at a given index
    if (!img || !img->data)
        return;
    const WCHAR *ext = GfxFileExtFromData(img->data, img->len);
    CrashAlwaysIf(!ext);
    ScopedMem<WCHAR> fileName(str::Format(L"%s_img_%d%s", filePathBase, imgNo, ext));
    file::WriteAll(fileName.Get(), img->data, img->len);
}
Ejemplo n.º 2
0
bool PdfCreator::AddImagePage(const char *data, size_t len, float imgDpi)
{
    CrashIf(!ctx || !doc);
    if (!ctx || !doc) return false;

    const WCHAR *ext = GfxFileExtFromData(data, len);
    if (str::Eq(ext, L".jpg") || str::Eq(ext, L".jp2")) {
        Size size = BitmapSizeFromData(data, len);
        fz_image *image = nullptr;
        fz_try(ctx) {
            image = (str::Eq(ext, L".jpg") ? pack_jpeg : pack_jp2)(ctx, data, len, SizeI(size.Width, size.Height));
        }
        fz_catch(ctx) {
            return false;
        }
        bool ok = AddImagePage(image, imgDpi);
        fz_drop_image(ctx, image);
        return ok;
    }