Display Image from website in Windows Phone 8.1 - windows-phone-8

why that code work in WinRT but not in Windows Phone 8.1?
foreach (var img_url in imagesList)
{
image = new Image();
image.Source = new BitmapImage(new Uri(img_url, UriKind.Absolute));
image.Width = 300;
image.Height = 300;
pnlImages.Children.Add(image);
}

Try this one:
foreach (var img_url in imagesList)
{
image = new Image();
image.Source = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri(img_url));
image.Width = 300;
image.Height = 300;
pnlImages.Children.Add(image);
}
Hope it helps!

Related

Pics are sideways on iOS (using HTML Input)

I have this HTML code to allow a user to upload a picture on my hybrid iOS app:
<input type="file" accept="image/*">
When selected, the web view gives the user 2 options.
1. Take a new picture 2. Choose an existing picture.
When the users selects 'Choose an existing picture' everything works fine. But if the user selects 'Take a new picture', when it uploads to Firebase Storage, it somehow uploads sideways.
How can I fix this? This is not ideal, but is there a way to only allow an 'existing picture' option?
Here is my code that processes the image and shows it in a <img>.
function fileUploaded(files) {
var file = files[0];
var reader = new FileReader();
reader.onload = function (e) {
var img = document.createElement("img");
img.src = e.target.result;
img.onload = function () {
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
canvas.width = 200;
canvas.height = 200;
var xStart = 0;
var yStart = 0;
var newHeight = 0;
var newWidth = 0;
var aspectRadio = img.height / img.width;
if (img.height < img.width) {
//horizontal
aspectRadio = img.width / img.height;
newHeight = 200;
newWidth = aspectRadio * 200;
xStart = -(newWidth - 200) / 2;
} else {
//vertical
newWidth = 200;
newHeight = aspectRadio * 200;
yStart = -(newHeight - 200) / 2;
}
var ctx = canvas.getContext("2d");
ctx.drawImage(img, xStart, yStart, newWidth, newHeight);
dataurl = canvas.toDataURL(file.type);
document.getElementById('img_element').src = dataurl;
}
}
reader.readAsDataURL(file);
}
Are you displaying the image before uploading? You might want to do that to see if it is already rotated by iOS (similar issue here). As for a fix, this might be what you will want to use.
Edit:
My previous response was somewhat vague. To be more precise, you're having a problem with the EXIF orientation. Here is a JSFiddle that will show you the orientation of the image and how it looks as an <img/> vs. as a <canvas>. The fix previously mentioned is still the path you will probably want to take. You should be able to use the library to correctly orient the image in a <canvas>. Here is an example of that library in use. Hope this helps!

large Images Canvas with FF

i have a Pronlem with large Image Files to display it in a Canvas with FileReader. With small Images it works fine, in Chrome with large images too. But in Firefox it displays nothing and after toDataUrl its gives a black Image. The Image size is 5580 * 8333 (8mb).
If i load the dataUrl from FileReader in a Image Tag it works too.
var reader = new FileReader();
reader.onloadend = function () {
preview.src = reader.result;
console.log(reader.result);
var canvas = document.getElementById("resize");
var ctx = canvas.getContext("2d");
var image = new Image();
image.src = reader.result;
image.onload = function() {
var MAX_WIDTH = 400;
var MAX_HEIGHT = 300;
var tempW = image.width;
var tempH = image.height;
if (tempW > tempH) {
if (tempW > MAX_WIDTH) {
tempH *= MAX_WIDTH / tempW;
tempW = MAX_WIDTH;
}
} else {
if (tempH > MAX_HEIGHT) {
tempW *= MAX_HEIGHT / tempH;
tempH = MAX_HEIGHT;
}
}
image.width=tempW;
image.height=tempH;
canvas.width = tempW;
canvas.height = tempH;
ctx.drawImage(image, 0, 0, tempW, tempH);
};
}
if (file) {
reader.readAsDataURL(file);
} else {
preview.src = "";
}
}
Thanks for help

Error #2044: Unhandled IOErrorEvent: when LOOPED, but display correctly

I am trying to load images from server in a loop, it might have no image or max 3 images. Loading the image through URLRequest.
Not very sure how to correctly put this into a loop, it is giving me error 2044 twice then it display the image correctly. Thanks for your time and help!
for (var j:int = 5; j < somedata.length; j++)
{
var myLoader:Loader = new Loader();
var image:Bitmap;
var url:URLRequest = new URLRequest("http://www.rentaid.info/rent/"+somedata[j]);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
myLoader.load(url);
function onImageLoaded(e:Event):void {
image = new Bitmap(e.target.content.bitmapData);
var mw:Number = bf.width*2;
var mh:Number = bf.height*1.2;
image.y = bf4.y+25;
/* if you set width and height image same with the stage use this */
image.width = mw;
image.height = mh;
addChild(image);
}
}
Edit:
for (var j:int = 5; j < somedata.length; j++)
{
if(somedata[j]==! null){
var myLoader:Loader = new Loader();
var image:Bitmap;
var url:URLRequest = new URLRequest("http://www.rentaid.info/rent/"+somedata[j]);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
myLoader.load(url);
function onImageLoaded(e:Event):void {
image = new Bitmap(e.target.content.bitmapData);
var mw:Number = bf.width*2;
var mh:Number = bf.height*1.2;
image.y = bf4.y+25;
/* if you set width and height image same with the stage use this */
image.width = mw;
image.height = mh;
addChild(image);
}
}
}

