Example #1
0
void PixelMapCreator::saveAsPng( String name, OwnedArray<Slice>& slices, Point<int> resolution )
{
	Image pixelMap = Image( Image::PixelFormat::ARGB, resolution.x, resolution.y, true );
	Graphics g( pixelMap );

	//create a sub array to get a better distribution of colors when lots of slices are disabled
	Array<Slice*> visibleSlices;
	for ( auto slice : slices )
		if ( !slice->screenIsCollapsed && slice->enabled )
			visibleSlices.add( slice );
	
	for ( auto visibleSlice : visibleSlices )
	{
		PixelMapButton b( *visibleSlice );
		b.updatePath( resolution );
		b.paint( g, visibleSlices.indexOf( visibleSlice ) / (float) visibleSlices.size() );
	}

	File tempFile = File( File::getSpecialLocation( File::SpecialLocationType::userDesktopDirectory ).getFullPathName() + "/" + name + ".png" );
	File pngFile;
	FileChooser chooser("Export Pixelmap as...", tempFile, "*.png");
	if ( chooser.browseForFileToSave( true ) )
	{
		pngFile = chooser.getResult();
		if ( pngFile.exists() )
			pngFile.deleteFile();
		if ( !pngFile.hasFileExtension( "png" ) )
			pngFile = File( pngFile.getParentDirectory().getFullPathName() + "/" + pngFile.getFileNameWithoutExtension() + ".png" );
		FileOutputStream stream( pngFile );
		PNGImageFormat pngWriter;
		pngWriter.writeImageToStream( pixelMap, stream );
	}
}
Example #2
0
const String imageToBase64 (const Image &image)
{
	MemoryBlock memoryBlock;
	MemoryOutputStream memoryStream(memoryBlock,true);
	PNGImageFormat png;
	png.writeImageToStream (image, memoryStream);

	return (memoryBlock.toBase64Encoding());
}
void MDLHelper::saveMDLFileAsImage(const MDLFile& mdlFile,
                                       const ContentComp* contentComp)
{
    if (contentComp)
    {
        ObjectsHolder * const oh = contentComp->getHolderComponent();
        Image img = oh->createComponentSnapshot(oh->getObjectsBounds());

        String initFilePath;
        initFilePath << mdlFile.getFile().getParentDirectory().getFullPathName()
            << "/" << mdlFile.getFile().getFileNameWithoutExtension()
            << "_" << Time::getCurrentTime().formatted("%Y%m%d%H%M%S")
            << ".png";

        FileChooser fc(TRANS("Please select the filename for the image") + "...",
                       File::createFileWithoutCheckingPath(initFilePath),
                       "*.png;*.jpg;*.jpeg", true);

        if (fc.browseForFileToSave(true))
        {
            File f(fc.getResult());
            TemporaryFile temp(f);

            ScopedPointer <FileOutputStream> out(temp.getFile().createOutputStream());

            if (out != nullptr)
            {
                bool imgToStreamOk = false;
                if (f.hasFileExtension(".png"))
                {
                    PNGImageFormat png;
                    imgToStreamOk = png.writeImageToStream(img, *out.get());
                }
                else if (f.hasFileExtension(".jpg;.jpeg"))
                {
                    JPEGImageFormat jpeg;
                    imgToStreamOk = jpeg.writeImageToStream(img, *out.get());
                }
                out = nullptr;

                bool succeeded = false;
                if (imgToStreamOk)
                    succeeded = temp.overwriteTargetFileWithTemporary();

                if (succeeded)
                {
                    SAM_CONSOLE("MSG: Wrote file " + f.getFullPathName(), PostLevel::ALL);
                }
                else
                {
                    SAM_CONSOLE("Could not write file " + f.getFullPathName(), PostLevel::ERROR);
                }
            }
        }
    }
}
Example #4
0
void MainContentComponent::buttonClicked(Button* button)
{
	 if (&readFileButton == button) {
		  FileChooser chooser("Choose an image file to display...");
		  if (chooser.browseForFileToOpen()) {
				origImage = ImageFileFormat::loadFrom(chooser.getResult());

				if (origImage.isValid()) {
					 procImage = origImage.createCopy();
					 imageComponent.setImage(procImage);
				}
		  }
	 } else if (&writeFileButton == button) {
		  if (procImage.isValid()) {
				FileChooser chooser("Write processed image to file...");
				
				if (chooser.browseForFileToSave(true)) {
					 FileOutputStream stream(chooser.getResult());
					 PNGImageFormat pngImageFormat;
					 pngImageFormat.writeImageToStream(procImage, stream);
				}
		  }
	 }
}