graphics

Custom Fonts in Java

ⅰ亾dé卋堺 提交于 2020-01-11 02:26:11
问题 How to fix problem with custom fonts in Java? For example, my app uses font, that isn't on all computers. Can I somehow include it in compiled executable and then call it from there, if it doesn't exists on clients computer? What are other alternatives? I could make all fonts chars as images (before, in some graphics app) and then display image for each char... is it ok? 回答1: Here's an utility method I'm using to load a font file from a .ttf file (can be bundled): private static final Font

Drawing on a transparent image using Java SWT

不羁的心 提交于 2020-01-11 00:06:26
问题 How do I create an in-memory fully transparent SWT image and draw a black line on it with antialias enabled? I expect the result to include only black color and alpha values ranging from 0 to 255 due to antialias... I googled and tried everything that I could... is this possible at all? 回答1: This is how I did and it works: Image src = new Image(null, 16, 16); ImageData imageData = src.getImageData(); imageData.transparentPixel = imageData.getPixel(0, 0); src.dispose(); Image icon = new Image

Can a ThreadStatic IDisposable be automatically disposed?

一个人想着一个人 提交于 2020-01-10 19:53:08
问题 This is not a question of how to automatically call dispose - my problem is the opposite: I have a thread pool where each thread has a ThreadStatic Graphics (which was created from an Image) to perform text size measuring. Now I've ran into the problem that from time to time the graphics seems to be disposed as even reading the TextRenderingHint property fails(causes an ArgumentException). Is there some mechanism which disposes the Graphics e.g. if the thread is idle for a long period? 回答1:

Draw a Fill Rectangle with low opacity

橙三吉。 提交于 2020-01-10 00:41:35
问题 I a have a PictureBox with a picture in a Windows Form application in C# language.I want draw a FillRectangle in some location of picturebox.but i also need to see picture of picture box.how can i draw this rectangle with low opacity to see image of picturebox ? 回答1: Do you mean: using (Graphics g = Graphics.FromImage(pb.Image)) { using(Brush brush = new SolidBrush(your_color)) { g.FillRectangle(brush , x, y, width, height); } } or you can use Brush brush = new SolidBrush(Color.FromArgb(alpha

Best approach for game animation?

只谈情不闲聊 提交于 2020-01-09 19:28:50
问题 I have a course exercise in OpenGL to write a game with simple animation of a few objects While discussing with my partner our design options we've realized we have two major choices for how the animation is going to work, Either Set a timer for a constant interval, say 30 msec, when the timer hits, calculate where objects should be and draw the frame. or - Don't use a timer, just a normal loop that runs all the time and in each iteration check how much time passed, calculate where the

Measuring text height to be drawn on Canvas ( Android )

人盡茶涼 提交于 2020-01-08 13:25:54
问题 Any straight forward way to measure the height of text? The way I am doing it now is by using Paint's measureText() to get the width, then by trial and error finding a value to get an approximate height. I've also been messing around with FontMetrics , but all these seem like approximate methods that suck. I am trying to scale things for different resolutions. I can do it, but I end up with incredibly verbose code with lots of calculations to determine relative sizes. I hate it! There has to

Simplest Code to round corners of JLabel in java [duplicate]

☆樱花仙子☆ 提交于 2020-01-07 08:27:26
问题 This question already has answers here : Border with rounded corners & transparency (3 answers) Closed 5 years ago . I have many JLabel 's and want smooth around corners on them. How can I make this? I already searched on SO but I didn't find any answer. Could someone help me with a simple and exact code for making round corners for JLabel 's? Other questions are asking some extra details like border and others but I want just exact and simplest code for making round corners for JLabel 's.

Java: Image Not Displaying

萝らか妹 提交于 2020-01-07 05:35:05
问题 I am making a program where I need to display an image. I am using the ImageIcon and Image classes in order to do this. I declared the ImageIcon in the constuctor and then assigned the images value through i.getImage(). Everything but the image seems to be loading fine. Here is my code: UPDATE: I have the image in the same directory as the code. I am using a mac and I have tried "image.png", "./image.png", "Users/myStuff/Documents/workspace/Game/src/image.png". Niether of these have worked.

Issues writing PNM P6

我的未来我决定 提交于 2020-01-07 03:26:06
问题 I'm writing a program that takes in two duplicate PNM P6 files, puts the memory of the first file into a buffer, creates a yellow diagonal line over that, and writes the result to the second file. When I run it, the output file is corrupted and can't be displayed. I noticed when looking at the output that it's missing the three lines that should be at the top: P6 1786 1344 255 I don't know how to programmatically ensure that those lines stay in the code -- I can't figure out why they're even

translate coordinates relative to line segment

送分小仙女□ 提交于 2020-01-07 03:22:30
问题 I need to write a function (in Javascript) that accepts the endpoints of a line segment and an additional point and returns coordinates for the point relative to the start point. So, based on this picture: function perpendicular_coords(x1,y1, x2,y2, xp,yp) returns [xp',yp'] where xp' is the distance from (xp,yp) along a line perpendicular to the line segment, and yp' is the distance from (x1,y1) to the point where that perpendicular line intersects the line segment. What I've tried so far: