How can I rotate picture dynamically? - image

I have a resource in my prog (*.bmp image). When I start a timer, my image should rotate until I click "pause". I need a sample which explain me how I could to do this.
Currently I use this code:
void rotatewaiticon()
{
Graphics::TBitmap *bmpOriginal = new Graphics::TBitmap();
//bmpOriginal->LoadFromResourceName(0,"bmpcrug");
bmpOriginal->LoadFromFile("degrees.bmp");
FormMain->Image65->Picture->Assign(bmpOriginal);
Graphics::TBitmap *bmpCopy = new Graphics::TBitmap();
bmpCopy->Width = bmpOriginal->Height;
bmpCopy->Height = bmpOriginal->Width;
int wOr = bmpOriginal->Width, hOr = bmpOriginal->Height;
for(int x = 0; x < wOr; x++)
{
for(int y = 0; y < hOr; y++)
{
bmpCopy->Canvas->Pixels[hOr - y][x] = bmpOriginal->Canvas->Pixels[x][y];
}
}
/**/FormMain->Image65->Picture->Assign(bmpCopy);
bmpCopy->SaveToFile("degrees.bmp");
delete bmpOriginal, bmpCopy;
}
But I don't see a way to work with this file without saving it on a disk.

Related

Is it possible to convert an AutoCAD solid3d entity to an Eyeshot brep entity and add it to the Eyeshot model viewport?

I am drawing a Cad Solid3d Entity by changing it to Brep and approaching the face,
but the shape is different. what's wrong
Or is there a way to directly import Autocad solid3d entity into the Eyeshot Model Viewport without redrawing with geometry information?
Below is my code
public void Main()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
CivilDocument cdoc = CivilApplication.ActiveDocument;
using (doc.LockDocument())
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
List<GBrep.Face> gFaces = new List<GBrep.Face>();
ObjectId solid3dId = EditorInputUtil.GetEntityId(ed, typeof(Solid3d));
GBRepView gBRepView = new GBRepView();
using (Solid3d solid = tr.GetObject(solid3dId, OpenMode.ForWrite) as Solid3d)
using (Brep brep = new Brep(solid))
{
foreach (Face face in brep.Faces)
{
Autodesk.AutoCAD.Geometry.NurbSurface nurbSurface = face.GetSurfaceAsNurb();
int uDegree = nurbSurface.DegreeInU;
int vDegree = nurbSurface.DegreeInV;
KnotCollection uKnotVector = nurbSurface.UKnots;
KnotCollection vKnotVector = nurbSurface.VKnots;
double[] uKnots = ConvertKnotVector(uKnotVector);
double[] vKnots = ConvertKnotVector(vKnotVector);
Point3dCollection p3ts = nurbSurface.ControlPoints;
Point4D[,] controlPoints = ConvertControlPoints(p3ts, nurbSurface.NumControlPointsInU, nurbSurface.NumControlPointsInV);
GSurface gSurface = new GSurface(uDegree, uKnots, vDegree, vKnots, controlPoints);
gBRepView.GetModel.Entities.Add(new devDept.Eyeshot.Entities.Surface(gSurface));
}
}
gBRepView.ShowDialog();
}
}
}
private Point4D[,] ConvertControlPoints(Point3dCollection point3ds, int uNums, int vNums)
{
Point4D[,] controlPoints = new Point4D[uNums, vNums];
int count = 0;
for (int i = 0; i < uNums; i++)
{
for (int j = 0; j < vNums; j++)
{
Point3d cadPoint = point3ds[count];
controlPoints[i, j] = new Point4D(cadPoint.X, cadPoint.Y, cadPoint.Z);
count++;
}
}
return controlPoints;
}

How to render Sprites normally on rotated isometric tiles? LIBGDX

