Beispiel #1
0
void ImageResize::run()
{
    d->running = true;
    while (d->running)
    {
        ImageResizePriv::Task *t = 0;
        {
            QMutexLocker lock(&d->mutex);
            if (!d->todo.isEmpty())
                t = d->todo.takeFirst();
            else
                d->condVar.wait(&d->mutex);
        }

        if (t)
        {
            QString errString;

            emit startingResize(t->orgUrl);
            d->count++;
            int percent = (int)(((float)d->count/(float)t->settings.itemsList.count())*100.0);

            if (imageResize(t->settings, t->orgUrl, t->destName, errString))
            {
                KUrl emailUrl(t->destName);
                emit finishedResize(t->orgUrl, emailUrl, percent);
            }
            else
            {
                emit failedResize(t->orgUrl, errString, percent);
            }

            if (t->settings.itemsList.count() == d->count)
            {
                emit completeResize();
                d->count = 0;
            }

            delete t;
        }
    }
}
Beispiel #2
0
void MainWindow::imageLoaded(QNetworkReply *reply) {
    disconnect(reply, &QNetworkReply::downloadProgress, this, &MainWindow::downloadProgress);
    progress->setValue(0);

    ui->appendVote->setEnabled(true);

    if(ui->operationsStack->currentIndex() == 0) {
        if(QNetworkReply::NoError == reply->error()) {
            //Данные
            QImage img;
            QImageReader reader(reply);

            reader.read(&img);

            //Чтение изображения
            currentPixmap = QPixmap::fromImage(img);

            imageResize();
            recieveMessage(Errors::NoError, "Изображение загружено");
        } else {
            recieveMessage(Errors::Error, "Не удалось загрузить изображение");
        }
    }
}
static int getImage(const char *fileName, image *imageData, unsigned maxWidth,
	unsigned maxHeight, int stretch, color *background)
{
	int status = 0;
	image loadImage;
	float scale = 0;
	unsigned thumbWidth = 0;
	unsigned thumbHeight = 0;

	memset(&loadImage, 0, sizeof(image));

	status = imageNew(imageData, maxWidth, maxHeight);
	if (status < 0)
		return (status);

	if (!stretch && background)
	{
		status = imageFill(imageData, background);
		if (status < 0)
			goto out;
	}

	if (fileName)
	{
		status = imageLoad(fileName, 0, 0, &loadImage);
		if (status < 0)
			goto out;

		// Scale the image
		thumbWidth = loadImage.width;
		thumbHeight = loadImage.height;

		// Presumably we need to shrink it?
		if (stretch)
		{
			thumbWidth = maxWidth;
			thumbHeight = maxHeight;
		}
		else
		{
			if (thumbWidth > maxWidth)
			{
				scale = ((float) maxWidth / (float) thumbWidth);
				thumbWidth = (unsigned)((float) thumbWidth * scale);
				thumbHeight = (unsigned)((float) thumbHeight * scale);
			}

			if (thumbHeight > maxHeight)
			{
				scale = ((float) maxHeight / (float) thumbHeight);
				thumbWidth = (unsigned)((float) thumbWidth * scale);
				thumbHeight = (unsigned)((float) thumbHeight * scale);
			}
		}

		if ((thumbWidth != loadImage.width) ||
			(thumbHeight != loadImage.height))
		{
			status = imageResize(&loadImage, thumbWidth, thumbHeight);
			if (status < 0)
				goto out;
		}

		status = imagePaste(&loadImage, imageData,
			((maxWidth - loadImage.width) / 2),
			((maxHeight - loadImage.height) / 2));
		if (status < 0)
			goto out;
	}

	status = 0;

out:
	if (loadImage.data)
		imageFree(&loadImage);

	if ((status < 0) && imageData->data)
		imageFree(imageData);

	return (status);
}
Beispiel #4
0
void MainWindow::resizeEvent(QResizeEvent *) {
    imageResize();
}