why does ImageResizer is rotating automaticlly image photographed vertical and show it horizontal - imageresizer

Hello i Have uploaded image using ImageResizer
using this code
var instructions = new ImageResizer.Instructions
{
Width = Convert.ToInt32(Newwidth),
Height = Convert.ToInt32(Newheiht),
Format = "jpg",
Mode = ImageResizer.FitMode.Crop,
Scale = ImageResizer.ScaleMode.Both,
};
File.InputStream.Seek(0, SeekOrigin.Begin);
ImageResizer.ImageJob i = new ImageResizer.ImageJob(File, Filepath, instructions);
i.CreateParentDirectory = false;
i.Build();
i have tried using
AutoRotate = true
i still got the image rotated to horizontall
i also tried Rotate=90
the pic was rotated and lost the proportion here is how it looks like after rotate
the resized roteted picture changed it to width=296 height=437 instead of height=296 width=437
the image was taken vertically using samsung galaxy 3 buy when resized it and upload it it show horizonally
here is the original photo taken:
here is how it shown after uploaded:

You haven't posted the diagnostics page, which lists which plugins are installed.
The most likely cause is that you didn't <add name="AutoRotate" /> or new AutoRotate().Install(Config.Current) to install the AutoRotate plugin, and therefore &autorotate=true had no effect.
It's also possible that there's a new form of image metadata that we can't detect yet, but that seems less likely.

Try Autorotate property "True"; It worked for me.
&autorotate=true

Related

PDFsharp Not Reading in Correct Page Size

I'm trying to develop an application to watermark PDF's. I'm having an issue with saving the PDF document in the correct format.
I've noticed that some documents when pulled in will read the page size as one thing but when I go to save the document part of it will be cut off. For example I have a document saved in landscape at 792x612 pts which correlates to a letter size. However when saved in letter it cuts part of the page off. I noticed that if I save the document in A1 that the entire document will then be present. Here is my code:
Dim gfx As XGraphics = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append)
gfx.RotateTransform(-90)
Dim font As XFont = New XFont("Times New Romans", 6, XFontStyle.Bold)
Dim tf As XTextFormatter = New XTextFormatter(gfx)
Dim rect As XRect = New XRect(-550, 500, 250, 150)
gfx.DrawRectangle(XBrushes.Transparent, rect)
tf.DrawString(Text, font, XBrushes.Red, rect)
page.Size = PdfSharp.PageSize.A1
page.Orientation = PdfSharp.PageOrientation.Landscape
Doc.save(strFileSaveLocation)
Is there any reason why this could be happening? I am reading the page.height and page.width and confirming these to be correct before continuing.
There is a known bug in PDFsharp when it comes to handling pages in landscape format. This bug is present up to PDFsharp 1.50 beta 3b, but should be fixed with the next release.
See discussion in the PDFsharp forum:
http://forum.pdfsharp.net/viewtopic.php?p=9591#p9591
Suggested fix in PdfPage.cs:
internal PdfPage(PdfDictionary dict)
: base(dict)
{
// Set Orientation depending on /Rotate.
//int rotate = Elements.GetInteger(InheritablePageKeys.Rotate);
//if (Math.Abs((rotate / 90)) % 2 == 1)
// _orientation = PageOrientation.Landscape;
}
If you do not want to modify PDFsharp, maybe try the workaround from the first post:
http://forum.pdfsharp.net/viewtopic.php?p=9587#p9587
For others running into the same issue as me, the answer is to simply set the orientation to portrait. This for some reason will trigger the document to save correctly. The answer by PDFsharp Novice will allow you to fix your code to some extent, but if you're like me and need to know the orientation in order to process the page the solution is setting the orientation back to portrait. You may need to reset page width and height also.
Code:
page.Orientation = PdfSharp.PageOrientation.Portrait
page.Width = dblPageWidth
page.Height = dblPageHeight

Image Resize - Fixed width and height with padding even image is smaller

When i upload 100x100 image, i cant make it 120x120 with whitespace filled for those extra 20px.
If i upload 200x150, then 120x120 image is ok, filled whitespace.
This is my code.
var setting = new ResizeSettings
{
Width = 120,
Height = 120,
Format = "jpg"
};
ImageBuilder.Current.Build(image, "desctination", setting, false, false);
Don`t know why, but i think i used this method successfully in past.
Any suggestion?
This is explained in paragraph 2 of the ImageResizer API Introduction page; use &scale=canvas or Scale = ScaleMode.UpscaleCanvas.

Soundcloud custom widget : change container background color w/o waveform.js?

Is there any way to change the sc-waveform container background from #efefef without having to load the waveform.js library? I have enough libraries loading already and the conainer bg conflicts with our site background color
I am experiencing the same issue and have had this problem before ( Overlay visible areas of transparent black silhouette PNG with pattern using CSS3 or JS ).
Here is an example with your waveform: http://jsfiddle.net/eLmmA/3/
$(function() {
var canvas = document.createElement('canvas');
canvas.width = 1800; // must match
canvas.height = 280; // must match
var canvas_context = canvas.getContext("2d");
var img = new Image();
img.onload = function(){
var msk = new Image();
msk.onload = function(){
canvas_context.drawImage(img, 0, 0);
canvas_context.globalCompositeOperation = "destination-in";
canvas_context.drawImage(msk, 0, 0);
canvas_context.globalCompositeOperation = "source-over";
};
msk.src = 'WAVEFORM_IMAGE.EXT';
}
img.src = 'OVERLAY_IMAGE.EXT';
document.body.appendChild(canvas);
});
I think I understand what you mean. You want to change the color of the waveform background, the gray stuff around the waveform:
The problem here is that waveforms you get from SoundCloud API are represented as partly transparent PNG images, where waveform itself is transparent and the chrome around it is gray (#efefef) color.
So, unless the library you want to use for waveform customisation is using HTML5 canvas, you won't be able to use change the color of that chrome (so no, not possible with either HTML5 Widget API or Custom Player API). And you have to use waveform.js or the likes (or modify the waveform image on canvas yourself).
You could try to experiment with newest CSS filters (webkit only for now) and SVG filters, and possibly some MS IE filters for older IE versions, but I am not sure you'd manage to just change the color.

How to set Background of a Button without flicker?

I am trying to change the Background of a button to an image source. I want to load that image in memory when we navigate to the page so that it doesn't flicker the first time it shows.
On Windows Phone, I was able to create the image source as such:
StreamResourceInfo resourceInfo = Application.GetResourceStream(uri);
BitmapImage bitmapSource = new BitmapImage();
// Avoid flicker by not delay-loading.
bitmapSource.CreateOptions = BitmapCreateOptions.None;
bitmapSource.SetSource(resourceInfo.Stream);
imageSource = bitmapSource;
I tried something similar in my Windows 8 Store app:
BitmapImage bitmapSource = new BitmapImage();
bitmapSource.CreateOptions = BitmapCreateOptions.None;
bitmapSource.UriSource = uri;
imageSource = bitmapSource;
but the same problem occurs. The button already has a different image as the Background, and on a certain event I would like it to change to the new background. But when I change the source, a noticeable flicker is observed. I'm assuming this is because the image is not yet in memory, as the issue goes away the second time the image source is modified.
Anyone know a solution? I need to somehow force the loading of this image.
Thanks!
If you use the SetSourceAsync method on the BitmapImage and await it before you attach it to the image source you should not see the flicker:-
// Ensure the stream is disposed once the image is loaded
using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
// Set the image source to the selected bitmap
BitmapImage bitmapImage = new BitmapImage();
await bitmapImage.SetSourceAsync(fileStream);
imageSource = bitmapImage;
}
The MSDN docs have some more info on this
Thanks Ross, but what I ended up doing instead is I preloaded the half dozen or so bitmaps I needed by using similar code to what you had above, except from resource of course. I did this asynchronously when the page loaded, and then when I set the ImageSource on the button background, I used the already preloaded bitmaps. That way I know I'm not allocated a new chunk of memory for every instance of the bitmap.

How is iBooks rendering the index view so quickly when viewing a PDF? Or: how do draw UIImages on UIScrollView directly without UIImageView?

I have a 140 pages test PDF (the full Adobe PDF specification, http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/adobe_supplement_iso32000.pdf) and open it in iBooks. Then switch to index (thumbnail) view. If I scroll to the end fast enough I can see that I can scroll faster than iBooks renders the pages but it catches up pretty quickly on iPad 2.
I learn two things from this:
First iBooks is showing 140 empty squares in the right size and then populates the preview.
iBooks really renders all of the previews and keeps them in memory (if I scroll around I cannot spot any re-rendering)
I also tested with another Adobe Spec that has 700+ pages: exactly same behavior! Fascinating!
The question is how are they doing it? I wrote some code that gets each page of the PDF as an image, adds it to a UIImageView and adds that to the scrollview.
I use the same technique and layout as iBooks does. It renders just as quick as iBooks but memory consumption is insane and especially when scrolling the app gets totally stuck after a while. Can anybody point me in the right direction? I already removed the PDF rendering for testing and it is really fast, so I can pin it down to the thumbnail generation.
EDIT:
If from the code below the PDF generation is removed and an empty UIImageView is returned instead, the performance is still extremely weak. So my assumption is that the UIImageView is causing the problem. How can I draw the PDF thumbs onto my UIScrollView without the requirement of 140 UIImageViews?
For those firm in Monotouch, here's the code I'm using to render the thumbs, maybe it shows an obvious weakness:
/// <summary>
/// Gets the low res page preview of a PDF page. Does a quick image render of the page.
/// </summary>
/// <param name="iPage">the number of the page to render</param>
/// <param name="oTergetRect">the target rect to fit the PDF page into</param>
/// <returns>
/// The low res page image view.
/// </returns>
public static UIImageView GetLowResPagePreview (CGPDFPage oPdfPage, RectangleF oTargetRect)
{
RectangleF oOriginalPdfPageRect = oPdfPage.GetBoxRect (CGPDFBox.Media);
RectangleF oPdfPageRect = PdfViewerHelpers.RotateRectangle( oPdfPage.GetBoxRect (CGPDFBox.Media), oPdfPage.RotationAngle);
// If preview is requested for the PDF index view, render a smaller version.
if (!oTargetRect.IsEmpty)
{
// Resize the PDF page so that it fits the target rectangle.
oPdfPageRect = new RectangleF (new PointF (0, 0), GetFittingBox (oTargetRect.Size, oPdfPageRect.Size));
}
// Create a low res image representation of the PDF page to display before the TiledPDFView
// renders its content.
int iWidth = Convert.ToInt32 ( oPdfPageRect.Size.Width );
int iHeight = Convert.ToInt32 ( oPdfPageRect.Size.Height );
CGColorSpace oColorSpace = CGColorSpace.CreateDeviceRGB();
CGBitmapContext oContext = new CGBitmapContext(null, iWidth, iHeight, 8, iWidth * 4, oColorSpace, CGImageAlphaInfo.PremultipliedLast);
// First fill the background with white.
oContext.SetFillColor (1.0f, 1.0f, 1.0f, 1.0f);
oContext.FillRect (oOriginalPdfPageRect);
// Scale the context so that the PDF page is rendered
// at the correct size for the zoom level.
oContext.ConcatCTM ( oPdfPage.GetDrawingTransform ( CGPDFBox.Media, oPdfPageRect, 0, true ) );
oContext.DrawPDFPage (oPdfPage);
CGImage oImage = oContext.ToImage();
UIImage oBackgroundImage = UIImage.FromImage( oImage );
oContext.Dispose();
oImage.Dispose ();
oColorSpace.Dispose ();
UIImageView oBackgroundImageView = new UIImageView (oBackgroundImage);
oBackgroundImageView.Frame = new RectangleF (new PointF (0, 0), oPdfPageRect.Size);
oBackgroundImageView.ContentMode = UIViewContentMode.ScaleToFill;
oBackgroundImageView.UserInteractionEnabled = false;
oBackgroundImageView.AutoresizingMask = UIViewAutoresizing.None;
return oBackgroundImageView;
}
internal static RectangleF RotateRectangle ( RectangleF oRect, int iRotationAngle )
{
if ( iRotationAngle == 90 || iRotationAngle == 270 )
{
return new RectangleF (oRect.X, oRect.Y, oRect.Height, oRect.Width);
}
return oRect;
}
You shouldn't be using 140 UIImageViews !!! use only just enough to fill the area and then recycle the ones that are no longer displayed.
How did Apple implement UITableView ?? Do you think they keep all tableview cells in memory??
Look at the PhotoScroller sample code and the corresponding WWDC 2010 video. I think it is named "Desigining apps with scrollViews"
WWDC 2011 video of similar name is continuation of the same trick of view reuse.
Hope this helps.
Have you checked the size of each UIImageView? Perhaps each of your thumbnails is actually the size of a full page.
Perhaps iBooks doesn't put each thumbnail in a UIImageView? Maybe the app is using something from CoreAnimation or even OpenGL ES?