How to avoid Alias when rotate the image in gdi+? - gdi+

I have a problem on roating an Image on a canvas in gdi+, I am using the following code, however I find there are alias on the edge.
myPathMatrix.Rotate(GetDCAngle(), MatrixOrderAppend);
myPathMatrix.Translate(
GetDCX(),
GetDCY(),
MatrixOrderAppend);
canvas->SetTransform(&myPathMatrix);
canvas->Draw(XXX);
I used the following code to remove the alias, but failed.
canvas->SetInterpolationMode(InterpolationMode::InterpolationModeHighQualityBicubic);
canvas->SetSmoothingMode(SmoothingModeAntiAlias);
How can I remove the alias at rotated image's edges.
Many thanks!

It's been a while since I worked with GDI+, but I'd assume there's no effective option to remove antialiasing around the edges when rotating. The reason is basically that pixels are square. To rotate an image an amount other than a multiple of 90 degrees, you need to use some kind of interpolation to estimate pixel colours where there weren't really pixels before.
So if there's nothing in the library to specifically take away antialiasing around the edges, have you thought about drawing hard lines in the background colour along the borders? It should be easier to draw those lines without any antialiasing.

Related

Creating alert icon with shadow in CSS

i am trying to create the following image using css.... so far i've got this after googling a bit http://jsfiddle.net/w9Zgc/ and i want to make the following shape..
is there any way this can be done... any help would be appreciated.. oh and i would like the shadow to be like the one here... http://jsfiddle.net/w9Zgc/
So I managed to create an icon that renders more or less the same in all current browsers. I had to use an extra useless span, unfortunately.
http://codepen.io/myajouri/full/nJDzl
The triangle is made of two parts:
the upper (triangular) part is a transformed (skewed and rotated) square with rounded corners.
the bottom of the triangle is the bottom part of a rectangle with rounded corners.
Both parts are cut and joint at certain places to form the triangular shape with rounded corners and shadows.

css 3D transform cube perspective

I'm trying to create a grid of cubes that have a perspective that looks like you're looking at them from the top. Here is an example
http://imgur.com/elyJ5tu
This one is made by calculating how far the cube is from the middle and changing the border size. I want to make my own texture on the sides of the cube so I used CSS3 rotation to create the six sides of the cube and position them correctly to form a cube. Now I tried to recreate the effect by having the cubes tilt over the x and y axis depending on how far they are from the center and i got this:
http://codepen.io/anon/pen/yKmwg
As you can see it looks like they're on some kind of spherical surface. This is because the front and back side of the cube should not be rotating. Does anyone know of the proper way to do this. Thanks
Thank you #jozzas perspective origin was what i was looking for:
http://codepen.io/avovk/pen/yICrt

How does Qt draw a border around a rectangle?

I want to know how Qt does a border when using QPainter's drawRect. The reason for this is I am trying to draw three rectangles next to each other, but I'm having trouble getting them to touch perfectly at all pen sizes.
QPainter's documentation for drawRect says:
A stroked rectangle has a size of [the input rectangle] plus the pen width.
So it goes like this:
I just wanted to add to the answer and address the question about truncation.
Truncation might be happening because you are using the QRect and not QRectF. QRectF gives you floating point precision. Similarly, you can use QPen::setWidthF(qreal width) to ensure your border is not getting truncated either.

FileModeWinding and DrawPath cause odd spikes to appear

I'm using gdiplus to "stroke" a textout. In certain circumstances, we see a "spike" appearing on the top or bottom of the graphic, and I'm not really sure why. We can minimize this by adjusting stroke width and font size, but thats not a good solution. I'm hoping someone can explain the problem to me.
And the code sample generating this 4, its outline, and the spike (unintentional)
GraphicsPath path(FillModeWinding);
path.AddString(text,wcslen(text),&fontFamily,StateInfo.TheFont.TheWeight,(REAL)minSize,PointF((REAL)ptStart.x, (REAL)ptStart.y),&sf);
// Draw the outline first
if (StateInfo.StrokeWidth > 0) {
Gdiplus::Color strokecolor(GetRValue(StateInfo.StrokeColor), GetGValue(StateInfo.StrokeColor), GetBValue(StateInfo.StrokeColor));
Pen pen(strokecolor,(REAL)StateInfo.StrokeWidth);
graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
graphics.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHighQuality);
graphics.DrawPath(&pen, &path);
}
// Draw the text by filling the path
graphics.FillPath(&solidBrush, &path);
Use Pen::SetLineJoin on the Pen you're using to draw the outline, and use something other than LineJoinMiter.
I agree that the fill mode isn't the issue, I think it is just the pen width used for drawing the outline. For characters that have enclosed spaces with pointy corners (like 4 and 'A'), as the pen width used for drawing the outline gets bigger, the size of the inner shape (the little triangle in the case of the four) gets bigger too.
Eventually the inner shape will get too big to be contained by the outer shape, and will start to poke through, resulting in the artifact you see.
Here is an illustration of a fixed font size (the Impact font again) as the outline width gets bigger. There is no fill here, just a call to graphics.DrawPath():
The fill operation doesn't care about the outline width, and uses the original shape of the letter.
This partially masks the problem by covering up some of the messy outline. Here is with the fill turned on:
Something similar will happen with the character 'A':
EDIT: calling SetLineJoin, as indicated in the other answer, is the way to stop this from happening.

How can I manipulate shapes in Adobe Flex?

I'm working on an application where I'm drawing some rectangles on the screen, and then will need to manipulate the shapes (change their size, location). I tried to do something with .drawRect and clearing the shape each time I was manipulating it, but the RAM usage was spiking and then falling (presumeably because i keep reinitializing a new component and then removing it, and garbage collection was cleaning it out). This seems like its probably not the most efficient way to do it.
Is there a way for me to just create a shape once, and then move it around on a canvas (and change its width and height without all this RAM usage?
If all you're doing is changing it's offsets, and adjusting it's width and height without needing to fundamentally change the structure of the shape (such as rounding the corners of a rectangle of some such) you should be able to just maintain a reference to the Shape and adjust it's x, y, scaleX, scaleY properties to effect the changes.
You can try Degrafa to draw the rectangle.
To move the rectangle:
Changing the x and y or height and width property of the shape
Using the Flex Move Effect

Resources