Beispiel #1
0
bool MPForm::addFile(const QString& name, const QString& path)
{
    KMimeType::Ptr ptr = KMimeType::findByUrl(path);
    QString mime       = ptr->name();
    if (mime.isEmpty())
        return false;

    QFile imageFile(path);
    if (!imageFile.open(QIODevice::ReadOnly))
        return false;
    QByteArray imageData = imageFile.readAll();

    //QString file_size = QString::number(imageFile.size());
    imageFile.close();

    QByteArray str;
    str += "--";
    str += m_boundary;
    str += "\r\n";
    str += "Content-Disposition: form-data; filename=\"";
    str += QFile::encodeName(name);
    str += "\"\r\n";
    //str += "Content-Length: ";
    //str += file_size.toAscii();
    //str += "\r\n";
    str += "Content-Type: ";
    str += mime.toAscii();
    str += "\r\n\r\n";

    m_buffer.append(str);
    m_buffer.append(imageData);
    m_buffer.append("\r\n");

    return true;
}
bool GraphicsServerCommunication::LoadImageFromDisk(gtString& imageName, unsigned char*& pImageBuffer, unsigned long& imageSize)
{
    bool retVal = false;

    pImageBuffer = nullptr;
    osFilePath imageFilePath(osFilePath::OS_USER_DOCUMENTS);

    imageFilePath.setFileName(imageName);
    imageFilePath.setFileExtension(L"png");

    // load the image and return it in the buffer:
    if (imageFilePath.exists())
    {
        osFile imageFile(imageFilePath);
        bool rc = imageFile.getSize(imageSize);
        GT_IF_WITH_ASSERT(rc)
        {
            rc = imageFile.open(osChannel::OS_BINARY_CHANNEL);
            GT_IF_WITH_ASSERT(rc)
            {
                pImageBuffer = new unsigned char[imageSize];
                rc = imageFile.read((char*)pImageBuffer, imageSize);
                GT_IF_WITH_ASSERT(rc)
                {
                    retVal = true;
                }
                imageFile.close();
            }
        }
    }
void MimeImageRecordEditor::on_mimeImageOpen_clicked()
{
    QString mimeDataFile = QFileDialog::getOpenFileName(this, tr("Select Image File"));
    if (mimeDataFile.isEmpty())
        return;

    QFile imageFile(mimeDataFile);
    if (!imageFile.open(QIODevice::ReadOnly)) {
        ui->mimeImageFile->clear();
        ui->mimeImageImage->clear();
    }

    QByteArray imageData = imageFile.readAll();

    QBuffer buffer(&imageData);
    buffer.open(QIODevice::ReadOnly);

    QImageReader reader(&buffer);
    QString mimeType = imageFormatToMimeType(reader.format());
    ui->mimeImageType->setText(mimeType);

    QImage image = reader.read();

    ui->mimeImageFile->setText(mimeDataFile);
    ui->mimeImageImage->setPixmap(QPixmap::fromImage(image));

    m_record.setType(mimeType.toLatin1());
    m_record.setPayload(imageData);
}
Beispiel #4
0
/*!
  Sample images, poses, and mobot models are loaded into the scene
  */
void ImageMapDisplay::testVisual(ImageMapVisual* visual_, std::string filePath){
	std::ifstream imageFile(filePath.c_str(), std::ios::binary);
	if(!boost::filesystem::exists(filePath.c_str())){
        return;
	}
	imageFile.seekg(0, std::ios::end);
	int length = imageFile.tellg();
	char buffer[length];
	imageFile.seekg(0, std::ios::beg);
	imageFile.read(buffer, length);
	std::vector<unsigned char>imageData;
	imageData.assign(buffer, buffer + sizeof(buffer) / sizeof(char));
    cv::Mat mat = cv::imdecode(imageData, 1);
    visual_->insertImage(0,0,0, 0,0,3.1415927, mat);
    visual_->insertImage(0,1,0, 1,1,1.5707963, mat);
    visual_->insertImage(0,2,0, 2,2,3.1415927, mat);
    visual_->insertImage(0,3,0, 3,3,4.712389, mat);
    visual_->insertImage(0,4,0, 4,4,6.2831853, mat);
    visual_->setImagePose(0,0,0,0,0.5,0,ImageMapVisual::ABSOLUTE_POSE_NODE);
    visual_->setImagePose(0,1,0,1,1.5,0,ImageMapVisual::ABSOLUTE_POSE_NODE);
    visual_->setImagePose(0,2,0,2,2.5,0,ImageMapVisual::ABSOLUTE_POSE_NODE);
    visual_->setImagePose(0,3,0,3,3.5,0,ImageMapVisual::ABSOLUTE_POSE_NODE);
    visual_->setMobotModel(0,0.5,0.6,0);
    visual_->setMobotModel(1,-0.5,0.6,0);
    visual_->setMobotModel(2,-1,0.6,0);
}
Beispiel #5
0
void XHTMLTagImageAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) {
	const char *fileName = reader.attributeValue(xmlattributes, *myPredicate);
	if (fileName == 0) {
		return;
	}

	const std::string fullfileName = pathPrefix(reader) + MiscUtil::decodeHtmlURL(fileName);
	ZLFile imageFile(fullfileName);
	if (!imageFile.exists()) {
		return;
	}

	bool flag = bookReader(reader).paragraphIsOpen();
	if (flag) {
		endParagraph(reader);
	}
	if (std::strlen(fileName) > 2 && std::strncmp(fileName, "./", 2) == 0) {
		fileName +=2;
	}
	bookReader(reader).addImageReference(fullfileName);
	bookReader(reader).addImage(fullfileName, new ZLFileImage(ZLFile(fullfileName), 0));
	if (flag) {
		beginParagraph(reader);
	}
}
Beispiel #6
0
SourceWidget::SourceWidget(QWidget *parent)
    : QWidget(parent)
{
    QFile imageFile(":/images/example.svg");
    imageFile.open(QIODevice::ReadOnly);
    imageData = imageFile.readAll();
    imageFile.close();

    QScrollArea *imageArea = new QScrollArea;
    imageLabel = new QSvgWidget;
    imageLabel->renderer()->load(imageData);
    imageArea->setWidget(imageLabel);
    //imageLabel->setMinimumSize(imageLabel->renderer()->viewBox().size());

    QLabel *instructTopLabel = new QLabel(tr("This is an SVG drawing:"));
    QLabel *instructBottomLabel = new QLabel(
        tr("Drag the icon to copy the drawing as a PNG file:"));
    instructBottomLabel->setWordWrap(true);
    QPushButton *dragIcon = new QPushButton(tr("Export"));
    dragIcon->setIcon(QIcon(":/images/drag.png"));

    connect(dragIcon, SIGNAL(pressed()), this, SLOT(startDrag()));

    QGridLayout *layout = new QGridLayout;
    layout->addWidget(instructTopLabel, 0, 0, 1, 2);
    layout->addWidget(imageArea, 1, 0, 2, 2);
    layout->addWidget(instructBottomLabel, 3, 0);
    layout->addWidget(dragIcon, 3, 1);
    setLayout(layout);
    setWindowTitle(tr("Delayed Encoding"));
}
Beispiel #7
0
void XHTMLTagImageAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) {
	const char *fileName = reader.attributeValue(xmlattributes, *myPredicate);
	if (fileName == 0) {
		return;
	}

	const std::string fullfileName = pathPrefix(reader) + MiscUtil::decodeHtmlURL(fileName);
	ZLFile imageFile(fullfileName);
	if (!imageFile.exists()) {
		return;
	}

	const bool flagParagraphIsOpen = bookReader(reader).paragraphIsOpen();
	if (flagParagraphIsOpen) {
		if (reader.myCurrentParagraphIsEmpty) {
			bookReader(reader).addControl(IMAGE, true);
		} else {
			endParagraph(reader);
		}
	}
	const std::string imageName = imageFile.name(false);
	bookReader(reader).addImageReference(imageName, 0, reader.myMarkNextImageAsCover);
	bookReader(reader).addImage(imageName, new ZLFileImage(imageFile, "", 0, 0, reader.myEncryptionMap->info(imageFile.path())));
	reader.myMarkNextImageAsCover = false;
	if (flagParagraphIsOpen && reader.myCurrentParagraphIsEmpty) {
		bookReader(reader).addControl(IMAGE, false);
		endParagraph(reader);
	}
}
bool FakeVmsConnector::init(const opencctv::api::VmsConnectInfo& info, const std::string sPathToAnalyticDir)
{
	bool bRet = false;
	std::string sConfigFilePath = sPathToAnalyticDir;
	sConfigFilePath.append("/").append("analytic.config");
	try
	{
		_pConfig = util::Config::getInstance(sConfigFilePath);
	}
	catch(std::runtime_error &e)
	{
		std::cerr << "Failed to read Analytic Configuration file. " << e.what() << std::endl;
	}
	if(_pConfig)
	{
		std::string sFilePath = sPathToAnalyticDir;
		sFilePath.append("/").append(_pConfig->get(util::PROPERTY_IMAGE_FILE));
		std::vector<char>* pVImageData = NULL;
		try {
			std::ifstream imageFile(sFilePath.c_str(), std::ios::binary | std::ios::ate);
			std::ifstream::pos_type pos = imageFile.tellg();
			pVImageData = new std::vector<char>(pos);
			imageFile.seekg(0, std::ios::beg);
			imageFile.read(&(*pVImageData)[0], pos);
			_pVImageData = new std::vector<unsigned char>(pVImageData->begin(), pVImageData->end());
			bRet = true;
		} catch (std::exception &e) {
			std::cerr << e.what() << std::endl;
		}
		if(pVImageData) delete pVImageData;
	}
	return bRet;
}
ZLNetworkImage::ZLNetworkImage(shared_ptr<ZLMimeType> mimeType, const std::string &url) : ZLSingleImage(mimeType), myURL(url), myIsSynchronized(false) {
	static const std::string directoryPath = ZLNetworkManager::CacheDirectory();

	std::string prefix;
	if (ZLStringUtil::stringStartsWith(myURL, "http://")) {
		prefix = "http://";
	} else if (ZLStringUtil::stringStartsWith(myURL, "https://")) {
		prefix = "https://";
	} else if (ZLStringUtil::stringStartsWith(myURL, "ftp://")) {
		prefix = "ftp://";
	} else {
		myIsSynchronized = true;
		return;
	}
	myFileName = myURL.substr(prefix.length());
	myFileName = ZLFile::replaceIllegalCharacters(myFileName, '_');
	myFileName = directoryPath + ZLibrary::FileNameDelimiter + myFileName;

	static shared_ptr<ZLDir> dir = ZLFile(directoryPath).directory(true);
	if (dir.isNull()) {
		myIsSynchronized = true;
		return;
	}

	ZLFile imageFile(myFileName);
	if (imageFile.exists()) {
		myCachedImage = new ZLFileImage(imageFile, 0);
		if (myCachedImage->good()) {
			myIsSynchronized = true;
		} else {
			myCachedImage.reset();
			imageFile.remove();
		}
	}
}
Beispiel #10
0
/**
 * Save an image and its info file to disk.
 */
