w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Draw Text in Middle of the Screen
With your code, the String starts at the very middle. try this: FontMetrics fontMetrics = g.getFontMetrics(font); // draw title g.setColor(Color.WHITE); g.setFont(font); int titleLen = fontMetrics.stringWidth("Level 1 Over!"); g.drawString("Level 1 Over!", (screenWidth / 2) - (titleLen), 80);

Categories : Java

iOS: Mixing Core Graphics draw path and UIKit draw text functions
Save your previous context before drawing your path and restore it afterward: CGContextRef context = UIGraphicsGetCurrentContext(); // save the original context CGContextSaveGState(context); CGContextScaleCTM(context, 1, -1); CGContextTranslateCTM(context, 0, -rect.size.height); // draw path // restore the context CGContextRestoreGState(); // draw text That should do it.

Categories : IOS

Draw image in UIView using CoreGraphics and draw text on it outside drawRect
You're right on the fact that drawing text will make your application faster as there's no UILabel object overhead, but UIImageViews are highly optimized and you won't probably ever be able to draw images faster than this class. Therefore I highly recommend you do use UIImageViews to draw your images. Don't fall in the optimization pitfall: only optimize when you see that your application is not performing at it's max. Once the image is downloaded, just set the imageView's image property to your image and you'll be done.

Categories : IOS

Draw a sprite onto the map not to the screen
batch.draw(splayerSprite, Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2); You are telling the code to draw it to the center of your screen every time. You need to change Gdx.graphics.getWidth() / 2 and Gdx.graphics.getHeight() / 2 to actual values that change based on your input. Edit #2: The line batch.setProjectionmatrix(camera.combined); is needed in addition to everything I have mentioned, I both did not notice that specific line was already in my code (it is included in the default libGDX project), and did not try running my demo with that line removed. I hope that clears up any confusion I may have caused. Edit: Since apparently nobody really liked my answer, I went and wrote a demo using the controls specified in a clean libGDX game. Regardless of where the camera is

Categories : Java

Cannot draw sprite to screen
You need to update or flip the display: while True: player.draw(screen) event = Event() pygame.display.update() Also I recommend you to handle the events at the main loop or at least not in an init method, prehaps you can create the Events object and call a method always in the same object. The order should be: Handle events to update game state Clean background screen.fill() Draw update display Use Clock to keep a fps rate.

Categories : Python

Android draw on the mobile screen
You can use: drawLine(oldX, oldY, x, y, paint); Maybe you also need to check if the user is keeping the finger on screen or if the finger was lifted. For this check: http://developer.android.com/reference/android/view/MotionEvent.html

Categories : Android

C++ Draw a small dot in the center of a screen
Many graphics cards have overlay features, and it is likely possible to set one up to be foremost on the screen regardless of what other applications are rendering in other layers. But the method to do that would be specific to the video card model and driver. Or, you can try to get your code inside the application doing full-screen rendering, find their rendering context, and draw to it at the ideal time. Which still requires a bunch of variants for all the different graphics APIs. Here is someone who describes Steam's attempt to solve the portability issue (with a zillion implementations) and how to take advantage of that.

Categories : C++

How do I draw with the screen coordinates on canvas?
It seems that there are no direct converting methods. We have to convert it manually by the help of maths. We can process the coordinates according to the properties, like translation or scaling or even rotation.

Categories : Android

Looking for the fastest way possible to draw a Cairo context to the screen using C#
I don't know about Cairo specifically, especially since it's the mono variant of it, but when developing a seemingly simple engine to render mesh sets a while back using Helix 3D, a similar WPF-rendering toolkit to Tao, I noticed that when I rendered my samples and small meshes it worked fine, but when I tried to render larger areas at bigger resolutions, the performance was lackluster. I think it all boils down to the fact that these toolkits are perfect for your everyday rendering and small projects, but when you're looking to develop games or something that's supposed to perform well even at high resolutions, the optimisation and tweaking that OpenGL and DirectX have behind them are unmatched, and they will almost always outperform the smaller fish. For me personally when I transfered

Categories : C#

How to draw on just a portion of the screen with SpriteBatch in libgdx?
You're going to want to use the ScissorStack. Effectively, you define a rectangle that you want to draw in. All drawing will be in the rectangle that you defined. Rectangle scissors = new Rectangle(); Rectangle clipBounds = new Rectangle(x,y,w,h); ScissorStack.calculateScissors(camera, spriteBatch.getTransformMatrix(), clipBounds, scissors); ScissorStack.pushScissors(scissors); spriteBatch.draw(...); spriteBatch.flush(); ScissorStack.popScissors(); This will limit rendering to within the bounds of the rectangle "clipBounds". It is also possible push multiple rectangles. Only the pixels of the sprites that are within all of the rectangles will be rendered. From http://code.google.com/p/libgdx/wiki/GraphicsScissors

Categories : Opengl

Add KeyListener and Draw To Screen in All Apps on Android
Fortunately, it is not possible to "somehow add a keylistener to the keyboard at all apps", for blindingly obvious privacy and security reasons. Such things are called keyloggers, and they are primarily the province of malware authors.

Categories : Java

Slick2d, How can i draw a string on screen for a few seconds?
I believe that the best way to do this project would be to draw the scene at regular intervals e.g. 10 milliseconds using a Thread.sleep(). This way, you can simply add a variable to show the message for, say, 100 loops (1 second) like this: private LinkedList<String> drawStringList= new LinkedList<>(); private LinkedList<Integer> drawStringTimeout= new LinkedList<>(); private LinkedList<Integer[]> drawStringPos= new LinkedList<>(); public void addText(String stringToWrite, int posX, int posY, int timeOut) { drawStringList.add(stringToWrite); int[] pos = new int[2]; pos[0] = posX; pos[1] = posY; drawStringPos.add(pos); drawStringTimeout.add(timeOut); } private void mainLoop() { ...items to be drawn here... for(int i=0;i<dr

Categories : Java

Android - draw bitmap on screen on touch event
Never mind. I figured it out myself. I had missed setting an on touch listener to the view. Here's the final code after making changes. public class SurfaceViewTest extends Activity implements OnTouchListener{ FastRenderView renderView; float x, y; Bitmap bob565, bob4444; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); renderView = new FastRenderView(this); renderView.setOnTouchListener(this); setContentView(renderView); } protected void onResume() { super.onResume(); renderView.resume(); } protected

Categories : Android

Draw multiple views of scene on single screen
You just have to draw the scene three times using a different projection matrix (camera object in your case) each time. And in each of those three passes you set a different viewport for your renderings to appear in different parts of the overall framebuffer: glViewport(0, 0, width/3, height); //first column customCam1.begin(); //draw scene customCam1.end(); glViewport(width/3, 0, width/3, height); //second column customCam2.begin(); //draw scene customCam2.end(); glViewport(2*width/3, 0, width/3, height); //third column customCam3.begin(); //draw scene customCam3.end(); But you cannot draw the whole scene using three different projection matrices and three different viewports all in one go. EDIT: For the sake of completeness you can indeed do this with a single pass, using g

Categories : C++

I want to draw a point in screen,but in case i press the 'p',but it can not work
Keep drawing operations to the display function. Do not call OpenGL drawing calls from the event handler. In the event handler set a variable that will make the point draw in the display function, then issue a redraw using glutPostRedisplay.

Categories : Opengl

Quickly draw custom format image on screen
Calling SetPixel 2M times will take a bit of time. I think you'd be better of resizing the image into a bitmap, and then drawing that to the screen. Use for example CreateDIBSection, and then populate that via the ppvBits, and use BitBlit() to draw to the screen itself.

Categories : C++

Linux draw on screen independent of windows manager
Create a regular window. Tell the WM to skip decorations ant to keep the window always on top. Use XFixesSetWindowShapeRegion() to separately set a circular output region and an empty input region. You need a compositing window manager XFixes extensions for this to work. You can also make your window semi-transparent (this needs a compositing window manager). A modern toolkit such as gtk should have easy to use APIs to do all of the above. No OpenGL is needed at any stage.

Categories : C++

In win32 programming, how do I draw a rectangle anywhere on the screen (outside my program)?
I'm interested in hearing if there is a way to do this without cheating... Because as far as I know all of the snipping programs make a copy of your current desktop before it lets you select an area to copy. Check out the snipping tool that comes with Windows. %windir%system32SnippingTool.exe It captures the current desktops to a bitmap, displays them full screen over your current desktops, and then lets you select a portion of the screen to copy. Other programs use similar techniques with fancier code. For example some snipping tools create a full screen transparent window over all of your desktops and then lets you draw the square area on the transparent form; however, the actual image capture is done by removing the transparent window and mapping the form to screen coordinates to capt

Categories : Windows

Draw a dot always at a fixed point on screen, even when the Canvas is zoomed in or out? - Android
Is your app using full-screen? Otherwise, it is not 1280 for the height. But I don't think that is your problem. Based on my understanding, I will change the code to pinOnCanvasX = 336 / mScaleFactor; pinOnCanvasY = 578 / mScaleFactor; which I assume when mScaleFactor == 1, the pin that on Canvas are the same on screen

Categories : Android

in SDL when i draw a menu over the screen it makes the game slower and doesn't work how can i fix this?
One problem is that you are incorrectly initializing the SDL_Rect passed to SDL_BlitSurface. First you are assigning x to drawing.y, you probably meant to assign y to it. SDL_Rect drawing; drawing.x = x; drawing.y = y; There may be other problems but without seeing more code it's hard to tell.

Categories : C++

Android:clipChildren Causes Custom View's Background To Draw Full Height Of Screen
I just ran across the same problem. It was caused by having ColorDrawables as background (a StateListDrawable (<selector>) containing several @color/... items, to be exact). It looks like this was fixed in Android 3.2.4-r1 (commit 95930e1). Before that, the class comment used to say: Note that a ColorDrawable [...] ignores the Bounds, meaning it will draw everywhere in the current clip even if setBounds(...) was called with a smaller area. This was removed, and the draw(Canvas) method changed to respect the bounds. As a workaround, if you need to support older Android versions, you can use a ShapeDrawable with a solid color to get the same behaviour: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" a

Categories : Android

How to draw text using loadStrings(); and text();?
well that's because txt as you set it is an array (that's what loadstrings gives out).. You have to iterate over it and set the text to each one of its elements like this: for(int i = 0; i < txt.length; i++) text(txt[i],1,1); or: for(String s: txt) text(s,1,1);

Categories : String

I need to show an PDF in which text of pdf will auto fit to the screen width and remaining text move to the next line
** Try This** WebSettings settings = mWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setBuiltInZoomControls(true); Use for Zooming Purpose settings.setLoadWithOverviewMode(true); Use for Zooming Purpose settings.setUseWideViewPort(true); Use for Zooming Purpose mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

Categories : Android

How to draw Text with Timer?
Do not call InvalidateRect() or UpdateWindow() from WM_PAINT, or you will create an infinite loop of repaints. Do not paint from the WM_TIMER. It can be done (with GetWindowDC() instead of BeginPaint() but it isn't such a good idea. Instead put the InvalidateRect() in the WM_TIMER and leave the drawing code in WM_PAINT. You can optimize, as @typ1232 said in the comments, by creating the font only once, but that's not strictly necessary. The UpdateWindow() call should not generally be necessary, unless you are in a tight CPU loop and need to show the window just now: if the invalidation is done in a timer and the timeout is not too short you won't need it. But if your timeout is very short you can force the redraw calling UpdateWindow() just after InvalidateRect().

Categories : C++

Draw path above text in svg
I'd probably cut this into 2 different tasks: 1) Text generation and annotation marking: this is actually the harder part since you might have overlaps in your marker. 2) Drawing the annotation: once you have the coordinates of your markers, it's actually rather easy to draw the annotation using css and an svg background. Here's an example to get you started: http://jsfiddle.net/wAq4U/1/. I avoided the hard problem of annotation collision so you'll need to find a way to mark overlapping words. In the example, I used plain html to write the sentence and mark the annotations with a span. Then I used css and javascript to position the annotations on top of each marker. <div class="annotation-segment"> This <span class="marker" data-anno-id="0">is a</span> <span

Categories : Javascript

canvas keep the first text draw?
Looks like the issue is with your clearRect call. Your having it use your ctx.canvas.height value, but thats only set to 100, and your canvas is much bigger than that. ctx.canvas.width = 300; ctx.canvas.height = 100; ... ctx.clearRect(0,0,ctx.canvas.width,ctx.canvas.height); you going to want to use something like var myCanvas= document.getElementById("myCanvasID"); ctx.clearRect(0,0,myCanvas.width,myCanvas.height); or at least for the time being set ctx.canvas.height = 1000;

Categories : Jquery

Draw Text along a path
There is already such a sample on MSDN, which although is C++, you may be able to adapt to C#. From the description: This sample shows how to use Direct2D and DirectWrite to render a string of text along an animated, non-linear geometric path. The app renders "Hello, World!" repeated several times in different languages along a Bezier curve. The font style and size is constant.

Categories : C#

How to draw lines in Rich Text box
I don't know if rtf supports lines. You can use use a string of underscores ("_") maybe. Medicine Amount : 300 Doctor Fees : 0 __________________________ Total Amount : 300 See this SO question, looks like lines can be drawn http://stackoverflow.com/a/8657918/146167 Also, why are you using rtf to print? You can easily print crystal reports or word files for that matter on dot matrix.

Categories : C#

Draw css columned text on HTML5 canvas
It seems this is not a trivial thing to do. I think it may also introduce some security/privacy concerns as well. Regardless, I found this information that seemed to at least be on a track to having some, though not all, rendering capability: Rendering HTML elements to <canvas> I had most success with the "html2canvas" one found here: http://html2canvas.hertzen.com/documentation.html#how-it-works And tried it, which works somewhat well in this fiddle: http://jsfiddle.net/UdESC/1/ External scripts: http://html2canvas.hertzen.com/build/html2canvas.js HTML: <button id="exec">Exec</button> <p>Input:</p> <div id="abc"> <p>This is a test</p> <table> <tbody> <tr> <td>Col1<

Categories : CSS

How Draw Watermark Text Tiles to Fit Image
As I see, you have two problems: Get number of rows and columns of texts Calculate size of one text piece About first problem, it is a bit mathematical. If you have number and you want to split it to rows and columns, you shoud get all divides of this number, than you shoud choose some, multiply them together and it is one dimension. The second dimension is original number divided by this new number. See example: We coud split number 60 to 2 * 2 * 3 * 5 now we choose 2 * 3 = 6 for one dimension the second dimension will be 60 / 6 = 10 our table will be 6 x 10 cells The second problem is solved by function MeasureString(string s, Font f). It is method of instance of Graphics and return size of string written with this font. So the final code will look like this: void DrawTextOnIma

Categories : C#

Draw Rotated Text around it's center with RotateTransform
How to rotate Text in GDI+? works, but you need to rotate the text block on a coordinate plane whose width and height are both equal to the longest dimension of the block of text. The coordinate plane should be centered on the middle of the text box. It doesn't work if your coordinate plane is the background image. Notice I changed the values of PointF: grPhoto.DrawString(m_Copyright, //string of text crFont, //font myBrush, //Brush new PointF(xCenterOfText, yPosFromBottomOfText), //Position StrFormat); //Text alignment Rotating an image is the same thing as rotating a matrix: http://en.wikipedia.org/wiki/Rotation_matrix

Categories : C#

iOS UIView subclass, draw see-through text to background
Disclaimer: I'm writing this without testing, so forgive me if I'm wrong here. You should achieve what you need by these two steps: Create a CATextLayer with the size of your view, set the backgroundColor to be fully transparent and foregroundColor to be opaque (by [UIColor colorWithWhite:0 alpha:1] and [UIColor colorWithWhite:0 alpha:0]. Then set the string property to the string you want to render, font and fontSize etc. Set your view's layer's mask to this layer: myView.layer.mask = textLayer. You'll have to import QuartzCore to access the CALayer of your view. Note that it's possible that I switched between the opaque and transparent color in the first step. Edit: Indeed, Noah was right. To overcome this, I used CoreGraphics with the kCGBlendModeDestinationOut blend mode. First,

Categories : IOS

how to draw text in default marker of google map v2
1.Downlaod the library from github.com/googlemaps/android-maps-utils 2.To use check this link Using android-maps-utils with ADT TextIconGenerator tc = new TextIconGenerator(this); Bitmap bmp = tc.makeIcon("hello"); Then set the bitmap to the map object .icon(BitmapDescriptorFactory.fromBitmap(bmp))); snap shot

Categories : Android

Is it possible to draw text with shadows using the NSString UIKit additions?
The following snippet uses CALayer to add shadow around the edges of the characters in a UILabel: _helloLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 30)]; [_helloLabel setBackgroundColor:[UIColor clearColor]]; [_helloLabel setTextColor:[UIColor whiteColor]]; [_helloLabel setTextAlignment:NSTextAlignmentCenter]; [_helloLabel setFont:[UIFont lightApplicationFontOfSize:30]]; _helloLabel.layer.shadowColor = UIColorFromRGB(0xd04942).CGColor; _helloLabel.layer.shadowOffset = CGSizeMake(0, 0); _helloLabel.layer.shadowRadius = 2.0; _helloLabel.layer.shadowOpacity = 1.0; [self addSubview:_helloLabel]; . . normally this would add a shadow around the border, but UILabel seems to treat these properties as a special case.

