Why BlackCity/Backload automatially rotate the uploaded image? - c#

I'm using backload ( https://github.com/blackcity/Backload ) for image upload. It works fine. Here are the 2 lines in the Wev.backload.config
<images width="3072" height="2304" dpi="96" canvasColor="#00ffffff" forceImageType="image/png" resizeMode="ratio" maxFileSize="4194304" />
<thumbnails path="_thumbs" width="192" height="144" dpi="96" canvasColor="#00ffffff" resizeMode="ratio" imageType="image/png" />
However, I found that if upload an image whose width is < its height, the uploaded image will be automatically rotated. For example, the original image is (3072,2304), width 3072, after uploaded, the size becomes (2304,3072). It is rotated automatically.
Is there a way to keep the width/heigh ratio and without rotating it?

it turns out this is a bug in backload. and it is fixed in new package. the detail is on github
https://github.com/blackcity/Backload/issues/107#issuecomment-251363262

Related

Image.GetThumbnailImage() after Image.RotateFlip() seems to ignore rotation

I am using Image.RotateFlip() to fix the orientation of some photos. I read the EXIF information of each photo and then I rotate/flip the image accordingly to make it straight up. My code is something like this:
//get info before processing.
var imgf = img.RawFormat;
//rotate and/or flip.
img.RotateFlip(rfty);
//reset orientation info.
img.RemovePropertyItem(km_iPropertyTagOrientation);
img.RemovePropertyItem(km_iPropertyTagThumnbailOrientation);
//save fixed image to a new file.
string strFilenameNew = Path.ChangeExtension(strFilename, "temp");
img.Save(strFilenameNew, imgf);
//replace original file.
File.Delete(strFilename);
File.Move(strFilenameNew, strFilename);
As you can see, I rotate/flip the image, remove the EXIF information that encoded the old orientation, and lastly I save it in the same format and replace the original file.
When I upload my photos on to http://metapicz.com, this is what I get:
Source photo (rotated 90 degrees, with orientation data): image looks rotated, landscape aspect ratio, orientation shows as Rotate 90 CW. This is what you would expect.
Fixed photo (processed by code above): image looks straight up, portrait aspect ratio, orientation data not reported. This is also what you would expect.
So far, so good. Now, I use Image.GetThumbnailImage() to obtain a thumbnail of the fixed photo, by scaling its size by 20%. The odd thing is, the resulting thumbnail is rotated again! When I upload it on to http://metapicz.com, this is what I get:
Thumbnail photo (obtained from fixed photo): image looks rotated, portrait aspect ratio, orientation data not reported. This is awkward, because the photo is now distorted, since the aspect ratio is preserved from the fixed photo (portrait), but the image in the photo looks rotated as in the source photo!
You can find this set of photos (source, fixed and thumbnail) here: https://verdewek-my.sharepoint.com/personal/cesargon_verdewek_com/_layouts/15/guestaccess.aspx?folderid=0d56479242b154fb7a31ae9a96f7be9cb&authkey=AbT_VQeoKU2EoVDuhvM2RgM
Any idea what I may be missing? Thank you.

WinRT: How do I ensure Images are drawn in a pixel-perfect way on a Canvas?

I am adding Image instances to a Canvas in Windows Runtime environment and my image keeps getting scaled up when in 140 and 180 scale resolution displays, it looks perfect in scale resolution 100. I tried creating 3 PNG images, one for each scale size: 100, 140, 180 but it still scales them up and they look blurry. I created a test image with 4 black pixels on a cyan background and I took a screenshot from the simulator, see how the image is blurry, my original image has just 4 perfect black pixels:
I tried changing the stretch mode of my Image objects, but it does nothing. I'm using this code to add the images at runtime:
var bitmapImage = new BitmapImage();
StorageFile bitmapFile = await StorageFile.GetFileFromApplicationUriAsync(imageUri);
await bitmapImage.SetSourceAsync(await bitmapFile.OpenReadAsync());
Image image = new Image{ Source = bitmapImage};
image.SetValue(Canvas.LeftProperty, x);
image.SetValue(Canvas.TopProperty, y);
canvas.Children.Add(image);
How do I get the images to draw pixel perfectly in the canvas without scaling and at the exact x/y coordinates I want?
I think I have a workaround, but it requires two steps:
First I have to load the image using a more a standard way that doesn't involve getting the file path like so.
var bitmapImage = new BitmapImage(imageUri);
Somehow this must retain more information internally that this image came from a file with the corresponding ResolutionScale for the current display. Thus when it is drawn by the canvas it is not scaled at all. However this only solves half the problem.
The next problem is that the x, y coordinates used to specify where the image is drawn are being scaled so the image is drawn in the wrong place, further than where I wanted. The only thing I can figure to do is unscale them first like so:
var resScale = DisplayInformation.GetForCurrentView().ResolutionScale;
Image image = new Image{ Source = bitmapImage};
image.SetValue(Canvas.LeftProperty, (x * 100.0) / (int)resScale);
image.SetValue(Canvas.TopProperty, (y * 100.0) / (int)resScale);
canvas.Children.Add(image);
The whole thing seems a bit crazy but it seems to work so far... Anyone have a better solution or an explanation why all this is necessary? Seems like the Canvas class needs an unscaled mode that doesn't mess with the images or coordinates across different resolution displays.
UPDATE: This doesn't work perfectly, using a double to store the value results in precision loss and sometimes there are anti-aliasing artifacts. This is not acceptable if you want pixel perfect graphics. I am still looking for a perfect solution.
There are a few more things that might help with your solution.
Use UseLayoutRounding="False" on your image.
Put your Canvas in a full-screen Viewbox, then set the Canvas Width and Height to the screen resolution. You'd use unscaled Canvas.Left/Top values in this case.
Use Direct2D/Direct3D for rendering.
Good luck.
You can change the Stretch property to "None", If you image is still meshed-up:
You should look at what DPI it is saved on. WPF tries to be DPI-independend, so it tries to draw an image of 5"x5" on every monitor the same size. Even when the resolution is higher, it still should be 5"x5" only a high resolution would render(rasterize) the image in higher quality.
Here's some info: http://www.wpflearningexperience.com/?p=41
How do I convert a WPF size to physical pixels?
Here's a piece of xaml code
you can always use scale transform from code behind to scale the images to appropriate amount be it less or more.
<Image Canvas.Left="150" Height="170" Width="170" Visibility="Visible" Stretch="None">
<Image.Source >
<BitmapImage UriSource="ms-appx:///Assets/rollingDieSprite.png"></BitmapImage>
</Image.Source>
<Image.RenderTransform>
<ScaleTransform ScaleX="4" ScaleY="4" x:Name="scaleTfDie"></ScaleTransform>
</Image.RenderTransform>
</Image>
in c# code behind you can go for the following
ScaleTransform sc = new ScaleTransform();
sc.ScaleX = 0.9;
sc.ScaleY = 0.9;
imgDieRolling.RenderTransform = sc;
this will control the scaling . try using fill=none . Let me know if it works.
I found this issue quite problematic as well. I'm creating custom bitmaps and drawing them at different positions on the canvas. I couldn't find a way in the XAML, but I found a way using Direct2D. When you set up your D2DContext, there's a function called SetUnitMode(). The default unit mode is "DIPS" which causes all drawing to be scaled. By switching to PIXELS mode, the system stops scaling the drawing and does everything 1:1.
m_d2dContext->SetUnitMode(D2D1_UNIT_MODE_PIXELS);

How to crop and resize an image for a LiveTile

I would like to be able to add an image to a live tile so that there is no stretching and the image looks normal. I am getting my images from the PhotoChooserTask, which contain images from the medialibrary. As of now I can successfully place an image on a live tile, but it is stretched and the aspect ratio is not correct. How would I be able to find the aspect ratio of the image and crop the image so that it ends up being a square with dimensions 173x173 with no streching? I have followed a couple tutorials found online but nothing seems to accomplish this the way I need it to.
I accomplished this by referencing Resize image for Live Tile - WriteableBitmapEx which proved to have the correct implementation.

Extract size of the image embedded in a PDF

I have an image embedded in a PDF file. I was able to extract the resolution of the image. However, if i crop the PDF using iTextsharp and a part of the image is cropped in the process. The new image continues to have the same resolution. By resolution I mean the dimension in the form of Width x Height. The cropped image is supposed to have a smaller size. How can I extract the size of the image in inches, if possible, so that I can differentiate the original image from the cropped pdf?
Embedded images in PDFs are never "cropped" in the sense that the "cropped-away" parts are gone forever. They are only cropped in the sense that these parts are hidden or masked.
If the image data inside the PDF say /Height 216 and /Width 288 then this is the size in Pixels (not inches or any other length unit). And "resolution" is then secondary:
if the PDF environment commands that this image should be rendered onto a square of 3x4 inches, its resolution in this moment is 72x72 dpi.
if the PDF environment commands that this image should be rendered onto a square of 1.5x2 inches, its resolution in this moment is 144x144 dpi.
However it can well be that the image is only partially visible ("cropped"), maybe because half of it is rendering beyond the page borders...

Kinect show Depth Image in Full Screen

Is there a way to show Kinect Depth Image into Full Screen mode? I'm using C# and WPF, the OpenNI C++ example able to show the dept image in full size with out any stretch occur, but when I use WPF, the image gets stretch out.
Currently I'm getting resolution of 640X480, but I want to display it into any screen size or maybe TV. My laptop is 1280X768 but when u make the image full size it get stretced.
Thanks in advance.
As far as I know the hardware resolution of the Kinect cameras is 640 x 480 so there is no way to increase that without stretching.
In WPF it is possible to scale the image in proportion so the dots of the image remain square.
<Image Source="..." Stretch="Uniform" />
or not scale at all:
<Image Source="..." Stretch="None" />
See Stretching Images under Displaying Images in WPF

Categories

Resources