Image Rotation Animation in Windows Phone 7 - windows-phone-7

Upon Taping an image, i want the image to rotate. I checked online but nothing seems helpful.
So how can this be done?
Any help would be appreciated.
UPDATE:
I found the solution and it appears to be pretty simple. The following code does the trick of rotation animation of an image:
Duration duration = new Duration(TimeSpan.FromSeconds(2));
Storyboard sb = new Storyboard();
sb.Duration = duration;
DoubleAnimation da = new DoubleAnimation();
da.Duration = duration;
sb.Children.Add(da);
RotateTransform rt = new RotateTransform();
Storyboard.SetTarget(da, rt);
Storyboard.SetTargetProperty(da, new PropertyPath("Angle"));
da.To = 360;
Search.RenderTransform = rt;
Search.RenderTransformOrigin = new Point(0.5, 0.5);
sb.Begin();

The following code does the trick rotate an image:
Duration duration = new Duration(TimeSpan.FromSeconds(2));
Storyboard sb = new Storyboard();
sb.Duration = duration;
DoubleAnimation da = new DoubleAnimation();
da.Duration = duration;
sb.Children.Add(da);
RotateTransform rt = new RotateTransform();
Storyboard.SetTarget(da, rt);
Storyboard.SetTargetProperty(da, new PropertyPath("Angle"));
da.To = 360;
Search.RenderTransform = rt;
Search.RenderTransformOrigin = new Point(0.5, 0.5);
sb.Begin();

Related

unable to create document border using itext 7

Using the code below I try to set a border around my document, but nothing shows up:
PdfWriter pdfWriter = new PdfWriter(toFile);
PdfDocument pdfDoc = new PdfDocument(pdfWriter); //Initialize PDF document
var pageSize = PageSize.LETTER;
var document = new iText.Layout.Document(pdfDoc, pageSize); // Initialize document
var fontTimesRoman = PdfFontFactory.CreateFont(iText.IO.Font.Constants.StandardFonts.TIMES_ROMAN);
var fontTimesRomanBold = PdfFontFactory.CreateFont(iText.IO.Font.Constants.StandardFonts.TIMES_BOLD);
var navy = new DeviceRgb(0, 0, 128);
var red = new DeviceRgb(139, 0, 0);
document.SetBorder(new SolidBorder(red, 18));
document.Add( new Paragraph(DateTime.Now.ToString("MMMM dd, yyyy"))
.SetFont(fontTimesRoman)
.SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT)
//.SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.RIGHT)
.SetFontSize(11)
);
This won't work since the document is the size of the page and the Border will be outside of the page.
If you are trying to add a border to the edges of a Document you would need to do it in a PdfCanvas object
pdfDoc.AddNewPage();
var canvas = new PdfCanvas(pdfDoc, 1);
canvas.SetStokeColor(red);
canvas.SetLineWidth(18f);
canvas.Rectangle(0,1,pageSize.GetWidth()-1,pageSize.GetHeight()-1);
canvas.Stroke();
also don't forget to run
pdfDoc.Close();

Saving a polygon object into a bitmapimage in WIndows phone 8.1

I am working on a windows phone 8.1 app where I need to convert a polygon object to an image and ultimately save it as a png file. Till now, I created a polygon object with various properties. Now I'm clueless about the other parts.
pol.Opacity = 0.5;
System.Windows.Point Point1 = new System.Windows.Point(10, 200);
System.Windows.Point Point2 = new System.Windows.Point(60, 140);
System.Windows.Point Point3 = new System.Windows.Point(130, 140);
System.Windows.Point Point4 = new System.Windows.Point(180, 200);
System.Windows.Point Point5 = new System.Windows.Point(130, 260);
System.Windows.Point Point6 = new System.Windows.Point(60, 260);
PointCollection myPointCollection = new PointCollection();
myPointCollection.Add(Point1);
myPointCollection.Add(Point2);
myPointCollection.Add(Point3);
myPointCollection.Add(Point4);
myPointCollection.Add(Point5);
myPointCollection.Add(Point6);
pol.Points = myPointCollection;
var imageBrush = new ImageBrush();
imageBrush.ImageSource = image.Source;
pol.Fill = imageBrush;
pol.Height = image.Height;
pol.MaxHeight = image.Height;
pol.MaxWidth = image.Width;
pol.Width = image.Width;
pol.Stroke = new SolidColorBrush(Colors.Red);
pol.StrokeThickness = 2;
pol.Margin = image.Margin;
You can use the WritableBitmap class in order to achieve this. I have a similar post on Silverlight, which you can refer: How to Crop an Image based on a Shape or Path control?. Hope that helps, at least gives some basic concepts. Let me know, if you need further help on this.
To save the shape as PNG, you can utilize the following code snippet:
WriteableBitmap bmp = GetAsWritableBitmap();
using (var mediaLibrary = new MediaLibrary())
{
using (var stream = new MemoryStream())
{
var fileName = string.Format("Gs{0}.jpg", Guid.NewGuid());
bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 100);
stream.Seek(0, SeekOrigin.Begin);
var picture = mediaLibrary.SavePicture(fileName, stream);
if (picture.Name.Contains(fileName)) return true;
}
}
Hope that helps.