i was using this tutorial to make an isometric Map from normal Sprites:
http://www.badlogicgames.com/wordpress/?p=2032
I want to render a house on top of my floor tiles at position 0,0, but it looks like this:
http://gyazo.com/c7d5cd74829150c684cfa7b40c9fdfba
Here is my create() and render():
#Override
public void create () {
batch = new SpriteBatch();
img = new Texture(Gdx.files.internal("grass2d.jpg"));
//House
house = new Sprite(new Texture(Gdx.files.internal("mb_0004.png")));
house.setSize(2,2);
house.setPosition(0,0);
// Camera
cam = new OrthographicCamera(10,10*(Gdx.graphics.getHeight()/(float)Gdx.graphics.getWidth()));
cam.position.set(5,5,10);
cam.direction.set(-1,-1,-1);
cam.near = 1;
cam.far = 100;
//Matrices
//Matrix to rotate floor tiles
matrix.setToRotation(new Vector3(1,0,0), 90);
// Subject to change?
matrix2.setToRotation(new Vector3(0,1,0),45);
// populate Tiles
for(int z = 0; z < 100; z++) {
for(int x = 0; x < 100; x++) {
sprites[x][z] = new Sprite(img);
sprites[x][z].setPosition(x,z);
sprites[x][z].setSize(1, 1);
}
}
Gdx.input.setInputProcessor(this);
}
#Override
public void render () {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
cam.update();
batch.setProjectionMatrix(cam.combined);
batch.setTransformMatrix(matrix);
batch.begin();
for(int z = 0; z < 100; z++) {
for(int x = 0; x < 100; x++) {
sprites[x][z].draw(batch);
}
}
batch.end();
batch.begin();
//batch.setTransformMatrix(matrix2);
house.draw(batch);
batch.end();
I did try to create another Matrix to transform it back, but then my coordinates are messed up. Hope you guys can help.
i was able to do it using TiledMap and a self written algorithm to detect wether or not a tile has been clicked and which one. I am able to place my house by mouse now and really like the result.
If anybody is interested, i will take some time to write a small tutorial.
Here is what it looks like at the moment:
Isometric Tiles

As3 Position on top based on Y without lag?

I was creating a position script with my own made tag system to position all the objects in order of the y position they have. This script makes my game lag so I wanted to ask if there is a better way of doing this.
PS: This code is used every frame.
private function positionGameObjectToLayer():void
{
var objectOnScreen : Array = [];
var parentObj : Sprite;
var l : int;
l = gameObjects.length;
for (var i : int = 0; i < l; i++) {
/*checks if the object has the position tag*/
if (gameObjects[i].checkTag(Tags.POSITION_ON_Y_TAG)) {
objectOnScreen.push(gameObjects[i]); //if it does it goes into this array
}
}
objectOnScreen.sortOn("y", Array.NUMERIC); /* sorts the array on y position*/
l = objectOnScreen.length;
for (i = 0; i < l; i++) {
/*this sets the layer of the object in order of the array*/
parentObj = objectOnScreen[i].parent;
parentObj.setChildIndex(objectOnScreen[i],parentObj.numChildren - 1);
}
l = gameObjects.length;
for (i = 0; i < l; i++) {
//if it has the always on top tag
if (gameObjects[i].checkTag(Tags.POSITION_ON_TOP_TAG)) {
/*then this code will grab that object and place it over the other layers*/
parentObj = gameObjects[i].parent;
parentObj.setChildIndex(gameObjects[i], parentObj.numChildren - 1);
}
}
}

How to run processing script on multiple frames in a folder

Using processing I am trying to run a script that will process a folder full of frames.
The script is a combination of PixelSortFrames and SortThroughSeamCarving.
I am new to processing and what I want does not seems to be working. I would like the script to run back through and choose the following file in the folder to be processed. At the moment it stops at the end and does not return to start on next file (there are three other modules also involved).
Any help would be much appreciated. :(
/* ASDFPixelSort for video frames v1.0
Original ASDFPixelSort by Kim Asendorf <http://kimasendorf.com>
https://github.com/kimasendorf/ASDFPixelSort
Fork by dx <http://dequis.org> and chinatsu <http://360nosco.pe>
// Main configuration
String basedir = ".../Images/Seq_002"; // Specify the directory in which the frames are located. Use forward slashes.
String fileext = ".jpg"; // Change to the format your images are in.
int resumeprocess = 0; // If you wish to resume a previously stopped process, change this value.
boolean reverseIt = true;
boolean saveIt = true;
int mode = 2; // MODE: 0 = black, 1 = bright, 2 = white
int blackValue = -10000000;
int brightnessValue = -1;
int whiteValue = -6000000;
// -------
PImage img, original;
float[][] sums;
int bottomIndex = 0;
String[] filenames;
int row = 0;
int column = 0;
int i = 0;
java.io.File folder = new java.io.File(dataPath(basedir));
java.io.FilenameFilter extfilter = new java.io.FilenameFilter() {
boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(fileext);
}
};
void setup() {
if (resumeprocess > 0) {i = resumeprocess - 1;frameCount = i;}
size(1504, 1000); // Resolution of the frames. It's likely there's a better way of doing this..
filenames = folder.list(extfilter);
size(1504, 1000);
println(" " + width + " x " + height + " px");
println("Creating buffer images...");
PImage hImg = createImage(1504, 1000, RGB);
PImage vImg = createImage(1504, 1000, RGB);
// draw image and convert to grayscale
if (i +1 > filenames.length) {println("Uh.. Done!"); System.exit(0);}
img = loadImage(basedir+"/"+filenames[i]);
original = loadImage(basedir+"/"+filenames[i]);
image(img, 0, 0);
filter(GRAY);
img.loadPixels(); // updatePixels is in the 'runKernals'
// run kernels to create "energy map"
println("Running kernals on image...");
runKernels(hImg, vImg);
image(img, 0, 0);
// sum pathways through the image
println("Getting sums through image...");
sums = getSumsThroughImage();
image(img, 0, 0);
loadPixels();
// get start point (smallest value) - this is used to find the
// best seam (starting at the lowest energy)
bottomIndex = width/2;
// bottomIndex = findStartPoint(sums, 50);
println("Bottom index: " + bottomIndex);
// find the pathway with the lowest information
int[] path = new int[height];
path = findPath(bottomIndex, sums, path);
for (int bi=0; bi<width; bi++) {
// get the pixels of the path from the original image
original.loadPixels();
color[] c = new color[path.length]; // create array of the seam's color values
for (int i=0; i<c.length; i++) {
try {
c[i] = original.pixels[i*width + path[i] + bi]; // set color array to values from original image
}
catch (Exception e) {
// when we run out of pixels, just ignore
}
}
println(" " + bi);
c = sort(c); // sort (use better algorithm later)
if (reverseIt) {
c = reverse(c);
}
for (int i=0; i<c.length; i++) {
try {
original.pixels[i*width + path[i] + bi] = c[i]; // reverse! set the pixels of the original from sorted array
}
catch (Exception e) {
// when we run out of pixels, just ignore
}
}
original.updatePixels();
}
// when done, update pixels to display
updatePixels();
// display the result!
image(original, 0, 0);
if (saveIt) {
println("Saving file...");
//filenames = stripFileExtension(filenames);
save("results/SeamSort_" + filenames + ".tiff");
}
println("DONE!");
}
// strip file extension for saving and renaming
String stripFileExtension(String s) {
s = s.substring(s.lastIndexOf('/')+1, s.length());
s = s.substring(s.lastIndexOf('\\')+1, s.length());
s = s.substring(0, s.lastIndexOf('.'));
return s;
}
This code works by processing all images in the selected folder
String basedir = "D:/things/pixelsortframes"; // Specify the directory in which the frames are located. Use forward slashes.
String fileext = ".png"; // Change to the format your images are in.
int resumeprocess = 0; // If you wish to resume a previously stopped process, change this value.
int mode = 1; // MODE: 0 = black, 1 = bright, 2 = white
int blackValue = -10000000;
int brightnessValue = -1;
int whiteValue = -6000000;
PImage img;
String[] filenames;
int row = 0;
int column = 0;
int i = 0;
java.io.File folder = new java.io.File(dataPath(basedir));
java.io.FilenameFilter extfilter = new java.io.FilenameFilter() {
boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(fileext);
}
};
void setup() {
if (resumeprocess > 0) {i = resumeprocess - 1;frameCount = i;}
size(1920, 1080); // Resolution of the frames. It's likely there's a better way of doing this..
filenames = folder.list(extfilter);
}
void draw() {
if (i +1 > filenames.length) {println("Uh.. Done!"); System.exit(0);}
row = 0;
column = 0;
img = loadImage(basedir+"/"+filenames[i]);
image(img,0,0);
while(column < width-1) {
img.loadPixels();
sortColumn();
column++;
img.updatePixels();
}
while(row < height-1) {
img.loadPixels();
sortRow();
row++;
img.updatePixels();
}
image(img,0,0);
saveFrame(basedir+"/out/"+filenames[i]);
println("Frames processed: "+frameCount+"/"+filenames.length);
i++;
}
essentially I want to do the same thing only with a different image process but my code is not doing this to all with in the folder... just one file.
You seem to be confused about what the setup() function does. It runs once, and only once, at the beginning of your code's execution. You don't have any looping structure for processing the other files, so it's no wonder that it only processes the first one. Perhaps wrap the entire thing in a for loop? It looks like you kind of thought about this, judging by the global variable i, but you never increment it to go to the next image and you overwrite its value in several for loops later anyway.

Memory management in window phone 8

My app need to load image from web each time with provided category and it is working, the problem is memory, Image loaded in memory not being remove when next category image load and hence memory increases and the app closing with the following message-
The program '[4036] TaskHost.exe' has exited with code -2005270523 (0x887a0005).
The code is ---
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
{
timer.Stop();
return;
}
List rootobj = JsonConvert.DeserializeObject>(e.Result);
int c = 0, x = 0;
for (int i = 0; i < rootobj.Count; i++)
{
Image img = new Image();
img.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
img.VerticalAlignment = System.Windows.VerticalAlignment.Top;
img.Height = 160;
img.Width = 210;
img.Stretch = System.Windows.Media.Stretch.Fill;
BitmapImage bit = new BitmapImage();
string path = rootobj.ElementAt(i).ThumbnailUrl;
bit.UriSource = new Uri(path,UriKind.RelativeOrAbsolute);
img.Source = bit;
img.Margin = new Thickness(x, y, 0, 0);
c++;
if (c == 2)
{
x = 0;
y = y + 160;
c = 0;
}
else
{
x = x + 210;
}
mainGrid.Children.Add(img);
} mainGrid.Children.Add(grid);
}
and to remove i had tried these--
for (int i = 0; i < rootobj.Count; i++)
{
Image image = (Image)mainGrid.Children.ElementAt(i);
BitmapImage bitmapImage = image.Source as BitmapImage;
bitmapImage.UriSource = null;
image.Source = null;
bitmapImage = null;
image = null;
}
grid.Children.Clear();
mainGrid.Children.Remove(grid);
But it still crashes after few type of image selected.
you can do something like the following :
grid1.Children.Remove(image1);
image1 = null;

Resources