Google
 
Showing posts with label matrix. Show all posts
Showing posts with label matrix. Show all posts

Saturday, September 03, 2011

Weird behaviour while rotating image in C#

I was working on an image processing code in C#. Had to rotate an image by few degrees around a specified point. This can be done either by transformation or matrix method.

private Bitmap rotateImage(Bitmap b, int x, int y, float angle)
{
//create a new empty bitmap to hold rotated image
Bitmap returnBitmap = new Bitmap(b.Width, b.Height);

//make a graphics object from the empty bitmap
Graphics g = Graphics.FromImage(returnBitmap);

Matrix m = new Matrix();
m.RotateAt((float)angle, new PointF(x,y));

g.Transform = m;
g.DrawImage(b, 0, 0);

return returnBitmap;
}

However this wont work properly. It rotates the image, but strangely enough at the same time scales it down too (on larger images).

After some digging into MSDN, found this page, http://msdn.microsoft.com/en-us/library/1bttkazd.aspx, which says:

GDI+ may automatically scale an image as you draw it, which would decrease performance. Alternatively, you can control the scaling of the image by passing the dimensions of the destination rectangle to the DrawImage method.
So to avoid scaling, the above DrawImage line should be changed to

g.DrawImage(b, 0, 0, b.Width, b.Height);

I have no idea why any function would have "automatic" behaviour. But this is how it works. Weird.

Saturday, July 26, 2008

The day i felt like Neo..

Ok, by Neo i mean The One in the movie 'The Matrix'. If you havent watched this epic movie, i suggest you do. This is one movie you surely dont wanna miss. Well, what happens in this movie is that this hacker aliased Neo lives in a virtual world called 'Matrix' and the people from real world try to contact him by sending messages to his computer.. 'Wake up, Neo. Follow the white rabbit!' [trailer]

Similar kind of message had started to appear my computer since yesterday. I was away from computer n when i came back, there was a libnotification popup message saying 'haha', 'happy birthday.. ' n like that.. i felt like being hacked coz my computer is always connected to internet. More worried than being hacked, i was interested on how it was done.. Read everything from libnotification api to hacking dbus through tcp/ip. I shared this situation to Ankur and Shankar too, and they too were quite puzzled.

But what happened this morning was out of proportion. The message appeared again! I woke up at around 8 in the morning, unlocked the screen to see if there's any new mail. No messages. Then i went to wash my face, and when i returned back, there was this popup message:

"The milk is on the table. Go and get it."

I was clever this time to take the screenshot.


The message..

You can see that the internet is disconnected. Surely, it hasn't come through the network. But lets not go into how it was done, lets focus on the message. I took a look at the other table, there was no milk cup too. But still i was confused about the message. Then i got up, turned around, n WTF, THERE WAS A CUP OF MILK ON THE TABLE NEXT TO THE WINDOW!!!

Are you kiddin me? I had this run over my spine but still i tried to control myself. Okay, "Go and get it." I was still confused. But i went and drank it (without coffee). Was something to happen to me? Well, nothing happened (but i sure had a terrible headache).

Then there were these plethora of questions that ran down my mind. Is 'somebody' 'watching' me? BTW, also look at the fortune cookie quote on the desktop. Does that imply anything? Also note the SETI satellite wallpaper!

The fortune cookie..

I was scared to death for a while and shocked till evening. What the hell happened? Also checked if i have dual-personality thingy too ;) Checked all logs, shell history.. nothing! Also wrote a mail to Shankar and Ankur explaining the situation. Ankur was already busy reading books on Conspiracy theory n what not (he always does :)). The whole thing went over-heated among us.

And finally during dinner i was asking mom n my sis on who touched my computer during morning. Mom def has nothing to do with my computer. And there was my sis, at first was playin cool but later on was goin like 'haha..' She was the one playing all the pranks with me!

Whenever you lock the screen in Linux, there an option to leave a message n i didnt know that.. Seems like she knows more linux functionalities than me.. She was the one behind yesterday's strange messages too..

The whole day i was like, 'OMG, i'm being contacted.. this Matrix thing DOES exist..' haha.. Felt like a total moron later on.. damn! My sis pranked me on my own computer, n i still didnt have a clue about it.. :) But nevertheless, feeling like being a Neo for the whole day was really cool!