Categories : IOS

Draw auto adjustable text infront of bitmap
private TextPaint mTp; private String mText; private final static float TEXT_SIZE = 30; private void drawingSettings() { mTp = new TextPaint(Paint.ANTI_ALIAS_FLAG); mTp.setStyle(Paint.Style.FILL); mTp.setColor(0xFFCCCCCC); mTp.setTextSize(TEXT_HEIGHT); mText = "some text" } @Override public void onDraw(Canvas canvas) { int bmpWidth = mBitmap.getWidth(); int textWidth = mTp.mesureText(mText); float textSize = TEXT_SIZE; while(mTp.mesureText(text)>bmpWidth) { textSize-1; mTp.setTextSize(textSize); } float xPos = 0; float yPos = 0; canvas.drawText(mText,xPos,yPos,mTp); } Note, when optimizing you should consider moving text size calculation outside the onDraw function.

Categories : Android

How to draw a text inside a box on canvas with DynamicLayout and Ellipsize
refer this for automatic ellipsize http://developer.android.com/reference/android/widget/TextView.html#attr_android%3aellipsize

Categories : Android

How to draw text in centre of circle in the max font size possible
You can try to add onGlobalLayoutListener to you button: myButton.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { // Here your button is added to layout and has it's height and width } }); According to it's width you can try to set its font size. myButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, [SIZE]); just note, that size of the button in that listener you will get in pixels, so you need to set text size in pixels too.

Categories : Android

(Closed) C++ & Direct3D 9 - How to draw formatted text? (Like printf etc)
You may use sprintf to format a string into a memory string, and then print it using DrawText Example: (not tested) char formatted_string[100]; sprintf(formatted_string, "Score: %d", score); font->DrawTextA(sprite, formatted_string, -1, scoreR, DT_CALCRECT, 0xFFFFFFFF); Obviously this is just illustrative, as this could be much more polished.

Categories : C++

QPainter drawText() in QGLWidget draw long Chinese text with English upside down
The codes below can solve the upside down problem: void MainWindow::paintEvent(QPaintEvent* event) { qglClearColor(QColor(0,0,0)); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); QPainter painter(this); painter.beginNativePainting(); renderText(-offset, 60, 0, text, QFont("YaHei Consolas Hybrid", 40, 1, false)); painter.endNativePainting(); }

Categories : Qt

php ImageMagick exec -draw text doesn't work as expected - special characters
if you want the quotes drawn as well you need to enclose them in a different set of quotes, double quotes wrapped in single quotes. label:'"fill white stroke none decorate underline text 580,28 Kühle Frische, not working"' As for the special characters try saving your script in unix utf-8 format (editors like Textpad have options for saving files as these when showing the save dialog, similar editors should have the same option). And set the system LANG to use utf LANG=en_US.utf-8; exec("LANG=en_US.utf-8; ".$IM_path."convert -size 800x300 xc:black -font ".$linktottf." -pointsize 16 label:'"fill white stroke none decorate underline text 580,28 Kühle Frische, not working"' output.png"); Looks like you want 'label' and not draw. also it needs to be on one line otherwise it will int

Categories : PHP



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.