int ImagePose::initWrite(){
#if 0
  // Create the directory
	char* infoFolderPath = concPath();
	boost::filesystem::create_directories(infoFolderPath);
	delete[] infoFolderPath;
#endif
  
	// Save info to disk
	try{
		infoData.save(infoPath);
	}catch (std::exception &e){
		ROS_INFO("Error: %s", e.what());
		errorStatus = 102;
		return 1;
	}
	// Save image to disk
	std::ofstream imageFile(imagePath.c_str(), std::ios::binary);
	if(imageFile.is_open()){
		imageFile.write((const char*) &imageData[0], imageData.size() * sizeof(unsigned char));
		imageFile.close();
	} else {
		ROS_INFO("ImagePose:%s: Can't save image", imagePath.c_str());
		return 1;
	}
	return 0;
}
Beispiel #11
0
bool GDMPForm::addFile(const QString& path)
{
    QByteArray str;
    qCDebug(DIGIKAM_WEBSERVICES_LOG) << "in addfile" << path;

    QMimeDatabase db;
    QMimeType ptr = db.mimeTypeForUrl(QUrl::fromLocalFile(path));
    QString mime  = ptr.name();
    str += "--";
    str += m_boundary;
    str += "\r\n";
    str += "Content-Type: ";
    str += mime.toLatin1();
    str += "\r\n\r\n";

    QFile imageFile(path);

    if (!imageFile.open(QIODevice::ReadOnly))
    {
        return false;
    }

    QByteArray imageData = imageFile.readAll();
    m_file_size          = QString::number(imageFile.size());

    imageFile.close();

    m_buffer.append(str);
    m_buffer.append(imageData);
    m_buffer.append("\r\n");

    return true;
}
ImageCaptionObject
ImageCaptionGrabber::imageCaption()
{
  ImageCaptionObject co;
  co.set(position(), imageFile(),
	 width(), height());
  return co;
}
bool GalleryMPForm::addFile(const QString& path, const QString& displayFilename)
{

    QString filename = "userfile_name";
    if (GalleryTalker::isGallery2())
        filename = "g2_userfile_name";

    if (!addPairRaw(filename, displayFilename)) 
    {
        return false;
    }

    KMimeType::Ptr ptr = KMimeType::findByUrl(path);
    QString mime = ptr->name();
    if (mime.isEmpty())
    {
        // if we ourselves can't determine the mime of the local file,
        // very unlikely the remote gallery will be able to identify it
        return false;
    }

    QFile imageFile(path);
    if (!imageFile.open(QIODevice::ReadOnly))
        return false;
    QByteArray imageData = imageFile.readAll();
    imageFile.close();

    QString str;

    str += "--";
    str += m_boundary;
    str += "\r\n";
    str += "Content-Disposition: form-data; name=\"";

    if (GalleryTalker::isGallery2())
        str += "g2_userfile";
    else
        str += "userfile";

    str += "\"; ";
    str += "filename=\"";
    str += QFile::encodeName(KUrl(path).fileName());
    str += "\"";
    str += "\r\n";
    str += "Content-Type: ";
    str +=  mime.toAscii();
    str += "\r\n\r\n";

    m_buffer.append(str.toUtf8());

    int oldSize = m_buffer.size();
    m_buffer.resize(oldSize + imageData.size() + 2);
    memcpy(m_buffer.data() + oldSize, imageData.data(), imageData.size());
    m_buffer[m_buffer.size()-2] = '\r';
    m_buffer[m_buffer.size()-1] = '\n';

    return true;
}
QString WebResourceManager::getMatchingImage(const QString& requestedURL) const {
    // if something explicitly on the disk is requested, then return it
    if(requestedURL.length() > 10 && requestedURL.mid(0, 9).compare("asset:///") == 0) {
        return requestedURL;
    }

    // check if cache folder exists, if not, creates it
    QString directory = QDir::homePath() + "/../native/assets/TMP/";
    if (!QFile::exists(directory)) {
        QDir dir;
        dir.mkpath(directory);
    }


    // check if image already available
    QUrl url = QUrl(requestedURL);
    // Check if image is stored on disc
    // The qHash is a bucket type hash so the doubling is to remove possible collisions.
    QString diskPath = QDir::homePath() + "/../native/assets/TMP/"
            + QString::number(qHash(url.host())) + "_"
            + QString::number(qHash(url.path())) + ".PNG";

    QFile imageFile(diskPath);

    // If the file exists, send a signal the image is ready
    if (imageFile.exists()) {
        qDebug() << requestedURL << "...existing";
        qDebug() << diskPath;
        return "asset:///TMP/" + QString::number(qHash(url.host())) + "_"
                + QString::number(qHash(url.path())) + ".PNG";
    } else {
        // check if the file is being downloaded, if so, skip it
        m_EditQueue->lockForRead();
        for(int i = 0 ; i < m_DownloadQueue->length() ; ++i)
            if(m_DownloadQueue->at(i).compare(requestedURL) == 0) {
                m_EditQueue->unlock();
                return "asset:///TMP/" + QString::number(qHash(url.host())) + "_"
                + QString::number(qHash(url.path())) + ".PNG";;
            }
        m_EditQueue->unlock();

        // otherwise let's download the file
        QNetworkRequest request(url);
        request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");


        QNetworkReply* reply = HFRNetworkAccessManager::get()->get(request);
        bool ok = connect(reply, SIGNAL(finished()), this, SLOT(checkReply()));
        Q_ASSERT(ok);
        Q_UNUSED(ok);

        return "file://" + diskPath;

        qDebug() << requestedURL << "...dowload";
    }

    return "";
}
Beispiel #15
0
void OEBBookReader::startElementHandler(const char *tag, const char **xmlattributes) {
	std::string tagString = ZLUnicodeUtil::toLower(tag);
	if (!myOPFSchemePrefix.empty() &&
			ZLStringUtil::stringStartsWith(tagString, myOPFSchemePrefix)) {
		tagString = tagString.substr(myOPFSchemePrefix.length());
	}
	if (MANIFEST == tagString) {
		myState = READ_MANIFEST;
	} else if (SPINE == tagString) {
		const char *toc = attributeValue(xmlattributes, "toc");
		if (toc != 0) {
			myNCXTOCFileName = myIdToHref[toc];
		}
		myState = READ_SPINE;
	} else if (GUIDE == tagString) {
		myState = READ_GUIDE;
	} else if (TOUR == tagString) {
		myState = READ_TOUR;
	} else if ((myState == READ_MANIFEST) && (ITEM == tagString)) {
		const char *id = attributeValue(xmlattributes, "id");
		const char *href = attributeValue(xmlattributes, "href");
		if ((id != 0) && (href != 0)) {
			myIdToHref[id] = MiscUtil::decodeHtmlURL(href);
		}
	} else if ((myState == READ_SPINE) && (ITEMREF == tagString)) {
		const char *id = attributeValue(xmlattributes, "idref");
		if (id != 0) {
			const std::string &fileName = myIdToHref[id];
			if (!fileName.empty()) {
				myHtmlFileNames.push_back(fileName);
			}
		}
	} else if ((myState == READ_GUIDE) && (REFERENCE == tagString)) {
		const char *type = attributeValue(xmlattributes, "type");
		const char *title = attributeValue(xmlattributes, "title");
		const char *href = attributeValue(xmlattributes, "href");
		if (href != 0) {
			const std::string reference = MiscUtil::decodeHtmlURL(href);
			if (title != 0) {
				myGuideTOC.push_back(std::make_pair(std::string(title), reference));
			}
			if ((type != 0) && (COVER_IMAGE == type)) {
				myModelReader.setMainTextModel();
				ZLFile imageFile(myFilePrefix + reference);
				const std::string imageName = imageFile.name(false);
				myModelReader.addImageReference(imageName, 0, false);
				myModelReader.addImage(imageName, new ZLFileImage(imageFile, "", 0));
			}
		}
	} else if ((myState == READ_TOUR) && (SITE == tagString)) {
		const char *title = attributeValue(xmlattributes, "title");
		const char *href = attributeValue(xmlattributes, "href");
		if ((title != 0) && (href != 0)) {
			myTourTOC.push_back(std::make_pair(title, MiscUtil::decodeHtmlURL(href)));
		}
	}
}
// Saves the image to disk for later use
void ImageLoader::saveToDisk(QUrl url, QByteArray data)
{

	QFile imageFile(ImageLoader::generateTempUrl(url));
	if(!imageFile.open(QIODevice::WriteOnly)) return;

	imageFile.write(data);
	imageFile.close();
}
Beispiel #17
0
void MainVerticalSlider::setImage(String imagePath, int numFrames){
    if (image != nullptr){ 
        delete image;
        image = nullptr;
    }
    
    File imageFile(File(File::getCurrentWorkingDirectory().getFullPathName() + "/" + imagePath));
    PNGImageFormat p;
    image = new Image(PNGImageFormat::loadFrom(*imageFile.createInputStream()));
    setNumFrames(numFrames);
}
Beispiel #18
0
bool KNLibHashPixmapList::removeImageFile(const QString &key)
{
    QFile imageFile(m_folderPath+key+".png");
    //If the file is exsist, then return the delete state.
    if(imageFile.exists())
    {
        return imageFile.remove();
    }
    //File is not exsist.
    return true;
}
Beispiel #19
0
bool writeImage(QString devicePath, QString deviceImage, QObject *caller)
{
    utils::writeLog("Writing " + deviceImage + " to " + devicePath);
    WriteImageWorker* worker = NULL;
    if(caller) {
        if(! (worker = qobject_cast<WriteImageWorker*>(caller)) ) {
            worker = NULL;
        }
    }
    QFile imageFile(deviceImage);
    QFile deviceFile(devicePath);
    bool imageOpen = imageFile.open(QIODevice::ReadOnly);
    bool deviceOpen = deviceFile.open(QIODevice::WriteOnly);
    if(!imageOpen) {
        utils::writeLog("Error opening image");
        return false;
    }
    if(!deviceOpen) {
        utils::writeLog("Error opening device");
        return false;
    }
    char buf[512*1024];
    QDataStream in(&imageFile);
    QDataStream out(&deviceFile);
    unsigned total = 0;
    int r = in.readRawData(buf,sizeof(buf));
    int ret;
    while(r>0) {
        ret = out.writeRawData(buf, r);
        if(ret == -1 || ret != r) {
            imageFile.close();
            deviceFile.close();
            utils::writeLog("Error writing to device");
            return false;
        }
        total += r;
        if(worker){
            worker->emitProgressUpdate(total);
        }
        r = in.readRawData(buf,sizeof(buf));
    }
    if(worker){
        worker->emitFlushingFS();
    }
    imageFile.close();
    if(!deviceFile.flush()) {
        return false;
    }
    deviceFile.close();

    updateKernelTable();
    return true;
}
Beispiel #20
0
QPixmap MapWidget::loadTile(int zoomLevel, int x, int y)
{
    QString path(MapWidget::TILES_DIR + "%1/%2/%3.png");
    path = path.arg(zoomLevel).arg(x).arg(y);
    QFile imageFile(path);
    if (!imageFile.exists()) {
        qCritical() << "Tile not found to zoom:" << zoomLevel << " x:" << x << " y:" << y;
        return QPixmap();
    }

    return QPixmap(path);
}
// Gets an image file from disk if it exists
bool ImageLoader::loadFromDisk(QUrl url, bb::cascades::ImageView* img)
{
	QFile imageFile(ImageLoader::generateTempUrl(url));
	if(imageFile.exists() && imageFile.open(QIODevice::ReadOnly))
	{
		bb::cascades::Image i = bb::cascades::Image(imageFile.readAll());
		img->setImage(i);
		imageFile.close();
		return true;
	}
	return false;
}
Beispiel #22
0
void OEBBookReader::addCoverImage() {
	ZLFile imageFile(myCoverFileName);
	shared_ptr<const ZLImage> image = coverIsSingleImage()
		? new ZLFileImage(imageFile, "", 0) : XHTMLImageFinder().readImage(imageFile);

	if (!image.isNull()) {
		const std::string imageName = imageFile.name(false);
		myModelReader.setMainTextModel();
		myModelReader.addImageReference(imageName, (short)0, true);
		myModelReader.addImage(imageName, image);
		myModelReader.insertEndOfSectionParagraph();
	}
}
Beispiel #23
0
const shared_ptr<std::string> ZLNetworkImage::stringData() const {
	if (myCachedImage.isNull()) {
		ZLFile imageFile(myFileName);
		if (imageFile.exists()) {
			myCachedImage = new ZLFileImage(imageFile, 0);
			if (!myCachedImage->good()) {
				myCachedImage.reset();
				imageFile.remove();
			}
		}
	}
	return myCachedImage.isNull() ? 0 : myCachedImage->stringData();
}
void BlackBoardWidget::saveImage()
{ 
    if (m_parentApplet->destroyed()){
        KIO::del(imagePath());
    }else{
        if (m_changed){
            KSaveFile imageFile(imagePath());
            imageFile.open();
            m_pixmap.save(&imageFile, "PNG");
            imageFile.finalize();
            imageFile.close();
        }
    }
}
Beispiel #25
0
bool FlickrMPForm::addFile(const QString& name, const QString& path)
{
    QMimeDatabase db;
    QMimeType ptr = db.mimeTypeForUrl(QUrl::fromLocalFile(path));
    QString mime  = ptr.name();

    if (mime.isEmpty())
    {
        // if we ourselves can't determine the mime of the local file,
        // very unlikely the remote site will be able to identify it
        return false;
    }

    QFile imageFile(path);

    if (!imageFile.open(QIODevice::ReadOnly))
    {
        return false;
    }

    QByteArray imageData = imageFile.readAll();

    QByteArray str;
    QString file_size = QString::fromLatin1("%1").arg(imageFile.size());
    imageFile.close();

    str += "--";
    str += m_boundary;
    str += "\r\n";
    str += "Content-Disposition: form-data; name=\"";
    str += name.toLatin1();
    str += "\"; ";
    str += "filename=\"";
    str += QFile::encodeName(QUrl::fromLocalFile(path).fileName());
    str += "\"\r\n";
    str += "Content-Length: ";
    str += file_size.toLatin1();
    str += "\r\n";
    str += "Content-Type: ";
    str +=  mime.toLatin1();
    str += "\r\n\r\n";

    m_buffer.append(str);
    m_buffer.append(imageData);
    m_buffer.append("\r\n");

    return true;
}
Beispiel #26
0
void KNMusicLibraryImageManager::removeImage(const QString &imageHash)
{
    //Check is the file exist.
    QFileInfo imageFileInfo(m_imageFolderPath + "/" + imageHash + ".png");
    //If it's exist.
    if(imageFileInfo.exists())
    {
        //If it's a file, remove it.
        if(imageFileInfo.isFile())
        {
            QFile imageFile(imageFileInfo.absoluteFilePath());
            imageFile.remove();
            return;
        }
    }
}
void AbstractMainWindow::set_background(QString image)
{
    qDebug() << "Setting background on "<< this->objectName();
    QPalette palatte = this->palette();
    QBrush brush(Qt::black);
    QFile imageFile(image);
    if(imageFile.exists())
    {
        brush.setTexture(QPixmap(image).scaled(QApplication::desktop()->screenGeometry(screenIndex).width(),
                                               QApplication::desktop()->screenGeometry(screenIndex).height(),
                                               Qt::IgnoreAspectRatio,
                                               Qt::SmoothTransformation));
    }
    palatte.setBrush(this->backgroundRole(),brush);
    this->setPalette(palatte);
}
Beispiel #28
0
bool CTagBase::addImage(wchar_t* s)
{
	if (!_tagFile) return false;
	TagLib::MPEG::File *pAudioFile = (TagLib::MPEG::File *)_tagFile.get();
	CString strFileName = s;
	ImageFile imageFile((CW2A)strFileName.GetBuffer());
	if (!pAudioFile->isValid() || !imageFile.isValid())
		return false;
	TagLib::ID3v2::Tag *tag = pAudioFile->ID3v2Tag(true);
	TagLib::ID3v2::AttachedPictureFrame *frame = new TagLib::ID3v2::AttachedPictureFrame;
	frame->setMimeType(imageFile.mimeType());
	frame->setPicture(imageFile.data());
	tag->addFrame(frame);
	return pAudioFile->save();

}
Beispiel #29
0
bool MPForm::addFile(const QString& name,const QString& path)
{
    KMimeType::Ptr ptr = KMimeType::findByUrl(path);
    QString mime       = ptr->name();
    if (mime.isEmpty())
    {
        // if we ourselves can't determine the mime of the local file,
        // very unlikely the remote site will be able to identify it
        return false;
    }

    QFile imageFile(path);
    if (!imageFile.open(QIODevice::ReadOnly))
        return false;

    QByteArray imageData = imageFile.readAll();

    QString str;
    QString file_size = QString("%1").arg(imageFile.size());

    str += "--";
    str += m_boundary;
    str += "\r\n";
    str += "Content-Disposition: form-data; name=\"";
    str += name.toAscii();
    str += "\"; ";
    str += "filename=\"";
    str += QFile::encodeName(KUrl(path).fileName());
    str += "\"\r\n";
    str += "Content-Length: " ;
    str +=  file_size.toAscii();
    str += "\r\n";
    str += "Content-Type: ";
    str +=  mime.toAscii();
    str += "\r\n\r\n";

    imageFile.close();
    m_buffer.append(str.toUtf8());

    int oldSize = m_buffer.size();
    m_buffer.resize(oldSize + imageData.size() + 2);
    memcpy(m_buffer.data() + oldSize, imageData.data(), imageData.size());
    m_buffer[m_buffer.size()-2] = '\r';
    m_buffer[m_buffer.size()-1] = '\n';

    return true;
}
Beispiel #30
0
bool BMP::read8bits()
{
    std::ifstream imageFile(_pathname.c_str(),std::ios::binary);

    //Palette recuperation
    imageFile.seekg(_offsetImage-1024,std::ios::beg);
    unsigned char red,green,blue,alpha,color;
    RGBA* rgba;
    for(int i=0;i<256;i++)
    {
        rgba = new RGBA();
        imageFile.read((char*)&red,sizeof(char));
        imageFile.read((char*)&green,sizeof(char));
        imageFile.read((char*)&blue,sizeof(char));
        imageFile.read((char*)&alpha,sizeof(char));
        rgba->setRed(red);
        rgba->setGreen(green);
        rgba->setBlue(blue);
        rgba->setAlpha(alpha);
        this->palette.push_back(rgba);
        _correspondancepixelPalette[red][green][blue][alpha]=i;

    }
    imageFile.seekg(_offsetImage,std::ios::beg);
    //pixel recuperation

    //Initialisation array first to reverse to order : 0,0 means top left
    this->pixel.resize(this->getHeightImage());
    for(int i=0;i<this->getHeightImage();i++)
    {
        this->pixel[i].resize(this->getWidthImage());
    }


    for(int i=this->getHeightImage()-1;i>=0;i--)
    {
        for(int j=0;j<this->getWidthImage();j++)
        {
        imageFile.read((char*)&color,sizeof(char));
        this->pixel[i][j]=new RGBA(this->palette[color]);
        }
    }

    imageFile.close();
    return false;
}