コード例 #1
0
NS_IMETHODIMP
sbClipboardHelper::PasteImageToClipboard(const nsACString &aMimeType,
        const PRUint8    *aData,
        PRUint32         aDataLen)
{
    nsresult rv;

    nsCOMPtr<imgITools> imgtool = do_CreateInstance("@mozilla.org/image/tools;1",
                                  &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    // Convert the image data to a stream so we can use the imagITools
    nsCOMPtr<nsIStringInputStream> stream = do_CreateInstance("@mozilla.org/io/string-input-stream;1",
                                            &rv);
    NS_ENSURE_SUCCESS(rv, rv);
    stream->ShareData(reinterpret_cast<const char*>(aData), aDataLen);

    // decode image
    nsCOMPtr<imgIContainer> image;
    rv = imgtool->DecodeImageData(stream, aMimeType, getter_AddRefs(image));
    NS_ENSURE_SUCCESS(rv, rv);

    // Now create a Transferable so we can copy to the clipboard
    nsCOMPtr<nsITransferable> xferable = do_CreateInstance("@mozilla.org/widget/transferable;1", &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsISupportsInterfacePointer>
    imgPtr(do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    rv = imgPtr->SetData(image);
    NS_ENSURE_SUCCESS(rv, rv);

    // copy the image data onto the transferable
    rv = xferable->SetTransferData(kNativeImageMime,
                                   imgPtr,
                                   sizeof(nsISupportsInterfacePointer*));
    NS_ENSURE_SUCCESS(rv, rv);

    // get clipboard
    nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    // check whether the system supports the selection clipboard or not.
    bool selectionSupported;
    rv = clipboard->SupportsSelectionClipboard(&selectionSupported);
    NS_ENSURE_SUCCESS(rv, rv);

    // put the transferable on the clipboard
    if (selectionSupported) {
        rv = clipboard->SetData(xferable, nsnull, nsIClipboard::kSelectionClipboard);
        NS_ENSURE_SUCCESS(rv, rv);
    }

    return clipboard->SetData(xferable, nsnull, nsIClipboard::kGlobalClipboard);
}
コード例 #2
0
boost::shared_ptr<Image> ImageManager::getImage(std::string imagePath)
{
	std::map<std::string,boost::shared_ptr<Image> >::iterator iter;

	iter = imageCache.find(imagePath);

	if (iter != imageCache.end())
	{
		return iter->second;
	}
	
	//Image* img = loadImage(imagePath);

	boost::shared_ptr<Image> imgPtr(loadImage(imagePath));



	imageCache.insert(std::pair<std::string,boost::shared_ptr<Image> >(imagePath,imgPtr));

	return imgPtr;

}