Drawing an image with a color tint in MonoTouch - cocoa

What do I need to read up on to tint the image I draw with a predefined color. Alternatively just adjust the alpha value? I've played around with BlendMode but I basically don't know what I'm doing. :)
Simplyfied code below
_backgroundImage = UIImage.FromFile ("whiteblock.png");
var ctx = UIGraphics.GetCurrentContext ();
// What do I do here to tint or adjust alpha of the image
ctx.DrawImage (rect, _backgroundImage.CGImage);
Thanks
AnkMannen

I recommend starting with the Core Image Filter reference docs (see also CIFilter).
(Note that depending on the version of the OS, not all filters may be available.)
You probably want to focus on the filters in the CICategoryColorAdjustment category.
In particular, the CITemperatureAndTint filter can adjust the tint of the image, as you ask. But, it is not straightforward to use.* There are other questions on StackOverflow describing it, like this one: Input parameters of CITemperatureAndTint (CIFilter)
Finally check out the MonoTouch docs for a code example with CITemperatureAndTint. (I believe the image attached to the examples given there are wrong, as they show a scaled image, not a tinted image.)
*It takes two parameters, each a 2D CIVector. I believe the first component of the vector is temperature and should be in the ballpark of (1k ... 30k). I believe the second component is wavelength, so in the ballpark of (380 ... 700). If someone knows better, correct me.

Related

Stroke width, or line material in three-globe

Just trying to up the stroke width a little on the country polygons for three-globe.
There doesn't appear to be a helper function for this material or any settings beyond color.
I had the bright idea of looping through all the children of the globe object, very crude but:
for (let i in Globe.children[0].children[4].children){
const child = Globe.children[0].children[4].children[i];
child.children[1].material.linewidth = 3;
child.children[1].material.color = new THREE.Color('rgba(255,255,255,1)');
}
This appears to have no effect on the line width. It does, however, successfully change the color, so I think I'm close, though I really hope there's a better way than this.
I'm sorry to inform you that the .linewidth property is very poorly supported due to OpenGL limitations. You can see an explanation in the LineBasicMaterial.linewidth documentation
Due to limitations of the OpenGL Core Profile with the WebGL renderer on most platforms linewidth will always be 1 regardless of the set value.
You'll run into this issue if you're using THREE.Line or THREE.LineSegments. However, there is an alternative you could use with THREE.Line2, which circumvents the limitation by drawing lots of instanced gl.TRIANGLES instead of gl.LINE. You can see it in action in this example. In fact, there are 3 demos of fat lines, each one with a slightly different implementation. You would then have to substitute the outlines of the country with your own fat lines.

About the translucent effect of three.js

I have a need. I need to make a window. The glass on the window is transparent. I have found some examples:
https://threejs.org/examples/#webgl_materials_shaders_fresnel
https://threejs.org/examples/#webgl_materials_cubemap_refraction
The background of these examples is static pictures.
My background is dynamic. How can I do it?
Maybe you can use THREE.Refractor like shown in this example. It allows you to create a refractive see-through surface. You might have to adjust the respective shader program in order to achieve your intended visual result (the default shader of THREE.Refractor does not perform any distortions).

Windows button ignores alpha channel for fully transparent image

I have a radio button that should display an image (style BS_AUTORADIOBUTTON|BS_PUSHLIKE|BS_BITMAP).
I create a bitmap via CreateDIBSection (using a BITMAPINFO with BI_RGB) and obtain a pointer to the raw pixels via the ppvBits, so that I can manipulate them freely.
I use BM_SETIMAGE to set the button's image to the bitmap I created.
So far, I can set the RGB and alpha by manipulating the pixels by hand. I tested that even semi-transparent (non-premultiplied) alpha values look good.
As far as I can tell, everything works, except if all pixels in the image are transparent. In that case, the button apparently ignores the alpha value, simply displaying a rectangle with each pixel having the respective color with full opacity.
I found a hint that Windows - at least in some cases - actually seems to interpret images whose pixels' alpha values are all 0 as completely opaque images:
When the window manager sees a 32bpp bitmap, it looks at the alpha
channel. If it's all zeroes, then it assumes that the image is in 0RGB
format; otherwise it assumes it is in ARGB format
Is this behavior documented somewhere?
Is this behaviour documented somewhere?
Yes! In Raymond's post! :) That's often the way of it, no?
If you look at the foot of the page here you will find a comments box. If you raise your concerns there then MS will most likely fix their documentation. See here for an example of the process they usually follow if they consider the problem serious enough to fix.

