1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833
|
\section{Magick::Image Class}
\scriptsize{
\begin{verbatim}
Quick Contents
* BLOBs
* Constructors
* Image Manipulation Methods
* Image Attributes
* Raw Image Pixel Access
------------------------------------------------------------------------
Image is the primary object in Magick++ and represents a single image frame
(see design). The STL interface must be used to operate on image sequences
or images (e.g. of format GIF, TIFF, MIFF, Postscript, & MNG) which are
comprized of multiple image frames. Individual frames of a multi-frame image
may be requested by adding array-style notation to the end of the file name
(e.g. "animation.gif[3]" retrieves the fourth frame of a GIF animation.
Various image manipulation operations may be applied to the image.
Attributes may be set on the image to influence the operation of the
manipulation operations. The Pixels class provides low-level access to image
pixels. As a convenience, including <Magick++.h> is sufficient in order to
use the complete Magick++ API. The Magick++ API is enclosed within the
Magick namespace so you must either add the prefix "Magick::" to each
class/enumeration name or add the statement "using namespace Magick;" after
including the Magick++.h header.
The preferred way to allocate Image objects is via automatic allocation (on
the stack). There is no concern that allocating Image objects on the stack
will excessively enlarge the stack since Magick++ allocates all large data
objects (such as the actual image data) from the heap. Use of automatic
allocation is preferred over explicit allocation (via new) since it is much
less error prone and allows use of C++ scoping rules to avoid memory leaks.
Use of automatic allocation allows Magick++ objects to be assigned and
copied just like the C++ intrinsic data types (e.g. 'int'), leading to clear
and easy to read code. Use of automatic allocation leads to naturally
exception-safe code since if an exception is thrown, the object is
automatically deallocated once the stack unwinds past the scope of the
allocation (not the case for objects allocated via new).
Image is very easy to use. For example, here is a the source to a program
which reads an image, crops it, and writes it to a new file (the exception
handling is optional but strongly recommended):
#include <Magick++.h>
#include <iostream>
using namespace std;
using namespace Magick;
int main(int argc,char **argv)
{
try {
// Create an image object and read an image
Image image( "girl.gif" );
// Crop the image to specified size
// (Geometry implicitly initialized by char *)
image.crop("100x100+100+100" );
// Write the image to a file
image.write( "x.gif" );
}
catch( Exception &error_ )
{
cout << "Caught exception: " << error_.what() << endl;
return 1;
}
return 0;
}
The following is the source to a program which illustrates the use of
Magick++'s efficient reference-counted assignment and copy-constructor
operations which minimize use of memory and eliminate unncessary copy
operations (allowing Image objects to be efficiently assigned, and copied
into containers). The program accomplishes the following:
1. Read master image.
2. Assign master image to second image.
3. Zoom second image to the size 640x480.
4. Assign master image to a third image.
5. Zoom third image to the size 800x600.
6. Write the second image to a file.
7. Write the third image to a file.
#include <Magick++.h>
#include <iostream>
using namespace std;
using namespace Magick;
int main(int argc,char **argv)
{
Image master("horse.jpg");
Image second = master;
second.zoom("640x480");
Image third = master;
third.zoom("800x600");
second.write("horse640x480.jpg");
third.write("horse800x600.jpg");
return 0;
}
During the entire operation, a maximum of three images exist in memory and
the image data is never copied.
The following is the source for another simple program which creates a 100
by 100 pixel white image with a red pixel in the center and writes it to a
file:
#include <Magick++.h>
using namespace std;
using namespace Magick;
int main(int argc,char **argv)
{
Image image( "100x100", "white" );
image.pixelColor( 49, 49, "red" );
image.write( "red_pixel.png" );
return 0;
}
If you wanted to change the color image to grayscale, you could add the
lines:
image.quantizeColorSpace( GRAYColorspace );
image.colors( 256 );
image.quantize( );
or, more simply:
image.type( GrayscaleType );
prior to writing the image.
BLOBs
While encoded images (e.g. JPEG) are most often written-to and read-from a
disk file, encoded images may also reside in memory. Encoded images in
memory are known as BLOBs (Binary Large OBjects) and may be represented
using the Blob class. The encoded image may be initially placed in memory by
reading it directly from a file, reading the image from a database,
memory-mapped from a disk file, or could be written to memory by Magick++.
Once the encoded image has been placed within a Blob, it may be read into a
Magick++ Image via a constructor or read(). Likewise, a Magick++ image may
be written to a Blob via write().
An example of using Image to write to a Blob follows:
#include <Magick++.h>
using namespace std;
using namespace Magick;
int main(int argc,char **argv)
{
// Read GIF file from disk
Image image( "giraffe.gif" );
// Write to BLOB in JPEG format
Blob blob;
image.magick( "JPEG" ) // Set JPEG output format
image.write( &blob );
[ Use BLOB data (in JPEG format) here ]
return 0;
}
likewise, to read an image from a Blob, you could use one of the following
examples:
[ Entry condition for the following examples is that data is pointer to
encoded image data and length represents the size of the data ]
Blob blob( data, length );
Image image( blob );
or
Blob blob( data, length );
Image image;
image.read( blob);
some images do not contain their size or format so the size and format must
be specified in advance:
Blob blob( data, length );
Image image;
image.size( "640x480")
image.magick( "RGBA" );
image.read( blob);
Constructors
Image may be constructed in a number of ways. It may be constructed from a
file, a URL, or an encoded image (e.g. JPEG) contained in an in-memory BLOB.
The available Image constructors are shown in the following table:
Image Constructors
Signature Description
Construct Image by reading from file or URL
const std::string specified by imageSpec_. Use array notation
&imageSpec_ (e.g. filename[9]) to select a specific scene
from a multi-frame image.
const Geometry &size_, Construct a blank image canvas of specified size
const Color &color_ and color
Construct Image by reading from encoded image
data contained in an in-memory BLOB. Depending
on the constructor arguments, the Blob size,
depth, magick (format) may also be specified.
Some image formats require that size be
specified. The default ImageMagick uses for
const Blob &blob_ depth depends on the compiled-in Quantum size (8
or 16). If ImageMagick's Quantum size does not
match that of the image, the depth may need to
be specified. ImageMagick can usually
automatically detect the image's format. When a
format can't be automatically detected, the
format (magick) must be specified.
const Blob &blob_, const Geometry &size_
const Blob &blob_, const Geometry &size,
unsigned int depth
const Blob &blob_, const Geometry &size,
unsigned int depth_, const string &magick_
const Blob &blob_, const Geometry &size, const
string &magick_
Construct a new Image based on an array of image
pixels. The pixel data must be in scanline order
top-to-bottom. The data can be character, short
int, integer, float, or double. Float and double
require the pixels to be normalized [0..1]. The
other types are [0..MaxRGB]. For example, to
create a 640x480 image from unsigned
red-green-blue character data, use
Image image( 640, 480, "RGB", 0, pixels );
The parameters are as follows:
width_ Width in pixels of the image.
const unsigned int height_ Height in pixels of the image.
width_,
const unsigned int
height_, This character string can be any
std::string map_, combination or order of R = red, G =
const StorageType type_, map_ green, B = blue, A = alpha, C = cyan, Y
const void *pixels_ = yellow M = magenta, and K = black. The
ordering reflects the order of the
pixels in the supplied pixel array.
Pixel storage type (CharPixel,
type_ ShortPixel, IntegerPixel, FloatPixel, or
DoublePixel)
This array of values contain the pixel
components as defined by the map_ and
pixels_ type_ parameters. The length of the
arrays must equal the area specified by
the width_ and height_ values and type_
parameters.
Image Manipulation Methods
Image supports access to all the single-image (versus image-list)
manipulation operations provided by the ImageMagick library. If you must
process a multi-image file (such as an animation), the STL interface, which
provides a multi-image abstraction on top of Image, must be used.
The operations supported by Image are shown in the following table:
Image Image Manipulation Methods
Method Signature(s) Description
addNoise NoiseType noiseType_ Add noise to image with specified noise
type.
const std::string
annotate &text_, const Annotate using specified text, and
Geometry &location_ placement location
string text_, const Annotate using specified text, bounding
Geometry area, and placement gravity. If
&boundingArea_, boundingArea_ is invalid, then bounding
GravityType gravity_ area is entire image.
const std::string
&text_, const Annotate with text using specified
Geometry text, bounding area, placement gravity,
&boundingArea_, and rotation. If boundingArea_ is
GravityType invalid, then bounding area is entire
gravity_, double image.
degrees_,
const std::string
&text_, GravityType Annotate with text (bounding area is
gravity_ entire image) and placement gravity.
Blur image. The radius_ parameter
const double radius_ specifies the radius of the Gaussian,
blur = 1, const double in pixels, not counting the center
sigma_ = 0.5 pixel. The sigma_ parameter specifies
the standard deviation of the
Laplacian, in pixels.
const Geometry Border image (add border to image).
border &geometry_ = The color of the border is specified by
"6x6+0+0" the borderColor attribute.
Extract channel from image. Use this
option to extract a particular channel
channel ChannelType layer_ from the image. MatteChannel for
example, is useful for extracting the
opacity values from an image.
Charcoal effect image (looks like
charcoal sketch). The radius_ parameter
const double radius_ specifies the radius of the Gaussian,
charcoal = 1, const double in pixels, not counting the center
sigma_ = 0.5 pixel. The sigma_ parameter specifies
the standard deviation of the
Laplacian, in pixels.
chop const Geometry Chop image (remove vertical or
&geometry_ horizontal subregion of image)
const unsigned int
opacityRed_, const
unsigned int Colorize image with pen color, using
colorize opacityGreen_, const specified percent opacity for red,
unsigned int green, and blue quantums.
opacityBlue_, const
Color &penColor_
const unsigned int
opacity_, const Colorize image with pen color, using
Color &penColor_ specified percent opacity.
Comment image (add comment string to
image). By default, each image is
commented with its file name. Use
this method to assign a specific
comment const string comment to the image. Optionally you
&comment_
can include the image filename, type,
width, height, or other image
attributes by embedding special format
characters.
const Image
&compositeImage_,
int xOffset_, int Compose an image onto the current image
composite yOffset_, at offset specified by xOffset_,
CompositeOperator yOffset_ using the composition
compose_ = algorithm specified by compose_.
InCompositeOp
const Image
&compositeImage_,
const Geometry Compose an image onto the current image
&offset_, at offset specified by offset_ using
CompositeOperator the composition algorithm specified by
compose_ = compose_.
InCompositeOp
const Image
&compositeImage_,
GravityType Compose an image onto the current image
gravity_, with placement specified by gravity_
CompositeOperator using the composition algorithm
compose_ = specified by compose_.
InCompositeOp
contrast unsigned int Contrast image (enhance intensity
sharpen_ differences in image)
Convolve image. Applies a
user-specfied convolution to the image.
unsigned int order_, The order_ parameter represents the
convolve const double number of columns and rows in the
*kernel_ filter kernel, and kernel_ is a
two-dimensional array of doubles
representing the convolution kernel to
apply.
crop const Geometry Crop image (subregion of original
&geometry_ image)
cycleColormap int amount_ Cycle image colormap
despeckle void Despeckle image (reduce speckle noise)
Display image on screen.
Caution: if an image format is is not
compatable with the display visual
display void (e.g. JPEG on a colormapped display)
then the original image will be
altered. Use a copy of the original if
this is a problem.
draw const Drawable Draw shape or text on image.
&drawable_
Draw shapes or text on image using a
const set of Drawable objects contained in an
std::list<Drawable> STL list. Use of this method improves
&drawable_ drawing performance and allows batching
draw objects together in a list for
repeated use.
Edge image (hilight edges in image).
edge unsigned int radius_ The radius is the radius of the pixel
= 0.0 neighborhood.. Specify a radius of zero
for automatic radius selection.
Emboss image (hilight edges with 3D
effect). The radius_ parameter
const double radius_ specifies the radius of the Gaussian,
emboss = 1, const double in pixels, not counting the center
sigma_ = 0.5 pixel. The sigma_ parameter specifies
the standard deviation of the
Laplacian, in pixels.
enhance void Enhance image (minimize noise)
equalize void Equalize image (histogram equalization)
erase void Set all image pixels to the current
background color.
flip void Flip image (reflect each scanline in
the vertical direction)
unsigned int x_, Flood-fill color across pixels that
floodFill- unsigned int y_, match the color of the target pixel and
Color const Color are neighbors of the target pixel. Uses
&fillColor_ current fuzz setting when determining
color match.
const Geometry
&point_, const Color
&fillColor_
unsigned int x_, Flood-fill color across pixels starting
unsigned int y_, at target-pixel and stopping at pixels
const Color matching specified border color. Uses
&fillColor_, const current fuzz setting when determining
Color &borderColor_ color match.
const Geometry
&point_, const Color
&fillColor_, const
Color &borderColor_
const long x_, const
long y_, const Floodfill pixels matching color (within
floodFillOpacityunsigned int fuzz factor) of target pixel(x,y) with
opacity_, const replacement opacity value using method.
PaintMethod method_
unsigned int x_, Flood-fill texture across pixels that
floodFill- unsigned int y_, match the color of the target pixel and
Texture const Image are neighbors of the target pixel. Uses
&texture_ current fuzz setting when determining
color match.
const Geometry
&point_, const Image
&texture_
unsigned int x_, Flood-fill texture across pixels
unsigned int y_, starting at target-pixel and stopping
const Image at pixels matching specified border
&texture_, const color. Uses current fuzz setting when
Color &borderColor_ determining color match.
const Geometry
&point_, const Image
&texture_, const
Color &borderColor_
flop void Flop image (reflect each scanline in
the horizontal direction)
const Geometry
frame &geometry_ = Add decorative frame around image
"25x25+6+6"
unsigned int width_,
unsigned int
height_, int x_, int
y_, int innerBevel_
= 0, int outerBevel_
= 0
gamma double gamma_ Gamma correct image (uniform red,
green, and blue correction).
double gammaRed_,
double gammaGreen_, Gamma correct red, green, and blue
double gammaBlue_ channels of image.
Gaussian blur image. The number of
neighbor pixels to be included in the
convolution mask is specified by
gaussianBlur double width_, 'width_'. For example, a width of one
double sigma_ gives a (standard) 3x3 convolution
mask. The standard deviation of the
Gaussian bell curve is specified by
'sigma_'.
implode double factor_ Implode image (special effect)
Assign a label to an image. Use this
option to assign a specific label to
the image. Optionally you can include
the image filename, type, width,
height, or scene number in the label by
embedding special format characters.
label const string &label_ If the first character of string is @,
the image label is read from a file
titled by the remaining characters in
the string. When converting to
Postscript, use this option to specify
a header string to print above the
image.
magnify void Magnify image by integral size
Remap image colors with closest color
from reference image. Set dither_ to
true in to apply Floyd/Steinberg error
const Image diffusion to the image. By default,
map &mapImage_ , bool color reduction chooses an optimal
dither_ = false set of colors that best represent the
original image. Alternatively, you can
choose a particular set of colors
from an image file with this option.
const Color
&target_, unsigned
matteFloodfill int opacity_, long Floodfill designated area with a
x_, long y_, replacement opacity value.
PaintMethod method_
Filter image by replacing each pixel
medianFilter const double radius_ component with the median color in a
= 0.0
circular neighborhood
minify void Reduce image by integral size
Prepare to update image. Ensures that
there is only one reference to the
underlying image so that the underlying
modifyImage void image may be safely modified without
effecting previous generations of the
image. Copies the underlying image to a
new image if necessary.
double brightness_,
modulate double saturation_, Modulate percent hue, saturation, and
double hue_ brightness of an image
Negate colors in image. Replace every
pixel with its complementary color
negate bool grayscale_ = (white becomes black, yellow becomes
false
blue, etc.). Set grayscale to only
negate grayscale values in image.
Normalize image (increase contrast by
normalize void normalizing the pixel values to span
the full range of color values).
oilPaint unsigned int radius_ Oilpaint image (image looks like oil
= 3 painting)
Set or attenuate the opacity channel in
the image. If the image pixels are
opaque then they are set to the
specified opacity value, otherwise they
are blended with the supplied opacity
opacity unsigned int value. The value of opacity_ ranges
opacity_
from 0 (completely opaque) to MaxRGB.
The defines OpaqueOpacity and
TransparentOpacity are available to
specify completely opaque or completely
transparent, respectively.
const Color
opaque &opaqueColor_, const Change color of pixels matching
Color &penColor_ opaqueColor_ to specified penColor_.
Ping is similar to read except only
enough of the image is read to
determine the image columns, rows, and
ping const std::string filesize. The columns, rows, and
&imageSpec_
fileSize attributes are valid after
invoking ping. The image data is not
valid after calling ping.
Quantize image (reduce number of
quantize bool measureError_ = colors). Set measureError_ to true in
false
order to calculate error attributes.
const Geometry
Raise image (lighten or darken the
raise &geometry_ = edges of an image to give a 3-D raised
"6x6+0+0", bool
raisedFlag_ = false or lowered effect)
read const string Read image into current object
&imageSpec_
Read image of specified size into
current object. This form is useful for
images that do not specifiy their size
const Geometry or to specify a size hint for decoding
an image. For example, when reading a
&size_, const Photo CD, JBIG, or JPEG image, a size
std::string
&imageSpec_ request causes the library to return an
image which is the next resolution
greater or equal to the specified size.
This may result in memory and time
savings.
Read encoded image of specified size
from an in-memory BLOB into current
object. Depending on the method
arguments, the Blob size, depth, and
format may also be specified. Some
image formats require that size be
specified. The default ImageMagick uses
const Blob &blob_ for depth depends on its Quantum size
(8 or 16). If ImageMagick's Quantum
size does not match that of the image,
the depth may need to be specified.
ImageMagick can usually automatically
detect the image's format. When a
format can't be automatically detected,
the format must be specified.
const Blob &blob_,
const Geometry
&size_
const Blob &blob_,
const Geometry
&size_, unsigned int
depth_
const Blob &blob_,
const Geometry
&size_, unsigned
short depth_, const
string &magick_
const Blob &blob_,
const Geometry
&size_, const string
&magick_
Read image based on an array of image
pixels. The pixel data must be in
scanline order top-to-bottom. The data
can be character, short int, integer,
float, or double. Float and double
require the pixels to be normalized
[0..1]. The other types are
[0..MaxRGB]. For example, to create a
640x480 image from unsigned
red-green-blue character data, use
image.read( 640, 480, "RGB", 0,
pixels );
The parameters are as follows:
width_ Width in pixels of the image.
const unsigned int height_Height in pixels of the image.
width_, const
unsigned int This character string can be
height_, std::string any combination or order of R
map_, const = red, G = green, B = blue, A
StorageType type_, = alpha, C = cyan, Y = yellow
const void *pixels_ map_ M = magenta, and K = black.
The ordering reflects the
order of the pixels in the
supplied pixel array.
Pixel storage type (CharPixel,
type_ ShortPixel, IntegerPixel,
FloatPixel, or DoublePixel)
This array of values contain
the pixel components as
defined by the map_ and type_
pixels_parameters. The length of the
arrays must equal the area
specified by the width_ and
height_ values and type_
parameters.
reduceNoise void Reduce noise in image using a noise
peak elimination filter.
unsigned int order_
Roll image (rolls image vertically and
roll int columns_, int horizontally) by specified number of
rows_
columnms and rows)
rotate double degrees_ Rotate image counter-clockwise by
specified number of degrees.
sample const Geometry Resize image by using pixel sampling
&geometry_ algorithm
scale const Geometry Resize image by using simple ratio
&geometry_ algorithm
Segment (coalesce similar image
components) by analyzing the histograms
of the color components and identifying
units that are homogeneous with the
double fuzzy c-means technique. Also uses
clusterThreshold_ = quantizeColorSpace and verbose image
attributes. Specify clusterThreshold_,
segment 1.0, as the number of pixels each
double
smoothingThreshold_ cluster must exceed the cluster
= 1.5 threshold to be considered valid.
SmoothingThreshold_ eliminates noise in
the second derivative of the
histogram. As the value is increased,
you can expect a smoother second
derivative. The default is 1.5.
Shade image using distant light source.
double azimuth_ = Specify azimuth_ and elevation_ as the
30, double position of the light source. By
shade elevation_ = 30, default, the shading results as a
bool colorShading_ = grayscale image.. Set colorShading_ to
false true to shade the red, green, and blue
components of the image.
Sharpen pixels in image. The radius_
const double radius_ parameter specifies the radius of the
sharpen = 1, const double Gaussian, in pixels, not counting the
sigma_ = 0.5 center pixel. The sigma_ parameter
specifies the standard deviation of the
Laplacian, in pixels.
shave const Geometry Shave pixels from image edges.
&geometry_
Shear image (create parallelogram by
sliding image by X or Y axis).
Shearing slides one edge of an image
along the X or Y axis, creating a
parallelogram. An X direction shear
slides an edge along the X axis, while
a Y direction shear slides an edge
shear double xShearAngle_, along the Y axis. The amount of the
double yShearAngle_ shear is controlled by a shear angle.
For X direction shears, x degrees is
measured relative to the Y axis, and
similarly, for Y direction shears y
degrees is measured relative to the X
axis. Empty triangles left over from
shearing the image are filled with
the color defined as borderColor.
Solarize image (similar to effect seen
solarize double factor_ = when exposing a photographic film to
50.0
light during the development process)
spread unsigned int amount_ Spread pixels randomly within image by
= 3 specified amount
stegano const Image Add a digital watermark to the image
&watermark_ (based on second image)
Create an image which appears in stereo
stereo const Image when viewed with red-blue glasses (Red
&rightImage_
image on left, blue on right)
swirl double degrees_ Swirl image (image pixels are rotated
by degrees)
texture const Image Layer a texture on pixels matching
&texture_ image background color.
threshold double threshold_ Threshold image
transform const Geometry Transform image based on image and crop
&imageGeometry_ geometries. Crop geometry is optional.
const Geometry
&imageGeometry_,
const Geometry
&cropGeometry_
transparent const Color &color_ Add matte image to image, setting
pixels matching color to transparent.
trim void Trim edges that are the background
color from the image.
Replace image with a sharpened version
of the original image using the unsharp
mask algorithm. The radius_ parameter
specifies the radius of the Gaussian,
in pixels, not counting the center
double radius_, pixel. The sigma_ parameter specifies
unsharpmask double sigma_, the standard deviation of the Gaussian,
double amount_, in pixels. The amount_ parameter
double threshold_ specifies the percentage of the
difference between the original and the
blur image that is added back into the
original. The threshold_ parameter
specifies the threshold in pixels
needed to apply the diffence amount.
double amplitude_ =
wave 25.0, double Alter an image along a sine wave.
wavelength_ = 150.0
Write image to a file using filename
imageSpec_.
Caution: if an image format is selected
which is capable of supporting fewer
write const string colors than the original image or
&imageSpec_
quantization has been requested, the
original image will be quantized to
fewer colors. Use a copy of the
original if this is a problem.
Write image to a in-memory BLOBstored
in blob_. The magick_ parameter
specifies the image format to write
(defaults to magick ). The depth_
parameter species the image depth
(defaults to depth).
Blob *blob_ Caution: if an image format is selected
which is capable of supporting fewer
colors than the original image or
quantization has been requested, the
original image will be quantized to
fewer colors. Use a copy of the
original if this is a problem.
Blob *blob_,
std::string &magick_
Blob *blob_,
std::string
&magick_, unsigned
int depth_
Write pixel data into a buffer you
supply. The data is saved either as
char, short int, integer, float or
double format in the order specified by
the type_ parameter. For example, we
want to extract scanline 1 of a 640x480
image as character data in
red-green-blue order:
image.write(0,0,640,1,"RGB",0,pixels);
The parameters are as follows:
Horizontal ordinate of
x_ left-most coordinate of
region to extract.
Vertical ordinate of top-most
y_ coordinate of region to
extract.
const int x_, const Width in pixels of the region
int y_, const columns_to extract.
unsigned int
columns_, const
unsigned int rows_, rows_ Height in pixels of the
const std::string region to extract.
&map_, const
StorageType type_, This character string can be
void *pixels_ any combination or order of R
= red, G = green, B = blue, A
map_ = alpha, C = cyan, Y =
yellow, M = magenta, and K =
black. The ordering reflects
the order of the pixels in
the supplied pixel array.
Pixel storage type
type_ (CharPixel, ShortPixel,
IntegerPixel, FloatPixel, or
DoublePixel)
This array of values contain
the pixel components as
defined by the map_ and type_
pixels_ parameters. The length of the
arrays must equal the area
specified by the width_ and
height_ values and type_
parameters.
zoom const Geometry Zoom image to specified size.
&geometry_
Image Attributes
Image attributes are set and obtained via methods in Image. Except for
methods which accept pointer arguments (e.g. chromaBluePrimary) all methods
return attributes by value.
The supported image attributes and the method arguments required to obtain
them are shown in the following table:
Image Image Attributes
Attribute Type Get Set Signature Description
Signature
Join images into a
adjoin bool void bool flag_ single multi-image
file.
Control antialiasing
of rendered
antiAlias bool void bool flag_ Postscript and
Postscript or
TrueType fonts.
Enabled by default.
Time in 1/100ths of a
second (0 to 65535)
which must expire
before displaying the
next image in an
animation- unsigned int (0 unsigned int animated sequence.
Delay to 65535) void delay_ This option is useful
for regulating the
animation of a
sequence of GIF
images within
Netscape.
Number of iterations
animation- unsigned int to loop an animation
Iterations unsigned int void iterations_ (e.g. Netscape loop
extension) for.
background- const Color Image background
Color Color void &color_ color
Image file name to
background- const string use as the background
Texture string void &texture_ texture. Does not
modify image pixels.
Base image width
baseColumns unsigned int void (before
transformations)
Base image filename
baseFilename string void (before
transformations)
Base image height
baseRows unsigned int void (before
transformations)
borderColor Color void const Color Image border color
&color_
Return smallest
bounding box
enclosing non-border
pixels. The current
boundingBox Geometry void fuzz value is used
when discriminating
between pixels. This
is the crop bounding
box used by
crop(Geometry(0,0)).
Base color that
boxColor Color void const Color annotation text is
&boxColor_
rendered on.
Pixel cache threshold
in megabytes. Once
this threshold is
exceeded, all
subsequent pixels
cacheThreshold unsigned int unsigned int cache operations are
to/from disk. This is
a static method and
the attribute it sets
is shared by all
Image objects.
chroma- float *x_, Chromaticity blue
BluePrimary float x & y float *y_ float x_, float y_ primary point (e.g.
x=0.15, y=0.06)
chroma- float *x_, Chromaticity green
GreenPrimary float x & y float *y_ float x_, float y_ primary point (e.g.
x=0.3, y=0.6)
chroma- float *x_, Chromaticity red
RedPrimary float x & y float *y_ float x_, float y_ primary point (e.g.
x=0.64, y=0.33)
chroma- float *x_, Chromaticity white
WhitePoint float x & y float *y_ float x_, float y_ point (e.g. x=0.3127,
y=0.329)
Image storage class.
Note that conversion
from a DirectClass
image to a
classType ClassType void ClassType class_ PseudoClass image may
result in a loss of
color due to the
limited size of the
palette (256 or 65535
colors).
Associate a clip mask
image with the
current image. The
clip mask image must
have the same
dimensions as the
current image or an
clipMask Image void const Image exception is thrown.
&clipMask_ Clipping occurs
wherever pixels are
transparent in the
clip mask image.
Clipping Pass an
invalid image to
unset an existing
clip mask.
Colors within this
distance are
considered equal. A
number of algorithms
search for a target
colorFuzz double void double fuzz_ color. By default the
color must be exact.
Use this option to
match colors that are
close to the target
color in RGB space.
unsigned int
colorMap Color unsigned int index_, const Color at color-pallet
index_ index.
Color &color_
The colorspace (e.g.
CMYK) used to
represent the image
colorSpace ColorspaceType void ColorspaceType pixel colors. Image
colorSpace_ colorSpace_ pixels are always
stored as RGB(A)
except for the case
of CMY(K).
columns unsigned int void Image width
comment string void Image comment
Image compresion
compress- CompressionType type. The default is
Type CompressionType void compressType_ the compression type
of the specified
image file.
Vertical and
horizontal resolution
in pixels of the
image. This option
density Geometry void const Geometry specifies an image
(default 72x72) &density_ density when decoding
a Postscript or
Portable Document
page. Often used with
psPageSize.
Image depth. Used to
specify the bit depth
when reading or
writing raw images
or when the output
depth unsigned int (8 void unsigned int format supports
or 16) depth_
multiple depths.
Defaults to the
quantum depth that
ImageMagick is
compiled with.
Specify (or obtain)
endian EndianType void EndianType endian_ endian option for
formats which support
it.
Tile names from
directory string void within an image
montage
fileName string void const string Image file name.
&fileName_
fileSize off_t void Number of bytes of
the image on disk
fillColor Color void const Color Color to use when
&fillColor_ filling drawn objects
Pattern image to use
fillPattern Image void const Image when filling drawn
&fillPattern_
objects.
const Rule to use when
fillRule FillRule void Magick::FillRule filling drawn
&fillRule_ objects.
Filter to use when
resizing image. The
reduction filter
employed has a
sigificant effect on
the time required to
filterType FilterTypes void FilterTypes resize an image and
filterType_ the resulting
quality. The default
filter is Lanczos
which has been shown
to produce high
quality results when
reducing most images.
Text rendering font.
If the font is a
fully qualified X
server font name, the
font is obtained from
an X server. To use
font string void const string a TrueType font,
&font_
precede the TrueType
filename with an @.
Otherwise, specify
a Postscript font
name (e.g.
"helvetica").
fontPointsize unsigned int void unsigned int Text rendering font
pointSize_ point size
const Update metrics with
std::string font type metrics
fontTypeMetrics TypeMetric &text_, using specified text,
TypeMetric and current font and
*metrics fontPointSize
settings.
format string void Long form image
format description.
Gamma level of the
image. The same color
image displayed on
two different
double (typical workstations may
gamma range 0.8 to void look different due
2.3) to differences in the
display monitor. Use
gamma correction to
adjust for this
color difference.
geometry Geometry void Preferred size of the
image when encoding.
unsigned int
{ 0 = Disposal
not specified,
1 = Do not GIF disposal method.
dispose of This option is used
graphic, to control how
gifDispose- 3 = Overwrite unsigned int successive frames are
Method graphic with void disposeMethod_ rendered (how the
background preceding frame is
color, disposed of) when
4 = Overwrite creating a GIF
graphic with animation.
previous
graphic. }
ICC color profile.
Supplied via a Blob
since Magick++/ and
ImageMagick do not
currently support
formating this data
iccColorProfile Blob void const Blob structure directly.
&colorProfile_
Specifications are
available from the
International Color
Consortium for the
format of ICC color
profiles.
The type of
interlacing scheme
(default
NoInterlace). This
option is used to
specify the type of
interlacing scheme
for raw image
formats such as RGB
or YUV. NoInterlace
means do not
interlace,
LineInterlace uses
scanline interlacing,
interlace- InterlaceType and PlaneInterlace
Type InterlaceType void interlace_ uses plane
interlacing.
PartitionInterlace is
like PlaneInterlace
except the different
planes are saved to
individual files
(e.g. image.R,
image.G, and
image.B). Use
LineInterlace or
PlaneInterlace to
create an interlaced
GIF or progressive
JPEG image.
IPTC profile.
Supplied via a Blob
since Magick++ and
ImageMagick do not
currently support
formating this data
iptcProfile Blob void const Blob& structure directly.
iptcProfile_
Specifications are
available from the
International Press
Telecommunications
Council for IPTC
profiles.
label string void const string Image label
&label_
magick string void const string Get image format
&magick_ (e.g. "GIF")
True if the image has
transparency. If set
matte bool void bool matteFlag_ True, store matte
channel if the image
has one otherwise
create an opaque one.
matteColor Color void const Color Image matte
&matteColor_ (transparent) color
The mean error per
pixel computed when
an image is color
meanError- reduced. This
PerPixel double void parameter is only
valid if verbose is
set to true and the
image has just been
quantized.
monochrome bool void bool flag_ Transform the image
to black and white
Tile size and offset
montage- within an image
Geometry Geometry void montage. Only valid
for montage images.
The normalized max
error per pixel
computed when an
image is color
normalized- reduced. This
MaxError double void parameter is only
valid if verbose is
set to true and the
image has just been
quantized.
The normalized mean
error per pixel
computed when an
image is color
normalized- reduced. This
MeanError double void parameter is only
valid if verbose is
set to true and the
image has just been
quantized.
The number of
packets unsigned int void runlength-encoded
packets in
the image
packetSize unsigned int void The number of bytes
in each pixel packet
Preferred size and
location of an image
canvas.
Use this option to
specify the
dimensions and
position of the
Postscript page in
page Geometry void const Geometry dots per inch or a
&pageSize_ TEXT page in pixels.
This option is
typically used in
concert with density.
Page may also be used
to position a GIF
image (such as for a
scene in an
animation)
unsigned int unsigned int x_,
pixelColor Color x_, unsigned unsigned int y_, Get/set pixel color
int y_ const Color at location x & y.
&color_
JPEG/MIFF/PNG
quality unsigned int (0 void unsigned int compression level
to 100) quality_
(default 75).
Preferred number of
colors in the image.
The actual number of
colors in the image
may be less than your
quantize- unsigned int request, but never
Colors unsigned int void colors_ more. Images with
less unique colors
than specified with
this option will have
any duplicate or
unused colors
removed.
Colorspace to
quantize colors in
(default RGB).
Empirical evidence
suggests that
distances in color
spaces such as YUV or
quantize- ColorspaceType YIQ correspond to
ColorSpace ColorspaceType void colorSpace_ perceptual color
differences more
closely than do
distances in RGB
space. These color
spaces may give
better results when
color reducing an
image.
Apply Floyd/Steinberg
error diffusion to
the image. The basic
strategy of dithering
is to trade
intensity resolution
for spatial
resolution by
averaging the
intensities of
quantize- several neighboring
Dither bool void bool flag_ pixels. Images which
suffer from severe
contouring when
reducing colors can
be improved with this
option. The
quantizeColors or
monochrome option
must be set for this
option to take
effect.
Depth of the
quantization color
classification tree.
Values of 0 or 1
allow selection of
quantize- unsigned int the optimal tree
TreeDepth unsigned int void treeDepth_ depth for the color
reduction algorithm.
Values between 2 and
8 may be used to
manually adjust the
tree depth.
rendering- RenderingIntent The type of rendering
Intent RenderingIntent void render_ intent
resolution- ResolutionType Units of image
Units ResolutionType void units_ resolution
rows unsigned int void The number of pixel
rows in the image
scene unsigned int void unsigned int Image scene number
scene_
Image MD5 signature.
Set force_ to 'true'
signature string bool force_ to force
= false
re-computation of
signature.
Width and height of a
raw image (an image
which does not
support width and
height information).
size Geometry void const Geometry Size may also be used
&geometry_
to affect the image
size read from a
multi-resolution
format (e.g. Photo
CD, JBIG, or JPEG.
Enable or disable
strokeAntiAlias bool void bool flag_ anti-aliasing when
drawing object
outlines.
Color to use when
strokeColor Color void const Color drawing object
&strokeColor_
outlines
While drawing using a
dash pattern, specify
strokeDashOffsetunsigned int void double distance into the
strokeDashOffset_
dash pattern to start
the dash (default 0).
Specify the pattern
of dashes and gaps
used to stroke paths.
The strokeDashArray
represents a
zero-terminated array
of numbers that
specify the lengths
(in pixels) of
alternating dashes
and gaps in user
strokeDashArray const double* void const double* units. If an odd
strokeDashArray_ number of values is
provided, then the
list of values is
repeated to yield an
even number of
values. A typical
strokeDashArray_
array might contain
the members 5 3 2 0,
where the zero value
indicates the end of
the pattern array.
Specify the shape to
be used at the
corners of paths (or
other vector shapes)
strokeLineCap LineCap void LineCap lineCap_ when they are
stroked. Values of
LineJoin are
UndefinedJoin,
MiterJoin, RoundJoin,
and BevelJoin.
Specify the shape to
be used at the
corners of paths (or
other vector shapes)
strokeLineJoin LineJoin void LineJoin lineJoin_ when they are
stroked. Values of
LineJoin are
UndefinedJoin,
MiterJoin, RoundJoin,
and BevelJoin.
Specify miter limit.
When two line
segments meet at a
sharp angle and miter
joins have been
specified for
'lineJoin', it is
possible for the
strokeMiterLimitunsigned int void unsigned int miter to extend far
miterLimit_ beyond the thickness
of the line stroking
the path. The
miterLimit' imposes a
limit on the ratio of
the miter length to
the 'lineWidth'. The
default value of this
parameter is 4.
Stroke width for use
strokeWidth double void double when drawing vector
strokeWidth_
objects (default one)
Pattern image to use
strokePattern Image void const Image while drawing object
&strokePattern_
stroke (outlines).
subImage unsigned int void unsigned int Subimage of an image
subImage_ sequence
Number of images
subRange unsigned int void unsigned int relative to the base
subRange_
image
tileName string void const string Tile name
&tileName_
totalColors unsigned long void Number of colors in
the image
type ImageType void ImageType Image type.
Print detailed
verbose bool void bool verboseFlag_ information about the
image
view string void const string FlashPix viewing
&view_ parameters.
X11 display to
x11Display string (e.g. void const string display to, obtain
"hostname:0.0") &display_ fonts from, or to
capture image from
xResolution double void x resolution of the
image
yResolution double void y resolution of the
image
Raw Image Pixel Access
Image pixels (of type PixelPacket) may be accessed directly via the Image
Pixel Cache. The image pixel cache is a rectangular window into the actual
image pixels (which may be in memory, memory-mapped from a disk file, or
entirely on disk). Two interfaces exist to access the Image Pixel Cache. The
interface described here (part of the Image class) supports only one view at
a time. See the Pixels class for a more abstract interface which supports
simultaneous pixel views (up to the number of rows). As an analogy, the
interface described here relates to the Pixels class as stdio's gets()
relates to fgets(). The Pixels class provides the more general form of the
interface.
Obtain existing image pixels via getPixels(). Create a new pixel region
using setPixels().
Depending on the capabilities of the operating system, and the relationship
of the window to the image, the pixel cache may be a copy of the pixels in
the selected window, or it may be the actual image pixels. In any case
calling syncPixels() insures that the base image is updated with the
contents of the modified pixel cache. The method readPixels() supports
copying foreign pixel data formats into the pixel cache according to the
QuantumTypes. The method writePixels() supports copying the pixels in the
cache to a foreign pixel representation according to the format specified by
QuantumTypes.
The pixel region is effectively a small image in which the pixels may be
accessed, addressed, and updated, as shown in the following example:
Image image("cow.png");
// Obtain pixel region with size 60x40, and top origin at 20x30
int columns = 60;
PixelPacket *pixel_cache = image.GetPixels(20,30,columns,40);
// Set pixel at column 5, and row 10 in the pixel cache to red.
int column = 5; [Cache.png]
int row = 10;
PixelPacket *pixel =
pixel_cache+row*columns*sizeof(PixelPacket)+column;
pixel = Color("red");
// Save updated pixel cache back to underlying image
image.syncPixels();
image.write("horse.png");
The image cache supports the following methods:
Image Cache Methods
Method Returns Signature Description
int x_, int y_, Transfers pixels from
the image to the pixel
getConstPixels const unsigned int cache as defined by
PixelPacket* columns_, unsigned
int rows_ the specified
rectangular region.
Returns a pointer to
the Image pixel
indexes. Only valid
for PseudoClass images
or CMYKA images. The
pixel indexes
represent an array of
type IndexPacket, with
each entry
getConstIndexes const void corresponding to an
IndexPacket* x,y pixel position.
For PseudoClass
images, the entry's
value is the offset
into the colormap (see
colorMap) for that
pixel. For CMYKA
images, the indexes
are used to contain
the alpha channel.
Returns a pointer to
the Image pixel
indexes corresponding
to the pixel region
requested by the last
getConstPixels,
getPixels, or
setPixels call. Only
valid for PseudoClass
images or CMYKA
images. The pixel
indexes represent an
getIndexes IndexPacket* void array of type
IndexPacket, with each
entry corresponding to
a pixel x,y position.
For PseudoClass
images, the entry's
value is the offset
into the colormap (see
colorMap) for that
pixel. For CMYKA
images, the indexes
are used to contain
the alpha channel.
Transfers pixels from
the image to the pixel
cache as defined by
int x_, int y_, the specified
getPixels PixelPacket* unsigned int rectangular region.
columns_, unsigned Modified pixels may be
int rows_ subsequently
transferred back to
the image via
syncPixels.
Allocates a pixel
cache region to store
int x_, int y_, image pixels as
defined by the region
setPixels PixelPacket* unsigned int rectangle. This area
columns_, unsigned
int rows_ is subsequently
transferred from the
pixel cache to the
image via syncPixels.
Transfers the image
syncPixels void void cache pixels to the
image.
Transfers one or more
pixel components from
a buffer or file into
QuantumTypes the image pixel cache
readPixels void quantum_, unsigned of an image.
char *source_, ReadPixels is
typically used to
support image
decoders.
Transfers one or more
pixel components from
QuantumTypes the image pixel cache
writePixels void quantum_, unsigned to a buffer or file.
char *destination_ WritePixels is
typically used to
support image
encoders.
\end{verbatim}
}
|