Cropped Image is not aligned in center - windows-phone-7

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.

Related

PdfSharp and iText7

I am replacing PdfSharp with iText7 and I am not sure why when I use the same x and y coordinates I am getting different results. I am using 735 and 520 on both but they are printing on different location on the pdf file. Any help with this would be great. PdfSharp is using a double and iText7 is using float but they are exactly the same, under the hood.
the origin (0, 0) is top left and coordinates grow right and down. The unit of measure is always point (1/72 inch).
http://www.pdfsharp.net/wiki/Graphics.ashx
PdfSharp
PdfSharp.Drawing.XGraphics gfx = PdfSharp.Drawing.XGraphics.FromPdfPage(page);
dfSharp.Drawing.Layout.XTextFormatter tf = new XTextFormatter(gfx);
pnt = new XPoint(735, 520);
gfx.DrawString("Text Enter", font, XBrushes.White, pnt);
iText7
iText.Kernel.Geom.Rectangle rectangle = new iText.Kernel.Geom.Rectangle(735, 520, 100, 100);
Canvas canvas = new Canvas(pdfCanvas, rectangle);
Style normal = new Style();
PdfFont font = PdfFontFactory.CreateFont(StandardFonts.HELVETICA_BOLD);
normal.SetFont(font).SetFontSize(34).SetFontColor(ColorConstants.WHITE);
Paragraph p = new Paragraph()
.Add(_versionNumber)
.SetFontSize(34)
.SetFontColor(ColorConstants.WHITE)
.SetFont(font);
paragraph.SetFixedPosition(0, 800, 200) will put you at the Top left edge of the page, 200 is the width. Itext7 PDF coordinates start at the bottom left. (0,0) is the bottom left corner of the document normally.

Add overlay image on top of other image

Suppose that I have an RGB image RGB and a binary image binary that contains the result of segmentation of image RGB. How to draw the image binary on top of image 'RGB` and show the segmentation as a red transparent area? I tried the following but I got an error. Please help me to figure out the best way in MATLAB
I=imread('RGB.png');
[M,N,C] = size(I);
h=imshow(I);
alpha= imread('binary.png');
alpha = cat(3,alpha,zeros(M,N), zeros(M,N));
set(h, 'AlphaData', alpha);
Here are the input images:
Here is a method to add red overlays in select regions of the mask. Modifications to these scripts can be made to fill in the remaining regions with the colours white or black. The regions of interest on the mask are selected using a logical array.
Overlay Red Over White Region of Mask
Overlay_Opacity = 0.5;
Image =imread('RGB.png');
imshow(Image);
Red_Channel = imread('binary.png');
White_Mask_Region = Overlay_Opacity*(Red_Channel ~= 0);
Overlay_Image(:,:,1) = White_Mask_Region;
Overlay_Image(:,:,2) = 0;
Overlay_Image(:,:,3) = 0;
hold on
Overlay = image(Overlay_Image);
Overlay.AlphaData = White_Mask_Region;
saveas(gcf,'Overlay_1.png');
Overlay Red Over Black Region of Mask
Overlay_Opacity = 0.5;
Image =imread('RGB.png');
imshow(Image);
Red_Channel = imread('binary.png');
Black_Mask_Region = Overlay_Opacity*(Red_Channel == 0);
Overlay_Image(:,:,1) = Black_Mask_Region;
Overlay_Image(:,:,2) = 0;
Overlay_Image(:,:,3) = 0;
hold on
Overlay = image(Overlay_Image);
Overlay.AlphaData = Black_Mask_Region;
saveas(gcf,'Overlay_2.png');
You simply use your binary alpha (one layer only) as AlphaData.
If you have the Image Processing Toolbox, this function will do what you want:
https://www.mathworks.com/help/images/ref/labeloverlay.html

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

rotate Qpixmap then crop it

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

Resources