QGraphicsView / QGraphicsScene image size

I want to display an image in a QGraphicsView with a QGraphicsScene. My code is very basic :
QGraphicsScene* scene = new QGraphicsScene(this);
scene->addPixmap(QPixmap(qApp->applicationDirPath() +"/france.gif"));
ui->myGraphicsView->setScene(scene);
ui->myGraphicsView->fitInView(scene->sceneRect());
My problem is that my picture has a wrong size. It is very small, with wrong proportions and on the center of my GraphicsView. With qDebug i kwow that my picture is load successfully and it has a size of about 100x800px. My graphicsView is smaller so i want to resize my picture to adjust it with my GraphicsView size.
The graphicsView is set in the mainwindow Form and the scene is declared in the header : "QGraphicsScene scene;"
I try everything is possible in the world (i think) but the graphicsView is alaways blank or contains the small version of the picture. When I copy/paste some codes of internet i always get this problem. I also try with this example : Qt GUI Development - Displaying a 2D grid using QGraphicsView , same problem...
Maybe i'm very very very tired but i really don't understand what is wrong. Help me please :)
sceneRect() may not be what you think it is unless you specifically set it. Also you are missing aspectRatioMode in fitInview call which can distort it image, sometimes resulting in "small" appearance.
QGraphicsScene* scene = new QGraphicsScene(this);
QGraphicsPixmapItem p = scene->addPixmap(QPixmap(qApp->applicationDirPath() +"/france.gif"));
ui->myGraphicsView->setScene(scene);
ui->myGraphicsView->fitInView(p, Qt::KeepAspectRatio);
From my experience, a shown image is very small if we try to fitInView before the scene window is displayed. Technically, the sceneRect size is not set in the way we want until it is actually shown. Therefore, we need to let the scene window shows up before we can properly use fitInView.
Well, I think the solution is available here
Qt5 C++ QGraphicsView: Images don't fit view frame

How to fix blurred Icon Decorator on DSL Tools?

I faced this problem and after an extensive research I found its root cause and a workaround that can be useful for other people.
The icon decorator becomes "blurred" because its positioning on the shape and the conversion from pixels to inches.
Usually the drawing surface of the Domain Specific Language has a resolution of 96dpi and the Icon Decorators are positioned using an offset of 0.06 inches. Translating it to pixels it becomes an offset of 5.76 pixels in the drawing surface. As it is not possible to draw a "half pixel" on the screen the GDI+ adjusts the image in an attempt to emulate the "haf pixel" positioning. That is the reason why the image becomes blurred.
My suggestion as workaround, is to use the Horizontal Offset and the Vertical Offset properties of the Icon decorator class for fixing the "half pixel" decorator position. If you use the "0.0025" inches as vertical and horizontal offsets, when the image positioning is translated from inches to pixels it becomes 6 pixels, instead of 5.76. It happens because the offset now is the default value 0.06 inches plus the offset you set 0.0025 = 0.0625.
I also found that using png images with transparency causes the image blurring, even using the offset workaround I suggested here. Converting the image to bitmap format fixes the problem.
If someone also has any suggestions for fixing the problem, please add your solution or workaround.
I fixed the blurred problem by creating a new Bitmap:
Under the overridden method
public override System.Drawing.Image GetDisplayImage(ShapeElement parentShape)
I call my custom method FixBitmap
Bitmap imageFixed = DynamicImageHelper.FixBitmap(image, out dynamicOffset);
This method receives the original image that DSL would show, but instead returns the exact same image but created as a new Bitmap
Bitmap fixedImage = new Bitmap(original, original.Width, original.Height);
return fixedImage;
If you check the new instance properties there are little differences (I don't quite remember which because i implemented this about 1 year ago).
Also, i mostly use .png files with transparency and they look exactly as they are.
Hope this helped.
If you need any further help, do not hesitate,
Regards,
Luís

Resources