rotate Qpixmap then crop it - image

I am newer in QT, I make a program that rotates images in QLabel and select area to crop, my code of crop based on this code here and my code of rotate is
current_angle = current_angle + value;
current_angle = current_angle % 360;
QPixmap pixmap(original_pixmap_angle);
QTransform rotate_disc;
rotate_disc.rotate(current_angle);
pixmap = pixmap.transformed(rotate_disc);
ui->label->setPixmap(pixmap);
cropping worked well if I don't make the rotation, but if I make rotate then crop it failed
any help please

Related

Playing video with TextureView, how to use Matrix to crop a video that specifies RectF?

Using TextureView to play video, users can choose RectF for cropping and preview playback. I am using Matrix postScale for scaling, but there are some issues.
I have seen some examples, but they are based on fixed point scaling and then fill the entire View, but did not display the video in RectF mode.
mEditAction.setCropWidth(actualCropRect.width());
mEditAction.setCropHeight(actualCropRect.height());
float scaleX = mVideoWidth / viewWidth;
float scaleY = mVideoHeight / viewHeight;
mEditAction.setCropX(actualCropRect.left);
mEditAction.setCropY(actualCropRect.top);
mEditAction.setCropScaleX(scaleX);
mEditAction.setCropScaleY(scaleY);
Matrix matrix = new Matrix();
matrix.setScale(scaleX, scaleY, actualCropRect.left, actualCropRect.top);
videoTextureView.setTransform(matrix);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams((int) (actualCropRect.width()), (int) (actualCropRect.height()));
layoutParams.gravity = Gravity.CENTER;
videoTextureView.setLayoutParams(layoutParams);
I use the above code, but sometimes the clipping matrix is wrong

Unity3d UI issue with Xiaomi

In Xiaomi devices, there are drawn an image outside of camera's letterbox
In other devices everything is correct
I attached both sumsung and xiaomi images, the screenshot that looks ugly is xiaomi, and good look in samsung
float targetaspect = 750f / 1334f;
// determine the game window's current aspect ratio
float windowaspect = (float)Screen.width / (float)Screen.height;
// current viewport height should be scaled by this amount
float scaleheight = windowaspect / targetaspect;
// obtain camera component so we can modify its viewport
Camera camera = GetComponent<Camera>();
// if scaled height is less than current height, add letterbox
if (scaleheight < 1.0f)
{
Rect rect = camera.rect;
rect.width = 1.0f;
rect.height = scaleheight;
rect.x = 0;
rect.y = (1.0f - scaleheight) / 2.0f;
camera.rect = rect;
}
try setting the image to clamp instead of repeat.
this will give the result of black borders but you won't have that weird texture
I don't know what caused that problem, however i solved it in a tricky way. I just added second camera to display black background. Only My main camera's viewport is letterboxed, but not second camera. So it made display to look good

Draw mask on image with transparency

In Matlab/Octave (Image package) is it possible to draw a slightly transparent coloured rectangle over an image region?
For example; I want to draw a red rectangle (alpha/opacity of 0.5) over the top left corner of an image.
pkg load image;
pkg load signal;
i = imread('foo.jpg');
% Somehow draw a transparent rectangle over the top left of the image
imshow(i);
You can use hold on and the property 'AlphaData' to draw a transparent overlay as follows:
image = rand(100); % a random image
imshow(image); % show the image
% create the red overlay
red = zeros(100, 100, 3);
red(:, :, 1) = 1;
% create the alpha channel with the right transparency
alpha = zeros(100); % everywhere completely transparent
alpha(1:50, 1:50) = 0.5; % except for the top left corner
hold on
h = imshow(red); % show the overlay
set(h, 'AlphaData', alpha); % apply the transparency

Flickering seams when scaling tiled images in Safari on the Mac

I'm trying to scale a bunch of tiled images in Safari. Safari on iOS displays this correctly. However, on the Mac, there is some weird flickering visible between the images while they are scaling. Once the animation stops, transparent lines are also visible between the tiles.
I've made a Pen showing the behaviour: http://cdpn.io/gdcxD
I've read a bunch of stuff suggesting that I use -webkit-backface-visibility: hidden or some other esoteric webkit directive. I've tried a couple of those, but they do not make any difference.
Ultimately, this will be used in a iBooks Author widget, so it needs to work both on iOS and on the Mac.
I do not really care how this gets solved except for one thing: I need to keep the -webkit-transform: translateZ(0) on the images so they display correctly on iOS.
Any ideas ?
Edit: The iBooks Author Widget I'm making will allow the user to zoom in on the tiled image. The images I'm using are large (1500 x 1200 px), but I'm scaling them down on the page to show the whole tiled image. I need to preserve their quality so the user can zoom in on them.
This is likely due to the browser using native system graphic processing such as anti-aliasing when scaling images. On the Mac it seems as images are not anti-aliased correctly at the edges which will at some sizes leave transparent (anti-aliased) pixels at the edges.
One way to solve this is to use a canvas element instead which you draw all your tiles to, then transform the canvas element instead.
var canvas = document.createElement('canvas'),
ctx = canvas.getContext('2d'),
tileW = 100,
tileH = 100,
cols = 10,
rows = 10,
x, y;
canvas.width = tileW * cols;
canvas.height = tileH * rows;
for(y = 0; y < rows; y++) {
for(x = 0; x < cols; y++) {
/// use spritesheet of image array here... just for example
ctx.drawImage(spriteSheet, srcX, srcY, tileW, tileH, // use position for x/y in spritesheet here instead (or 0,0 if image array)
x * tileW, y * tileH, tileW, tileH);
}
}
parentElement.appendChild(canavas);
Now apply the CSS to the canvas element.
Hope this helps.
Try using position:relative; on the img element.

Cropped Image is not aligned in center

I am developing a Photo App in Windows phone 7.
When I crop the image by a Rectangle area, the Cropped image aligned to the top-left corner of the image control. I want to align the image in center and zoom/stretch it to the full image control.
See the figures.
1st Image shows Before Crop and 2nd Image shows after crop, the image aligned top-left corner. the cropped image should be aligned in center. And plz also see the cropped image is not fully come in figure-2, I mean the Portion of Boot of Player is also cropped, but not showing in the cropped image, why this?
Code is:
void ClipImage()
{
RectangleGeometry geo = new RectangleGeometry();
r = (Rectangle)(from c in ImageLayout.Children where c.Opacity == .5 select
c).First();
GeneralTransform gt = r.TransformToVisual(ImageLayout);
Point p = gt.Transform(new Point(0, 0));
geo.Rect = new Rect(p.X, p.Y, r.Width, r.Height);
ImageMain.Clip = geo;
r.Visibility = System.Windows.Visibility.Collapsed;
TranslateTransform t = new TranslateTransform();
t.X = -p.X;
t.Y = -p.Y;
ImageMain.RenderTransform = t;
}
Here in code, I think some values should be changed, to align the image in center. This is just a cropped image code, many other functions also used inside, but is not concerned I think.
If you want to center some XAML element, use HorizontaAlignment.Center and VerticalAlignment.Center.

Resources