C# Winforms how to resize image and save

hi I want to open a image file with openfiledialog and resize to upload to database so please help me with this code which I got from some where but I don't know how to make it working thanks
private void ResizeImg(double scaleFactor, Stream sourcePath, string tragetPath)
{
using (var image = System.Drawing.Image.FromStream(sourcePath))
{
var newWidth = (int)(image.Width * scaleFactor);
var newHeight = (int)(image.Height * scaleFactor);
var resizingImg = new Bitmap(newWidth, newHeight);
var resizeGraph = Graphics.FromImage(resizingImg);
resizeGraph.CompositingQuality = CompositingQuality.HighQuality;
resizeGraph.SmoothingMode = SmoothingMode.HighQuality;
resizeGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
resizeGraph.DrawImage(image, imageRectangle);
resizingImg.Save(targetPath, image.RawFormat);
}
}
Without specifying source and target rectangle, it doesn't stretch.
Change
resizeGraph.DrawImage(image, imageRectangle);
to
var srcRectangle = new Rectangle(0, 0, image.Width, image.Height);
resizeGraph.DrawImage(image, imageRectangle,srcRectangle, GraphicsUnit.Pixel);
BTW: Consider ImageFormat.Jpeg or .Png for Save, because you cannot write all image formats you can read.

How to add text Stamp annotation in a rotation pdf

I want to add stamp annotation with text into a pdf.
The rotation of the pdf is 270.
The code I wrote, but the stamp rotation is wrong.
PdfReader reader = new PdfReader(file.getAbsolutePath(), "PDF".getBytes());
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outFile));
int i = 1;
PdfContentByte content = stamper.getOverContent(i);
Rectangle pageRect = reader.getPageSizeWithRotation(i);
float pageWidth = pageRect.getWidth();
float pageHeight = pageRect.getHeight();
float rectWidth = 700;
float rectHeight = 500;
float fontsize = 40;
content.setFontAndSize(font, fontsize);
rectWidth = content.getEffectiveStringWidth(stampLabel,false);
Rectangle rectangle = new Rectangle(0,0,rectWidth, rectHeight);
PdfAppearance appearance = content.createAppearance(rectWidth,rectHeight);
appearance.setColorFill(BaseColor.RED);
appearance.setFontAndSize(font, fontsize);
rectangle.setBorder(Rectangle.BOX);
rectangle.setBorderColor(BaseColor.RED);
rectangle.setBorderWidth(2);
appearance.rectangle(rectangle);
appearance.saveState();
appearance.beginText();
appearance.showText(stampLabel);
appearance.restoreState();
PdfAnnotation stampAnnot = PdfAnnotation.createStamp(content.getPdfWriter(), rectangle,stampLabel,"STATUA_STAMP");
stampAnnot.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, appearance);
stampAnnot.setFlags(PdfAnnotation.FLAGS_PRINT);
stamper.addAnnotation(stampAnnot, i);

Three.js scene background doesn't appear