Combobox's dropdown position for ipad (retina display) using As3 air application

the application which i created for ipad retina display in as3 mobile application. the combobox displayed in the screen in very small in size due to that changed the font, and size of the combo box dynamically. which all almost work fine. but the problem which was faced on the positioning of dropdown list, could not able to change the y position.
var tf:TextFormat = new TextFormat();
tf.font = "Arial";
tf.size = 35;
tf.color = 0x747070;
var dp:DataProvider = new DataProvider();
dp.addItem({label:"London", data:"item1"});
dp.addItem({label:"Paris", data:"item2"});
dp.addItem({label:"Sofia", data:"item3"});
dp.addItem({label:"Praha", data:"item4"});
dp.addItem({label:"Praha1", data:"item5"});
dp.addItem({label:"Praha2", data:"item6"});
_clip = new ComboBoxClip();
_clip.combo.dataProvider = dp;
_clip.combo.width = 199;
_clip.combo.height = 50;
_clip.combo.textField.setStyle("embedFonts", true);
_clip.combo.textField.setStyle("textFormat", tf);
_clip.combo.textField.setStyle("textPadding", 5);
_clip.combo.dropdown.setStyle("cellRenderer", CustomCellRenderer);
_clip.combo.dropdown.rowHeight = 31;
_clip.combo.dropdown.setStyle("paddingTop", 150);
_clip.combo.addEventListener(Event.CHANGE, onComboChange);
_clip.combo.tabIndex = 1;
_clip.x = _clip.y = 30;
addChild(_clip);
And the CustomeCellRenderer Class
public class CustomCellRenderer extends CellRenderer {
public function CustomCellRenderer() {
super();
var tf:TextFormat = new TextFormat();
tf.font = "Arial";
tf.size = 35;
tf.color = 0x747070;
setStyle("embedFonts", true);
setStyle("textFormat", tf);
}
override protected function drawLayout():void {
super.drawLayout()
textField.y += 2;
textField.x += 4;
}
}
Change the comboBox & dropdown height, width and text size to meet your needs.
var dp:DataProvider = new DataProvider();
dp.addItem({label:"London", data:"item1"});
dp.addItem({label:"Paris", data:"item2"});
dp.addItem({label:"Sofia", data:"item3"});
dp.addItem({label:"Praha", data:"item4"});
dp.addItem({label:"Praha1", data:"item5"});
dp.addItem({label:"Praha2", data:"item6"});
var tf:TextFormat;
tf = new TextFormat("Arial", 22, 0x747070);
comboBox.textField.height = 22;
comboBox.textField.setStyle("textFormat", tf);
comboBox.dropdown.setRendererStyle("textFormat", tf);
comboBox.dropdown.rowHeight = 32; //height of dropdown row
comboBox.dropdownWidth = 199; //combox and dropdown same width
comboBox.width = 199; //combox and dropdown same width
comboBox.height = 36;
comboBox.move(100, 100); //(x,y) use this to position comboBox
comboBox.prompt = "Select Something"; //if you need a prompt
comboBox.selectedItem = comboBox.getItemAt(-1); //show prompt
comboBox.dataProvider = dp;
comboBox.addEventListener(Event.CHANGE, onComboChange);
addChild(comboBox);

Three.js image disappearing after a few calls to requestAnimationFrame()

I am trying to get some basic movement/refreshing working in Three.js. I've cut the problem back to the following code.
A sphere displays fine first render, and twice (dictate by Nb), but the image vanishes for 3 renders that are called via requestAnimationFrame(simulate) (for 4 it displays then disappears); Am I missing something in how repeated rendering should happen ?
var sphere, WIDTH, HEIGHT, VIEW_ANGLE, ASPECT, NEAR, FAR, renderer, camera, scene, sphereMaterial, radius, sphere, pointLight, container;
function init() {
WIDTH = 400;
HEIGHT = 300;
VIEW_ANGLE = 45;
ASPECT = WIDTH / HEIGHT;
NEAR = 0.1;
FAR = 10000;
container = $('#container');
renderer = new THREE.WebGLRenderer();
camera = new THREE.PerspectiveCamera( VIEW_ANGLE,
ASPECT,
NEAR,
FAR );
scene = new THREE.Scene();
camera.position.z = 200;
renderer.setSize( WIDTH, HEIGHT );
container.append(renderer.domElement);
sphereMaterial = new THREE.MeshLambertMaterial(
{
color: 0xCC0000
});
radius = 50; segments = 16; rings = 16;
sphere = new THREE.Mesh(
new THREE.SphereGeometry(radius, segments, rings),
sphereMaterial);
//sphere.position.z -= 100;
scene.add(sphere);
scene.add(camera);
pointLight = new THREE.PointLight( 0xFFFFFF );
pointLight.position.x = 10;
pointLight.position.y = 50;
pointLight.position.z = 130;
scene.add(pointLight);
};
var Nb = 3;
var j = 0;
function simulate() {
console.log("simulate " + sphere.position.z);
if (j == Nb) { return; }
j++;
//sphere.position.z -= 1;
render();
requestAnimationFrame(simulate);
};
function render() {
console.log("rendering" + sphere.position.z);
renderer.render(scene,camera);
};
init();
simulate();`
This is solved after an update of Chromium browser in this case (and possible related libs/drivers) to version 25.0.1346.160. Isolated by using jsfiddle as shown above by Tomalak.