I need to display a CameraPreview widget and an image (separately) with the contrast adjusted on both. I've been looking into the ColorFiltered and ShaderMask widgets but I'm not sure what blend mode to use or if it will be helpful to change the blend mode. Does anyone have any examples of changing the contrast?
Hey I would recommend you to use you a color matrix to achieve your desired contrast.
You could use following Color matrix within an ColoFiltered widget:
class CustomSubFilters extends ColorFilter {
CustomSubFilters.matrix(List<double> matrix) : super.matrix(matrix);
factory CustomSubFilters.contrast(double c) {
num t = (1.0 - (1 + c)) / 2.0 * 255;
return CustomSubFilters.matrix(<double>[
1 + c,
0,
0,
0,
t,
0,
1 + c,
0,
0,
t,
0,
0,
1 + c,
0,
t,
0,
0,
0,
1,
0,
]);
}
}
Simply just wrap your widget within a ColorFiltered widget and use this colormatrix.
I used Camera plugin and there was no inbuilt feature in package to set contrast/brightness so I have set it by ColorFiltered widget as:
ColorFiltered(
colorFilter: const ColorFilter.mode(
Colors.white,
BlendMode.softLight,
// BlendMode.overlay,
),
child: CameraPreview(camController),
)
It worked for me. I hope, this solution will also help you. Thanks a lot for asking this question.
Related
In Flutter, if we use the ColorFilter widget, it takes a ColorFilter.matrix and an Image, on which it applies the ColorFilter.matrix.
const ColorFilter sepia = ColorFilter.matrix(<double>[
0.393, 0.769, 0.189, 0, 0,
0.349, 0.686, 0.168, 0, 0,
0.272, 0.534, 0.131, 0, 0,
0, 0, 0, 1, 0,
]);
Container _buildFilterThumbnail(int index, Size size) {
final Image image = Image.file(
widget.imageFile,
width: size.width,
fit: BoxFit.cover,
);
return Container(
padding: const EdgeInsets.all(4.0),
decoration: BoxDecoration(
border: Border.all(color: _selectedIndex == index ? Colors.blue : Theme.of(context).primaryColor, width: 4.0),
),
child: ColorFiltered(
colorFilter: ColorFilter.matrix(filters[index].matrixValues),
child: Container(
height: 80,
width: 80,
child: image,
),
),
);
}
How can we get the underlying image (in pixels/bytes) so that it can be saved on disk. I don't want to save the rendered ColorFiltered area on the screen.
Curretly am forced to use the photofilters library from pub.dev, which does the pixel manipulation to apply the custom filters. However, its not very efficient and essentially applies the pixel level manipulation for every thumbnail, making it very slow. On the other hand, ColorFiltered widget is lightening fast!
Below is internal working of photofilters library
int clampPixel(int x) => x.clamp(0, 255);
// ColorOverlay - add a slight color overlay.
void colorOverlay(Uint8List bytes, num red, num green, num blue, num scale) {
for (int i = 0; i < bytes.length; i += 4) {
bytes[i] = clampPixel((bytes[i] - (bytes[i] - red) * scale).round());
bytes[i + 1] =
clampPixel((bytes[i + 1] - (bytes[i + 1] - green) * scale).round());
bytes[i + 2] =
clampPixel((bytes[i + 2] - (bytes[i + 2] - blue) * scale).round());
}
}
// RGB Scale
void rgbScale(Uint8List bytes, num red, num green, num blue) {
for (int i = 0; i < bytes.length; i += 4) {
bytes[i] = clampPixel((bytes[i] * red).round());
bytes[i + 1] = clampPixel((bytes[i + 1] * green).round());
bytes[i + 2] = clampPixel((bytes[i + 2] * blue).round());
}
}
Any pointers appreciated.
I want the gauge chart inside a 'rectangular' div, with height=300px and width =400px
If I setup the chart height=300, width=400,the resulting chart is not taking all the available height&width (see image), in fact it looks as if it is taking the necessary space for a circle instead of a semi-circle.
I set up height=300, width=400 for all internal pies, as well as these parameters in 'chart', with no improvements
spacingTop: 0,
spacingBottom: 0,
spacingLeft: 0,
spacingRight: 0,
plotBorderWidth: null,
margin: [0, 0, 0, 0],
spacing: [0, 0, 0, 0]
jsfiddle available here https://jsfiddle.net/perikut/0woz42vt/248/
thanks in advance
You are right, the space is adapted for a circle - please check this example: https://jsfiddle.net/BlackLabel/2jrch4xn/
You need to position the chart as you want by center property:
pane: {
...,
center: ['50%', '100%']
},
plotOptions: {
series: {
...,
center: ['50%', '115%']
},
...
}
Live demo: https://jsfiddle.net/BlackLabel/4m2t6p35/1/
How can I create a columnrange highchart with a point object with one x and two y values? I need to have a point object as the points should be clickable and styleable.
Is there something like
data: [
{x:1, y1:-5.2, y2:10.4}
]
or
data: [
{x:2, y: [-13.5, 9.8]}
]
I already tried these and some other things but they didn't work.
Is there any way to create something like that?
Thanks!
Instead of y1/y2 you should use low/high
{
x:Date.UTC(2012,12,2),
low:-9.7,
high:9.4
},
data: [
[Date.UTC(2010, 0, 1),-9.7, 9.4],
[Date.UTC(2010, 0, 2),-8.7, 6.5],
[Date.UTC(2010, 0, 3),-3.5, 9.4],
[Date.UTC(2010, 0, 6),-1.4, 19.9],
[Date.UTC(2010, 0, 7),0.0, 22.6],
[Date.UTC(2010, 0, 8),2.9, 29.5],
]
DEMO
I have been trying to align an entire label along with text to the left of an GtkEventBox where I placed it. However, I cannot do so. I tried to align the text on the label, because I do not know of any functions that would align the label itself to the left of my event box. The event box is placed in the table in this code:
label1 = gtk_label_new(res);
gtk_label_set_justify(GTK_LABEL(label1), GTK_JUSTIFY_LEFT);
gtk_label_set_line_wrap (GTK_LABEL (label1), TRUE);
gtk_label_set_single_line_mode(GTK_LABEL(label1),TRUE);
//align = gtk_alignment_new(0.0, 0.5, 0.0, 0.0);
//gtk_container_add(GTK_CONTAINER(align), label1);
//gtk_table_attach(GTK_TABLE(table), align, 0, 10, 2, 3, GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 20, 10);
embedLabel= gtk_event_box_new();
gtk_container_add( GTK_CONTAINER(embedLabel), label1 );
gtk_container_set_resize_mode(GTK_CONTAINER(embedLabel), FALSE);
gtk_table_attach(GTK_TABLE(table), embedLabel, 0, 10, 2, 3, GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 20, 20);
Maybe try to set the alignment within the available space?
gtk_misc_set_alignment(GTK_MISC(label1), 0, .5);
I don't know what i'm doing wrong, this is perl but it's language agnostic(methinks):
This example draws a lot of snowmans from an example i've found in the web:
(I ported it to perl)
The problems is that there's no sign of the text being rendered.
sub renderScene{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gluLookAt( $x, 1.0, $z,
$lx,1.0,$lz,
0.0,1.0,0.0);
glColor3f(0.5, 0.2, 0.4);
glMatrixMode(GL_MODELVIEW);
#Draw ground
glBegin(GL_QUADS);
glVertex3f(-100.0, 0.0, -100.0);
glVertex3f(-100.0, 0.0, 100.0);
glVertex3f( 100.0, 0.0, 100.0);
glVertex3f( 100.0, 0.0, -100.0);
glEnd();
for ($i=-3; $i<3; $i++)
{
for ($j=-3 ; $j<3; $j++)
{
glPushMatrix();
glTranslatef($i*10.0,0,$j*10.0);
drawSnowMan();
glPopMatrix();
}
}
glColor3f(0.5, 0.5, 0.0);
glRasterPos2f(0.5, 0.5);
my $strin = "Viva peron carajo!";
my #string = split('',$strin);
for my $char(#string){
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, $char);
}
glutSwapBuffers();
}
Your code is incomplete. $x, $z, $lx and $lz are undefined and there are no calls to set up the projection matrix. As such, I can only give suggestions:
glRasterPos coordinates are world/model coordinates. Did you really mean to put the text close to the origin, possibly inside the center snowman?
If you want to work in screen coordinates, you should set up an appropriate orthogonal "2D" projection matrix. Remember that you can push/pop/play around with the projection matrix in between drawing commands.
Also, start by rendering a triangle/quad in the text position.