I'm trying to add a background to a webgl scene(Three.js). The scene contains two animated spritesheets that I created using DAZ3D and Photoshop. I've tried just about everything but to no avail, the background is either white or black. I've tried many examples on the web then either my spritesheet animator won't work or the background won't appear. I read that I need to make two scenes with two camera's, but that doesn't seem to work as well.
I really don't understand why I would need to have two scenes anyway.
<script>
// standard global variables
var container,scene,camera,renderer,controls,stats;
var keyboard = new THREEx.KeyboardState();
var clock = new THREE.Clock();
// custom global variables
var attack,defense;
init();
animate();
// FUNCTIONS
function init(){
// SCENE
scene = new THREE.Scene();
// CAMERA
var SCREEN_WIDTH = window.innerWidth,SCREEN_HEIGHT = window.innerHeight;
var VIEW_ANGLE = 45,ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT,NEAR = 0.1,FAR = 1000;
var light = new THREE.PointLight(0xEEEEEE);
var lightAmb = new THREE.AmbientLight(0x777777);
camera = new THREE.PerspectiveCamera(VIEW_ANGLE,ASPECT,NEAR,FAR);
scene.add(camera);
camera.position.set(-10,30,400);
camera.lookAt(scene.position);
// RENDERER
if (Detector.webgl)
renderer = new THREE.WebGLRenderer({antialias:true});
else
renderer = new THREE.CanvasRenderer();
renderer.setSize(SCREEN_WIDTH,SCREEN_HEIGHT);
container = document.getElementById('ThreeJS');
container.appendChild(renderer.domElement);
// EVENTS
THREEx.WindowResize(renderer,camera);
THREEx.FullScreen.bindKey({charCode :'m'.charCodeAt(0)});
// LIGHTS
light.position.set(20,0,20);
scene.add(light);
scene.add(lightAmb);
// BACKGROUND
var texture = THREE.ImageUtils.loadTexture('images/sky.jpg');
var backgroundMesh = new THREE.Mesh(new THREE.PlaneGeometry(2,2,0),new THREE.MeshBasicMaterial({map:texture}));
backgroundMesh.material.depthTest = false;
backgroundMesh.material.depthWrite = false;
var backgroundScene = new THREE.Scene();
var backgroundCamera = new THREE.Camera();
backgroundScene.add(backgroundCamera);
backgroundScene.add(backgroundMesh);
// FLOOR
var floorTexture = new THREE.ImageUtils.loadTexture('images/checkerboard.jpg');
floorTexture.wrapS = floorTexture.wrapT = THREE.RepeatWrapping;
floorTexture.repeat.set(10,10);
var floorMaterial = new THREE.MeshBasicMaterial({map:floorTexture,side:THREE.DoubleSide,shininess:30});
var floorGeometry = new THREE.PlaneGeometry(1000,1000);
var floor = new THREE.Mesh(floorGeometry,floorMaterial);
floor.position.y = -0.5;
floor.rotation.x = Math.PI / 2;
scene.add(floor);
// MESHES WITH ANIMATED TEXTURES!
var attackerTexture = new THREE.ImageUtils.loadTexture('images/kitinalevel2.png');
attack = new TextureAnimator(attackerTexture,2,13,26,25); // texture,#horiz,#vert,#total,duration.
var attackerMaterial = new THREE.MeshBasicMaterial({map:attackerTexture,side:THREE.DoubleSide,transparent:true});
var attackerGeometry = new THREE.PlaneGeometry(50,50,1,1);
var attacker = new THREE.Mesh(attackerGeometry,attackerMaterial);
attacker.position.set(-5,20,350);
scene.add(attacker);
var defenderTexture = new THREE.ImageUtils.loadTexture('images/kitinalevel1.png');
defense = new TextureAnimator(defenderTexture,2,13,26,25); // texture,#horiz,#vert,#total,duration.
var defenderMaterial = new THREE.MeshBasicMaterial({map:defenderTexture,side:THREE.DoubleSide,transparent:true});
var defenderGeometry = new THREE.PlaneGeometry(50,50,1,1);
var defenderx = new THREE.Mesh(defenderGeometry,defenderMaterial);
defenderx.position.set(25,20,350);
scene.add(defenderx);
}
function animate(){
requestAnimationFrame(animate);
render();
update();
}
function update(){
var delta = clock.getDelta();
attack.update(1000 * delta);
defense.update(1000 * delta);
//controls.update();
//stats.update();
}
function render(){
renderer.autoClear = false;
renderer.clear();
renderer.render(scene,camera);
renderer.render(backgroundScene,backgroundCamera);
}
function TextureAnimator(texture,tilesHoriz,tilesVert,numTiles,tileDispDuration){
// note:texture passed by reference,will be updated by the update function.
this.tilesHorizontal = tilesHoriz;
this.tilesVertical = tilesVert;
// how many images does this spritesheet contain?
// usually equals tilesHoriz * tilesVert,but not necessarily,
// if there at blank tiles at the bottom of the spritesheet.
this.numberOfTiles = numTiles;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(1 / this.tilesHorizontal,1 / this.tilesVertical);
// how long should each image be displayed?
this.tileDisplayDuration = tileDispDuration;
// how long has the current image been displayed?
this.currentDisplayTime = 0;
// which image is currently being displayed?
this.currentTile = 0;
this.update = function(milliSec){
this.currentDisplayTime += milliSec;
while(this.currentDisplayTime>this.tileDisplayDuration){
this.currentDisplayTime-=this.tileDisplayDuration;
this.currentTile++;
if (this.currentTile == this.numberOfTiles)
this.currentTile = 0;
var currentColumn = this.currentTile%this.tilesHorizontal;
texture.offset.x = currentColumn/this.tilesHorizontal;
var currentRow = Math.floor(this.currentTile/this.tilesHorizontal);
texture.offset.y = currentRow/this.tilesVertical;
}
};
}
</script>
What am I doing wrong?
Thanks in advance.
Found a solution:
renderer = new THREE.WebGLRenderer({antialias:true,alpha: true });
This will keep the background transparant, then with a little css I made the background appear.

Resources