How can I resize an image using the Lumia Imaging SDK? The documentation seems to be very poor and I cannot find any examples/methods to resize (not crop) the image on Windows Phone 8.1.
Which methods can I use?
You should set the Size property on the renderer. That will resize the image to the size you want.
Looking at the JpegRenderer (https://msdn.microsoft.com/en-us/library/lumia.imaging.jpegrenderer_members.aspx) set the Size to what you want the size to be. In addition you can set the OutputOption property (https://msdn.microsoft.com/en-us/library/lumia.imaging.outputoption.aspx) if you want the contents to be Stretched or to preserve aspect ratio instead.
A quick example:
using (var source = ...)
using (var renderer = new JpegRenderer(source))
{
renderer.Size = new Size(800, 600);
renderer.OutputOption = OutputOption.Stretch;
var result = await renderer.RenderAsync();
}
If you are using a BitmapRenderer or a WriteableBitmapRenderer and pass in the (writeable)bitmap the renderer will automatically resize the contents to the size of that image.
Related
Long story short: I want to set Edit2D polyline tool's line width to 6" based on calibration sizing and have it stay that size in the viewer no matter the camera zoom.
I'm using the edit2d library to allow drawing. I need to be able to set the line width for the polyline tool and have it stay at that width similar to how markups stay a set size when drawn. The default functionality of the edit2d polyline tool is for the line to be resized on camera changes and so it grows and shrinks depending on zoom.
I tried setting edit2DTools.polylineTool.style.isScreenSpace = false; which works, however, trying to set the specific size is difficult as it ends up being a decimal less then 1 and I can't find a correlation from the calibration, page size, etc. to allow me to dynamically set the size the same on different models.
I also found this in the Edit2D Snapper's code, but I can't figure out what's happening here to replicate it on the polyline tool. It seems to be doing what I want to do.
Any help or ideas at all would be greatly appreciated!
This code seems to be working for me:
async function setLineWidth(viewer) {
let mt = await viewer.loadExtension("Autodesk.Measure");
if (!mt.sharedMeasureConfig.calibrationFactor) {
console.log("Has not been calibrated yet");
return;
}
let edit2d = viewer.getExtension('Autodesk.Edit2D');
let pt1 = {x:0, y:0, z:0}, pt2 = {x:6, y:0, z:0};
viewer.model.pageToModel(pt1, pt2, 0 /*viewport id*/, true /*reverse*/);
let style = edit2d.defaultTools.polylineTool.style;
style.lineWidth = (pt2.x - pt1.x) / mt.calibration.scaleFactor;
}
Here is a video showing it in action: https://youtu.be/DIaKugvQdm4
As you can see first the lineWidth of the polylineTool is not what you want, but after setting what 6" should be in the drawing, I can set it to the same width and all is fine.
Here is a zip file with the html including the JavaScript code and the test PDFs I used: https://github.com/adamenagy/Container/blob/master/Edit2dTest.zip
I am using a font generated by Heiro tool.
game.scoreFont = new BitmapFont(Gdx.files.internal("fonts/score.fnt"), false);
I applied it for a label;
private void drawScore() {
Label.LabelStyle scoreStyle = new Label.LabelStyle();// style
scoreStyle.font = game.scoreFont;
scoreLabel2 = new Label(scoreController.getScoreString(), scoreStyle);// label
scoreLabel2.setPosition(scoreBox.getX()+scoreBox.getWidth()/2.7f,scoreBox.getY()+scoreBox.getHeight()/2);
scoreLabel2.setAlignment( Align.center);
}
While generating font,I gave a size of 32.
But same font I want to use for a label somewhere else in the game ,with a little bit bigger size.
Is it possible to increase the size then?or Should I generate a new font of required size with Heiro tool again?
You can scale your BitmapFont by
bitmapFont.getData().setScale(2);
and then use this font in LabelStyle, however you can also scale in this way
labelStyle.font.getData().setScale(2);
It works on reference of BitmapFontso it scaled everywhere, where you're using that BitmapFont in your game.
So you can create two object of BitmapFont with same file and scale one font and use where you want bigger font.
I'll recommend you to create two font with different size using your tools. Scaling is never a good solution.
I am trying to play sprite images on windows phone 8. But its not playing correctly, if the single sprite image is larger than screen dimensions. I try to reduce the image with aspect ratio by using rectangle and ImageBrush. Still I am facing the same problem. Please find the below scenario.
Scenario :
Sprite Width/Height : 22100 / 516
Single Sprite Width/Height : 850/516
Mobile Dimensions : 800/480
Could anyone can help me out.
So, if I understood your question, all you need to do is:
Create a BitMapImage, don't use ImageBrush or Rectangle..
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.UriSource = new Uri(imagePathOrUrl, UriKind.RelativeOrAbsolute);
I suggest you to add also this instruction to prevent memory issues:
bitmapImage.DecodePixelWidth = imageWidth;
Add the BitMapImage to an Image control and set the **Stretch** property for the aspect ratio:
Image img = new Image();
img.Source=bitmapImage;
img.Stretch = Stretch.Uniform;
Stretch property has also other values, so be sure to do some test with the other values to see what value adapts better to your needs.
Let me know if it works!
I am showing a Modal Dialog on the screen and I can set its size in units of pixels, however, people use different resolutions, so it might cut off on some computers. What I want to do is have the UI be full screen, in essence 100% x 100%. I am wondering if there is a way to do that.
function test() {
//I can set size in units of pixels here
var app = UiApp.createApplication().setHeight(700).setWidth(1500);
var label = app.createLabel("Hi").setId("label");
app.add(label);
SpreadsheetApp.getUi().showModalDialog(app, 'Test');
}
Thank you in advance
UiApp has no way to know the size of the browser view port, this can't be done.
I'm using a Flip Template for my tiles. On the MSDN page the text is seen to wrap, as well as be a smaller size.
This is not representative of behaviour I'm seeing in my live tiles. I can get a maximum of 3 lines, of large text, on the Wide live tile. The text does not wrap. This happens on all the different screen sizes of emulators. Frustratingly, I can get 4 lines of text on the Medium live tile, but the additional line of content is too long to fit there anyway so I don't include it.
I update my tiles periodically using a scheduled task:
Earthquake latest = quakes.First();
newTileData = new FlipTileData
{
Title = String.Format(AppResources.LiveTileTitleFormat, quakes.Count),
BackTitle = String.Format(AppResources.LiveTileTitleFormat, quakes.Count),
BackContent = String.Format(AppResources.LiveTileBackContentFormat, latest.FormattedMagnitude, latest.FormattedDepth),
WideBackContent = String.Format(AppResources.LiveTileWideBackContentFormat, latest.FormattedMagnitude, latest.FormattedDepth, latest.RelativeLocation)
};
ShellTile tileToFind = ShellTile.ActiveTiles.First();
if (tileToFind != null)
{
tileToFind.Update(newTileData);
}
The emulator on the left is attempting to show 4 lines.
The emulator on the right is showing the text not wrapping.
So, is there any way to force a fourth line, or specify a smaller font size, or both? I suspect there isn't, and the MSDN article is simply showing Windows 8 (not WP8) live tiles.
It's not possible to resize text on WP8 tiles. You can fake it by creating an image and placing that on the tile instead:
Create a user control that accommodate an image control and Text block
Assign you tile image to image control and the text with desire size to text block.
Then create a snapshot of the control through following code.
use this image for implementing tile generation.
private WriteableBitmap RenderControlAsImage(UserControl element)
{
element.UpdateLayout();
element.Measure(new Size(element.Width, element.Height));
element.Arrange(new Rect(0, 0, element.Width, element.Height));
return new WriteableBitmap(element, null);
}