本文整理汇总了C++中magick::Image::backgroundColor方法的典型用法代码示例。如果您正苦于以下问题:C++ Image::backgroundColor方法的具体用法?C++ Image::backgroundColor怎么用?C++ Image::backgroundColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类magick::Image
的用法示例。
在下文中一共展示了Image::backgroundColor方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddImage
bool ResourceManager::AddImage(const boost::filesystem::path& path,
const std::string& imgname,
const float width,
const float height,
const std::string& key) {
if(!boost::filesystem::is_regular_file(path/imgname)) {
Logger::Critical(LogOrigin::RESOURCEMANAGER, "Tried loading image path'"+(path/imgname).string()+"' but this image path doesn't exist!");
exit(1);
}
// create Original file path
std::string originalFile = (path / imgname).string();
// if the optional param key is not given, use the basename as key
std::string image_key = "";
if(key == "") {
image_key = boost::filesystem::basename(originalFile);
} else {
image_key = key;
}
// Create Cache Paths
boost::filesystem::path cacheDir = (path / "cached").string();
std::string cacheFile = (cacheDir / image_key ).string()+".png";
// if an image with that key already exists in the dictionary, return
if(mImages.count(image_key) != 0) {
return true;
}
// Log output
Logger::Debug(LogOrigin::RESOURCEMANAGER, "Caching image " + originalFile);
// Create cache directory
boost::filesystem::create_directory(cacheDir.string());
// Load, convert and save image (originalFile > cacheFile)
Magick::Image mimage;
mimage.backgroundColor(Magick::Color(0, 0, 0, 65535));
mimage.density(Magick::Geometry(144, 144));
mimage.read(originalFile);
// Conver floats to view pixels so that images will always be at the same scale
const Vector2D vec(Coordinates::WorldFloatToWorldPixel(Vector2D(width, height)));
mimage.zoom(Magick::Geometry(vec.x, vec.y));
mimage.depth(8);
mimage.write(cacheFile);
// Load cached file
sf::Image sfimage;
sfimage.LoadFromFile(cacheFile);
sfimage.SetSmooth(true);
// Save loaded Image in Dictionary
// mImages.insert(new std::pair<std::string, sf::Image>(image_key, sfimage));
mImages[image_key] = sfimage;
return true;
}
示例2: LayerToImage
/** layerToImage
*
* Converts a layer into an ImageMagick Image
*/
int HandlerUtils::LayerToImage(const Map& map, const Layer& layer, Magick::Image& image)
{
std::vector<Magick::Image> tiles;
if (HandlerUtils::GetTiles(map, tiles))
return -1;
Magick::Color color = Magick::ColorRGB(0, 0, 0);
color.alpha(0);
int width = map.GetWidth() * map.GetTileWidth();
int height = map.GetHeight() * map.GetTileHeight();
image.matte(true);
image.resize(Magick::Geometry(width, height));
image.backgroundColor(color);
image.erase();
return HandlerUtils::LayerToImage(map, layer, tiles, image);
}
示例3: MapToImage
/** MapToImage
*
* Converts a map into an ImageMagick Image
*/
int HandlerUtils::MapToImage(const Map& map, Magick::Image& image)
{
std::vector<Magick::Image> tiles;
if (HandlerUtils::GetTiles(map, tiles))
return -1;
Magick::Color color = Magick::ColorRGB(0, 0, 0);
color.alpha(0);
const Tileset& tileset = map.GetTileset();
uint32_t tile_width, tile_height;
tileset.GetTileDimensions(tile_width, tile_height);
int width = map.GetWidth() * tile_width;
int height = map.GetHeight() * tile_height;
image.matte(true);
image.resize(Magick::Geometry(width, height));
image.backgroundColor(color);
image.erase();
try
{
for (const auto& layer : map.GetLayers())
{
if (HandlerUtils::LayerToImage(map, layer, tiles, image))
return -1;
}
}
catch (Magick::Exception& error_)
{
return -1;
}
return 0;
}
示例4: AddTexture
bool ResourceManager::AddTexture(const boost::filesystem::path& path,
const std::string& imgname,
const float width,
const float height) {
if(!boost::filesystem::is_regular_file(path/imgname)) {
std::cerr << "Tried loading image path '" << (path/imgname).string() << "' but this image path doesn't exist!" << std::endl;
exit(1);
}
// convert coords
const Vector2D size(Coordinates::WorldFloatToWorldPixel(Vector2D(width, height)));
// create Original file path
std::string originalFile = (path / imgname).string();
// if the optional param key is not given, use the basename as key
std::string image_key = boost::filesystem::basename(originalFile);
// Create Cache Paths
boost::filesystem::path cacheDir = (path / "cached").string();
std::string cacheFile = (cacheDir / image_key ).string()+".png";
// if an image with that key already exists in the dictionary, return
if(mTextures.count(image_key) != 0) {
return true;
}
sf::Texture sftexture;
bool cache = true;
if(boost::filesystem::is_regular_file(cacheFile)) {
// Load cached file
bool success = sftexture.LoadFromFile(cacheFile);
if (success && (int)sftexture.GetHeight() == (int)size.x && (int)sftexture.GetWidth() == (int)size.y) {
cache = false;
std::cout << "Texture " << originalFile << " already exists. Not caching. "<< std::endl;
} else if (success) {
std::cout << "Texture " << originalFile << " does not exist in the resolution "
<< size.x << "x" << size.y << " but in " << sftexture.GetHeight() << "x" << sftexture.GetWidth() << "." << std::endl;
}
}
if(cache){
std::cout << ":: Caching image " << originalFile << std::endl;
// Create cache directory
boost::filesystem::create_directory(cacheDir.string());
// Load, convert and save image (originalFile > cacheFile)
Magick::Image mimage;
mimage.backgroundColor(Magick::Color(0, 0, 0, 65535));
mimage.density(Magick::Geometry(144, 144));
mimage.read(originalFile);
mimage.zoom(Magick::Geometry(std::max(size.x,size.y), std::max(size.x,size.y)));
mimage.depth(8);
mimage.write(cacheFile);
// Load cached file
sftexture.LoadFromFile(cacheFile);
}
sftexture.SetSmooth(true);
//std::cout << " Added image: "<<image_key << std::endl;
// Save loaded Texture in Dictionary
mTextures[image_key] = sftexture;
return true;
}
示例5: runtime_error
/*******************************************************************************
* Operations.
******************************************************************************/
ColorLevels::Statistics
ColorLevels::getColorLevels(
ColorLevels::Options options,
std::string imagePath,
Magick::Blob* blob)
{
Magick::Image image;
try {
image.read(imagePath);
} catch (Magick::Exception &e) {
throw std::runtime_error(e.what());
}
/* For simplicity, only support sRGB */
if (image.colorSpace() != Magick::sRGBColorspace)
throw std::logic_error("Unsupported colorspace");
/* Convert sRGB to Lab colorspace */
image.colorSpace(Magick::ColorspaceType::LabColorspace);
ColorLevels::Statistics imageStats;
imageStats.width = image.size().width();
imageStats.height = image.size().height();
imageStats.redPixels = 0;
imageStats.purplePixels = 0;
imageStats.backgroundPixels = 0;
const Magick::PixelPacket *pixels = image.getConstPixels(
0, 0, imageStats.width, imageStats.height);
/* Setup image masks */
Magick::Image maskTransparentImage, maskOriginalImage;
Magick::PixelPacket *maskTransparentPixels, *maskOriginalPixels;
if (options.drawMaskOverTransparent) {
maskTransparentImage = Magick::Image(Magick::Geometry(
imageStats.width, imageStats.height),
Magick::Color("rgba(0,0,0,0)"));
maskTransparentPixels = maskTransparentImage.getPixels(0, 0,
imageStats.width, imageStats.height);
}
if (options.drawMaskOverOriginalImage) {
maskOriginalImage = Magick::Image(imagePath);
maskOriginalPixels = maskOriginalImage.getPixels(0, 0,
imageStats.width, imageStats.height);
}
/* Sanity check color coordinates */
if (options.redCoordinateSet) {
if (options.redCoordinate.x >= imageStats.width)
throw std::runtime_error("Invalid red X value.");
if (options.redCoordinate.y >= imageStats.height)
throw std::runtime_error("Invalid red Y value.");
}
if (options.purpleCoordinateSet) {
if (options.purpleCoordinate.x >= imageStats.width)
throw std::runtime_error("Invalid purple X value.");
if (options.purpleCoordinate.y >= imageStats.height)
throw std::runtime_error("Invalid purple Y value.");
}
if (options.backgroundCoordinateSet) {
if (options.backgroundCoordinate.x >= imageStats.width)
throw std::runtime_error("Invalid background X value.");
if (options.backgroundCoordinate.y >= imageStats.height)
throw std::runtime_error("Invalid background Y value.");
}
/* Setup colors */
const ColorLevels::LAB red = options.redCoordinateSet ?
ColorLevels::LABColorToLAB(static_cast<Magick::ColorRGB>(
pixels[(imageStats.width * options.redCoordinate.x) +
options.redCoordinate.y])) :
ColorLevels::getLABValueOfRGBColor(
Magick::ColorRGB(options.redColor));
if (options.redCoordinateSet && options.verbose)
std::cout << "Red color: " << red << std::endl;
const ColorLevels::LAB purple = options.purpleCoordinateSet ?
ColorLevels::LABColorToLAB(static_cast<Magick::ColorRGB>(
pixels[(imageStats.width * options.purpleCoordinate.x) +
options.purpleCoordinate.y])) :
ColorLevels::getLABValueOfRGBColor(
Magick::ColorRGB(options.purpleColor));
if (options.purpleCoordinateSet && options.verbose)
std::cout << "Purple color: " << purple << std::endl;
const Magick::ColorRGB redMaskColor("#00FF00");
const Magick::ColorRGB purpleMaskColor("#0000FF");
const Magick::ColorRGB backgroundMaskColor("#000000");
/* backgroundColor() returns an sRGB value, even in LAB colorspace */
const ColorLevels::LAB backgroundColor =
options.backgroundCoordinateSet ?
ColorLevels::LABColorToLAB(static_cast<Magick::ColorRGB>(
pixels[(imageStats.width * options.backgroundCoordinate.x) +
options.backgroundCoordinate.y])) :
ColorLevels::getLABValueOfRGBColor(
options.backgroundColor == "" ? image.backgroundColor() :
Magick::ColorRGB(options.backgroundColor));
if ((options.backgroundCoordinateSet ||
options.backgroundColor == "") && options.verbose)
std::cout << "Background color: " << backgroundColor <<
//.........这里部分代码省略.........
示例6:
void Magick::backgroundColorImage::operator()( Magick::Image &image_ ) const
{
image_.backgroundColor( _color );
}