Matrix operations
-
QImage myMatrix(8,8,QImage::Format_Mono)will create a container of 8 by 8 bits (not bytes).myMatrix.fill(0);to turn everything off.- Point:
myMatrix.setPixel(0,0,1); - Line(1):
for(int i=0;i<myMatrix.width();++i) myMatrix.setPixel(0,i,1); - Column(1):
for(int i=0;i<myMatrix.height();++i) myMatrix.setPixel(i,0,1); - Border:
for(int i=0;i<myMatrix.width();++i) {myMatrix.setPixel(0,i,1); myMatrix.setPixel(myMatrix.height()-1,i,1);} for(int i=0;i<myMatrix.height();++i) {myMatrix.setPixel(i,0,1); myMatrix.setPixel(i,myMatrix.width()-1,1);} - Column Shift(1):
myMatrix=myMatrix.transformed(QTransform().translate(1,0)); - Column Shift(-1):
myMatrix=myMatrix.transformed(QTransform().translate(-1,0)); - Line Shift(1):
myMatrix=myMatrix.transformed(QTransform().translate(0,1)); - Line Shift(-1):
myMatrix=myMatrix.transformed(QTransform().translate(0,-1)); - Rotate(1):
myMatrix=myMatrix.transformed(QTransform().rotate(270)); - Rotate(-1):
myMatrix=myMatrix.transformed(QTransform().rotate(90)); - Invert:
myMatrix.invertPixels();
Great answer !, especially to be adapted to my needs. Anyway, I think I should try with Format_Indexed8 instead as I need to store the color values which requires more than a single bit:
0 : off
1 : Green
2 : Red
3 : Orange(Merci pour cette réponse)