Resize PNG image

The original author of the PNGImage component (the basis of the Delphi native component) had a forum where he, and others, posted code snippets on how to do things using the PNGImage component. Before the forum was taken down I grabbed a copy of all of the code snippets and placed them on the CodeGear … Read more

How can I add transparency to a c# form while keeping controls visible?

This is pretty easy to do in Winforms. What you need is a sandwich of two forms. The bottom one should provide the transparent gradient background, the top one should draw the icons and handle mouse clicks. Some sample code: public partial class Form1 : Form { public Form1() { InitializeComponent(); this.TopMost = true; this.FormBorderStyle … Read more

Creating a draw rectangle (filled with black color) function in Java for a grid

Don’t use paint, use paintComponent and don’t forget to call super.paintComponent JComponent may not be the best choice, JPanel is probably a better choice What’s wrong with Graphics#fillRect(int, int, int, int)? You might to take a look at Performing Custom Painting and 2D Graphics for more details. I’d advice against trying to have a second … Read more

What’s the usual way of controlling frame rate?

There are two “usual” ways of “controlling” framerate, and neither is quite that simple. The first and more controlling of the two, and something that is usually optional, is VSync. This forces the video card to only push out a new frame when the monitor is done refreshing. Many monitors refresh at 60 Hz, so … Read more

How to rotate image x degrees in c#?

If I’ve understood your question correctly, you essentially want to work out the new size of an image once rotated, and how to position the rotated image in it’s new bitmap. The diagram hopefully helps make clear the solution. Here is a bit of pseudo code: sinVal = abs(sin(angle)) cosVal = abs(cos(angle)) newImgWidth = sinVal … Read more

Drawing in Java using Canvas

Suggestions: Don’t use Canvas as you shouldn’t mix AWT with Swing components unnecessarily. Instead use a JPanel or JComponent. Don’t get your Graphics object by calling getGraphics() on a component as the Graphics object obtained will be transient. Draw in the JPanel’s paintComponent() method. All this is well explained in several tutorials that are easily … Read more