Пример #1
0
bool Editor::importBitmapImage( QString filePath )
{
    backup( tr( "ImportImg" ) );

    QImageReader reader( filePath );

    Q_ASSERT( layers()->currentLayer()->type() == Layer::BITMAP );
    auto layer = static_cast<LayerBitmap*>( layers()->currentLayer() );

    QImage img( reader.size(), QImage::Format_ARGB32_Premultiplied );

    while ( reader.read( &img ) )
    {
        if ( img.isNull() || reader.nextImageDelay() <= 0 )
        {
            break;
        }

        if ( !layer->keyExists( currentFrame() ) )
        {
            addNewKey();
        }
        BitmapImage* bitmapImage = layer->getBitmapImageAtFrame( currentFrame() );

        QRect boundaries = img.rect();
        boundaries.moveTopLeft( mScribbleArea->getCentralPoint().toPoint() - QPoint( boundaries.width() / 2, boundaries.height() / 2 ) );

        BitmapImage* importedBitmapImage = new BitmapImage( boundaries, img );
        bitmapImage->paste( importedBitmapImage );

        scrubTo( currentFrame() + 1 );
    }

    return true;
}
bool Editor::importBitmapImage( QString filePath )
{
    backup( tr( "ImportImg" ) );
    qDebug(filePath.toLatin1().data());
    QImageReader reader( filePath );

    Q_ASSERT( layers()->currentLayer()->type() == Layer::BITMAP );
    auto layer = static_cast<LayerBitmap*>( layers()->currentLayer() );

    QImage img;//( reader.size(), QImage::Format_ARGB32_Premultiplied );
    img.load(filePath);
    while ( reader.read( &img ) )
    {/*
        if ( img.isNull() || reader.nextImageDelay() <= 0 )
        {
            qDebug("why not image");
            break;
        }*/

        if ( !layer->keyExists( currentFrame() ) )
        {
            qDebug("why not imagesadfsdaf ssd");
            addNewKey();
        }


        BitmapImage* bitmapImage = layer->getBitmapImageAtFrame( currentFrame() );

        QRect boundaries = img.rect();

        boundaries.moveTopLeft( mScribbleArea->getCentralPoint().toPoint() - QPoint( boundaries.width() / 2, boundaries.height() / 2 ) );
        BitmapImage* importedBitmapImage = new BitmapImage( boundaries, img );
        bitmapImage->paste( importedBitmapImage );

      if(layers()->currentLayerIndex()>2)
      {
        //下面用来框出倒入的图片
        mScribbleArea->mySelection.moveTopLeft(mScribbleArea->getCentralPoint().toPoint() - QPoint( boundaries.width()/1.5, boundaries.height()/1.5) );//这个是为了将值赋给QRectF
        mScribbleArea->mySelection.moveBottomRight(mScribbleArea->getCentralPoint().toPoint() + QPoint( boundaries.width()/1.5, boundaries.height()/1.5));
        mScribbleArea->mySelection.setTopLeft(mScribbleArea->getCentralPoint().toPoint() - QPoint( boundaries.width()/1.5, boundaries.height()/1.5));
        mScribbleArea->mySelection.setBottomRight(mScribbleArea->getCentralPoint().toPoint() + QPoint( boundaries.width()/1.5, boundaries.height()/1.5));
        //mScribbleArea->mySelection.moveBottomRight(QPoint( boundaries.width()/2, boundaries.height()/2));
        mScribbleArea->setSelection( mScribbleArea->mySelection, true );
        mScribbleArea->myTransformedSelection = mScribbleArea->mySelection.adjusted( 0, 0, 0, 0 );
        mScribbleArea->myTempTransformedSelection = mScribbleArea->mySelection.adjusted( 0, 0, 0, 0 );
        mScribbleArea->update();
        mScribbleArea->mIncludeImg[mLayerManager->currentLayerIndex()]=mScribbleArea->mySelection;
        tools()->setCurrentTool(MOVE);
       }
       // scrubTo( currentFrame() + 1 );
    }

    return true;
}
Пример #3
0
bool Editor::importBitmapImage(QString filePath, int space)
{
    QImageReader reader(filePath);

    Q_ASSERT(layers()->currentLayer()->type() == Layer::BITMAP);
    auto layer = static_cast<LayerBitmap*>(layers()->currentLayer());

    QImage img(reader.size(), QImage::Format_ARGB32_Premultiplied);
    if (img.isNull())
    {
        return false;
    }

    while (reader.read(&img))
    {
        if (!layer->keyExists(currentFrame()))
        {
            addNewKey();
        }
        BitmapImage* bitmapImage = layer->getBitmapImageAtFrame(currentFrame());

        BitmapImage importedBitmapImage(mScribbleArea->getCentralPoint().toPoint() - QPoint(img.width() / 2, img.height() / 2), img);
        bitmapImage->paste(&importedBitmapImage);

        if (space > 1) {
            scrubTo(currentFrame() + space);
        } else {
            scrubTo(currentFrame() + 1);
        }

        backup(tr("Import Image"));

        // Workaround for tiff import getting stuck in this loop
        if (!reader.supportsAnimation())
        {
            break;
        }
    }

    return true;
}