示例#1
0
GdkPixbuf* BitmapImage::getGdkPixbuf()
{
    cairo_surface_t* frame = frameAtIndex(currentFrame());
    if (!frame)
        return 0;
    return cairoImageSurfaceToGdkPixbuf(frame);
}
示例#2
0
String ImageBuffer::toDataURL(const String& mimeType, const double* quality) const
{
    ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));

    if (!mimeType.startsWith("image/"))
        return "data:,";

    // List of supported image types comes from the GdkPixbuf documentation.
    // http://library.gnome.org/devel/gdk-pixbuf/stable/gdk-pixbuf-file-saving.html#gdk-pixbuf-save-to-bufferv
    String type = mimeType.substring(sizeof "image");
    if (type != "jpeg" && type != "png" && type != "tiff" && type != "ico" && type != "bmp")
        return "data:,";

    PlatformRefPtr<GdkPixbuf> pixbuf = cairoImageSurfaceToGdkPixbuf(m_data.m_surface);
    if (!pixbuf)
        return "data:,";

    GOwnPtr<gchar> buffer(0);
    gsize bufferSize;
    GError* error = 0;
    gboolean success = FALSE;
    if (type == "jpeg" && quality && *quality >= 0.0 && *quality <= 1.0) {
        String qualityString = String::format("%f", *quality);
        success = gdk_pixbuf_save_to_buffer(pixbuf.get(), &buffer.outPtr(), &bufferSize,
                                            type.utf8().data(), &error, "quality", qualityString.utf8().data(), NULL);
    } else {
        success = gdk_pixbuf_save_to_buffer(pixbuf.get(), &buffer.outPtr(), &bufferSize, type.utf8().data(), &error, NULL);
    }

    if (!success)
        return "data:,";

    Vector<char> out;
    base64Encode(reinterpret_cast<const char*>(buffer.get()), bufferSize, out);
    out.append('\0');

    return String::format("data:%s;base64,%s", mimeType.utf8().data(), out.data());
}
示例#3
0
GdkPixbuf* BitmapImage::getGdkPixbuf()
{
    return cairoImageSurfaceToGdkPixbuf(frameAtIndex(currentFrame()));
}
GdkPixbuf* BitmapImage::getGdkPixbuf()
{
    RefPtr<cairo_surface_t> surface = nativeImageForCurrentFrame();
    return surface ? cairoImageSurfaceToGdkPixbuf(surface.get()) : 0;
}