I am currently building a Flash AS 3.0 application that allows a user to load images into a container, move and scale them and the outputs to a DB. Once the user has uploaded and scaled the images, they are directed to an album viewer which gets the photos out of the DB and puts them into heads. The issue i am having is that once the images go into the viewer, the scaling and positining is not working correctly. The images will scale larger but i cannot shrink them from thrie original size.
I am using the following code to scale the images in the viewer:
headToLoad.width = headWidth;
headToLoad.scaleY > headToLoad.scaleX ? headToLoad.scaleX = headToLoad.scaleY : headToLoad.scaleY = headToLoad.scaleX;
headToLoad.x = xPosition;
headToLoad.y = yPosition;
Any assistance would be great.
Thanks
Justin
I'm not sure what you are trying to do with that 2nd line, but try with this:
headToLoad.width = headWidth;
headToLoad.scaleY = headToLoad.scaleX;
The function does what it should do.
If you want a something that would constrict the size of a loaded image to a maximum width and height, mantaining the ratio, you could use something like this.
import flash.display.*;
import flash.net.URLRequest;
import flash.events.Event;
var maxWidth = 200;
var maxHeight = 300;
var headToLoad:Loader = new Loader();
headToLoad.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadCompleted);
addChild(headToLoad);
headToLoad.load(new URLRequest("picture.jpg"));
function onLoadCompleted(evt:Event) {
var head = evt.target.loader; // or evt.target.content
head.width = maxWidth;
head.scaleY = head.scaleX;
if (head.height > maxHeight) {
head.height = maxHeight;
head.scaleX = head.scaleY;
}
head.x = 100;
head.y = 100;
}
Related
I need to recreate a program similar to whatsapp that can send and receive messages, images videos and audio. I have created a WPF form to show messages that looks like this:
I have a stack panel that contains text bubbles on them. Text messages work fine but if I send an image I want the user to be able to click on the image text bubble and it must become full screen. The image text bubble consists of a label that has a frame in it and then within that frame the image is stored. The label was used since we could resize the label.
However, because the image is done like this dynamically, we cannot seem to register an on-click event on this image bubble. If you have any better ways that we can display the image or how to log this event it would be much appreciated. Here is the method used to add the image.
public void AddMessage_Image(string path, string displayName, int role, string date = "")
{
//Create an image from the path
ImageBrush image = new ImageBrush();
image.ImageSource = new BitmapImage(new Uri(path, UriKind.Absolute));
image.Stretch = Stretch.Uniform;
//Create a frame in which to place the image
Frame fr = new Frame();
fr.Background = image;
fr.MinHeight = 120;
fr.MinWidth = 160;
//Ensure scalabilty of the image
Viewbox vb = new Viewbox();
vb.Child = fr;
vb.Stretch = Stretch.Uniform;
//Place the image in a sizable container
Label lbl = new Label();
lbl.MinHeight = 10;
lbl.MinWidth = 10;
lbl.MaxHeight = 300;
lbl.MaxWidth = 400;
lbl.Content = vb;
if (role == (int) Role.Sender)
lbl.HorizontalAlignment = HorizontalAlignment.Right;
else
lbl.HorizontalAlignment = HorizontalAlignment.Left;
lbl.Background = Brushes.Black;
//Place the image in the chat
chatbox.Children.Add(lbl);
}
I'm trying to generate a Word document through my application coded in WPF. In that document, I also need to layout few images along with caption as shown in the image below.
All the images are stored in database as base64 string. I'm able to load the images as "BitmapImage" object in the document however not sure how to layout the images as shown in image. Code snippet to load the images in document is as below :
var bookmarks = wordDoc.Bookmarks;
var range = bookmarks["ExternalImage"].Range;
foreach (var image in ExternalImages) // here image is "BitmapImage" object
{
float scaleHeight = (float)250 / (float)image.Image.PixelHeight;
float scaleWidth = (float)250 / (float)image.Image.PixelWidth;
var min = Math.Min(scaleHeight, scaleWidth);
var bitmap = new TransformedBitmap(image, new ScaleTransform(min, min));
System.Windows.Clipboard.SetImage(bitmap);
range.Paste();
}
How can I lay out the images as shown in image above along with caption? Note that I'm not loading images from file but from memory object.
Based on the direction provided by #CindyMeister in comments, following is the working code snippet to layout the images using code :
imageTable = wordDoc.Tables.Add(sel.Range, rows, cols, ref oMissing, ref oMissing);
imageTable.AllowAutoFit = true;
row = 1; col = 1;
foreach (var image in Images)
{
float scaleHeight = (float)475 / (float)image.PixelHeight;
// here 475 is approx image size I want in word document
float scaleWidth = (float)475 / (float)image.PixelWidth;
var min = Math.Min(scaleHeight, scaleWidth);
var bitmap = new TransformedBitmap(image, new ScaleTransform(min, min));
System.Windows.Clipboard.SetImage(bitmap);
//more efficient/faster in C# if you don't "drill down" multiple times to get an object
Word.Cell cel = imageTable.Cell(row, col);
Word.Range rngCell = cel.Range;
Word.Range rngTable = imageTable.Range;
rngCell.Paste();
cel.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
rngCell.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
// set caption below image
rngTable.ParagraphFormat.SpaceAfter = 6;
rngCell.InsertAfter(image.Caption);
rngTable.Font.Name = "Arial Bold";
row++;
}
This code I have posted for reference, only, to let people have some starting point. Any suggestions welcome.
I have the following png:
Each Icon is 100X100 px. All in all 800X100 px.
I have the following ImageView xml:
<ImageView
android:id="#+id/CycleStageImage"
android:layout_width="100dp"
android:layout_height="100dp">
I would like to set CycleStageImage to be show different Icon (100,100) on Timer Interval of 1 Second back and forth.
I am having a problem generating a code that moves on Axis of this PNG.
I have tried the followings from multiple links over SOF, but with no luck:
//first try - not working
//Resources res = mainActivity.ApplicationContext.Resources;
//Bitmap bitmap = BitmapFactory.DecodeResource(res, Resource.Id.CycleImage);
//BitmapDrawable bitmapDrawable = new BitmapDrawable(Resources.System, bitmap);
//ClipDrawable clipDrawable = new ClipDrawable(bitmapDrawable, GravityFlags.Center, ClipDrawable.Horizontal);
//clipDrawable.SetBounds(100, 100, 100, 100);
//clipDrawable.SetLevel(100);
//imageView.SetImageResource(Android.Resource.Color.Transparent);
//imageView.SetImageDrawable(clipDrawable);
//second try - shows only part of the left top corner
//double TUNNING = 0.5; //0.5 cut in half
//Bitmap srcBmp = BitmapFactory.DecodeResource(Resources.System, cycleStage);
//Bitmap modBmp = Bitmap.CreateBitmap(
// srcBmp,
// 0,
// srcBmp.Height, // TUNNING
// srcBmp.Height,
// srcBmp.Height
// );
//third try - same as the second try.
//int START_X = 0;
//int START_Y = 100;
//int WIDTH_PX = 100;
//int HEIGHT_PX = 100;
//// Crop bitmap
//Bitmap newBitmap = Bitmap.CreateBitmap(SOURCE_BITMAP, START_X, START_Y, WIDTH_PX, HEIGHT_PX, null, false);
//// Assign new bitmap to ImageView
//imageView.SetImageBitmap(newBitmap);
I have followed the Android tutorial:
https://developer.android.com/guide/topics/resources/drawable-resource.html#Clip
but with no luck..
It would be much appreciated the help with timer as well with the png.
Thanks!
Finally I got it to work, following these steps:
(Although I admit its a bit lame...)
I divided the above PNG into 8 (100x100) PNGs each using online tool -> PNG Splitter
I created a GIF using online tool - GIF Maker -> http://gifmaker.me/
I have placed the saved gif under "Assets" folder and changed its properties-> build action to "AndroidAsset"
I have created WebView and placed it inside my XML screen. it looks like this:
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/MyWebView"
android:layout_width="100dp"
android:layout_height="100dp"/>
In my Activity I generated the code as follows:
WebView myWebView = (WebView)findViewById(Resource.Id.MyWebView);
myWebView.loadUrl("file:///android_asset/Gif.gif");
It works like a charm!
I hope it will be of assistant to anyone who desires to accomplish running GIF's inside android application.
Good Luck.
i am working on a Mobile project (iPad with iOS 8.0.2);
I want to make clipping of my immage in order to display less from it.
When displaying on PC it works perfectly well, while we test it on the tablet the clipped image is not displayed at all.
Do you have any suggestions
this.background = new createjs.Bitmap('some_image.png');
//create a clipping of drawn image!
var dims = this.background.getBounds();
this.background.sourceRect = new createjs.Rectangle(0, 15, dims.width, dims.height);
this.background.x = 248;
this.background.y = 86;
this.stage.addChild(this.background);
I met the same trouble like this.I have given up using Bitmap to clipping the image. I have found another solution ,here is "
easeljs splitting an image into pieces
".Good luck.
I am working out, the code like this:
var img, stage;
function init() {
//wait for the image to load
img = new Image();
img.onload = handleImageLoad;
img.src = "./res/image.png";
}
function handleImageLoad(evt) {
// create a new stage and point it at our canvas:
stage = new createjs.Stage("canvas");
// create a new Bitmap, and slice out one image from the sprite sheet:
var bmp = new createjs.Bitmap(evt.target).set({x:200, y:200});
bmp.sourceRect = new createjs.Rectangle(916, 101, 84, 84);
//x,y,width,height
stage.addChild(bmp);
stage.update();
}
This is the example:
https://github.com/CreateJS/EaselJS/blob/master/examples/Filters_animated.html
I am generating a set images to form a human body so that I can use for a physics engine.
The images generated are in a specific user control in where I set the dimentions and co-ordinates of each image. That usercontrol is then loaded in another user control but for some reason when the images are loaded, one specific image which I named (rightBicep) is shifting to the right. Here is a screenshot :
alt text http://img193.imageshack.us/img193/592/imageshift.jpg
I illustrated the positions of the images with dotted lines, the green dotted line is refering to where the image should be located, and the red dotted line is where the image is being shown.
The weird thing is the image beneath it (called rightForearm) take's it's LeftPosition from it, and when during debugging they have the exact same leftProperty value. Here's the syntax :
public void generateRightBicep(string imageUrl)
{
rightBicep = new Image();
rightBicep.Name = CharacterName + "rightbicep";
Uri imageUri = new Uri(imageUrl, UriKind.Relative);
LayoutRoot.Children.Add(rightBicep);
rightBicep.Source = new BitmapImage(imageUri);
rightBicep.ImageOpened += new EventHandler<RoutedEventArgs>(bodyPart_ImageOpened);
}
public void rightBicepLoaded()
{
var bi = waitTillImageLoad(rightBicep.Name);
rightBicep.Height = elbowToArmpit + (2 * palm);
rightBicep.Width = ratio(bi.PixelHeight, bi.PixelHeight, rightBicep.Height); // to be determined
Vector2 topVector;
topVector.X = (float)(Convert.ToDouble(torso.GetValue(Canvas.LeftProperty)) - palm);
topVector.Y = (float)(Convert.ToDouble(neck.GetValue(Canvas.TopProperty)) + neck.Height);
if (!faceRight)
{
perspectiveVectorHeight(ref topVector, ref rightBicep, torso.Width);
rightBicep.Width = ratio(bi.PixelHeight, bi.PixelHeight, rightBicep.Height);
}
rightBicep.SetValue(Canvas.LeftProperty, Convert.ToDouble(topVector.X));
rightBicep.SetValue(Canvas.TopProperty, Convert.ToDouble(topVector.Y));
rightBicep.SetValue(Canvas.ZIndexProperty, rightBicepZindex);
generateRightShoulder();
}
public void generateRightForearm(string imageUrl)
{
rightForearm = new Image();
rightForearm.Name = CharacterName + "rightforearm";
Uri imageUri = new Uri(imageUrl, UriKind.Relative);
LayoutRoot.Children.Add(rightForearm);
rightForearm.Source = new BitmapImage(imageUri);
rightForearm.ImageOpened += new EventHandler<RoutedEventArgs>(bodyPart_ImageOpened);
}
public void rightForearmLoaded()
{
var bi = waitTillImageLoad(rightForearm.Name);
rightForearm.Height = (elbowToHandTip - handLength) + palm;
rightForearm.Width = ratio(bi.PixelHeight, bi.PixelWidth, rightForearm.Height);
Vector2 topVector;
if (faceRight)
{
topVector.X = (float)(Convert.ToDouble(rightBicep.GetValue(Canvas.LeftProperty)));
topVector.Y = (float)(Convert.ToDouble(rightBicep.GetValue(Canvas.TopProperty)) + rightBicep.Height - palm);
}
else
{
topVector.X = (float)(Convert.ToDouble(leftBicep.GetValue(Canvas.LeftProperty)));
topVector.Y = (float)(Convert.ToDouble(leftBicep.GetValue(Canvas.TopProperty)) + leftBicep.Height - palm);
perspectiveVectorHeight(ref topVector, ref rightForearm, torso.Width);
rightForearm.Width = ratio(bi.PixelHeight, bi.PixelWidth, rightForearm.Height);
}
rightForearm.SetValue(Canvas.LeftProperty, Convert.ToDouble(topVector.X));
rightForearm.SetValue(Canvas.TopProperty, Convert.ToDouble(topVector.Y));
rightForearm.SetValue(Canvas.ZIndexProperty, rightForearmZIndex);
generateRightElbow();
}
Now all the values I am adding together are a group of doubles I preset, and the property faceRight is to dertmine if the human body is facing right or left to determine where the positions of the body parts (since if the right hand looks on the left hand side when the human body turns the other way).
If you notice the rightforearm is taking the leftproperty of the rightbicep, so technically it should display direcrly underneath which it isn't. I also debugged the user control and both have the left property of -3.
PS. I call the methods rightbicepLoaded and rightforearmLoaded when an event is called when all the imageOpened events all have been triggered.
Any ideas on why this is happening?
Found out why , in my method ratio it should take hieght and width, and I put and i put 2 hieghts instead