draw html from a graphics object - blackberry

i want to display html from a graphics object.
string htmlText = "<html>......</Html>"
i want to know if it is possible to draw html content somehow using the graphics object. I could do it using browserfield, but i do not neeed that.
myGraphicsObject.draw.......... or something here
any help is welcome !

I am suggesting one solution here . I dont know, if it will be helpful for you. Using Graphics object you can create mutable objects. then you can modify that image like anything. i am showing here one example
you can craeate the mutable Bitmap like
Bitmap bmp = new Bitmap(width, height);
Graphics c = new Graphics(bmp);
c.setFont(customFont);
c.setColor(Color.LIMEGREEN);
c.drawRect(5, 5, width-10, height-10);
c.setColor(Color.ROSYBROWN);
c.setFont(customFont);
c.drawText("Some text" , 5, 5);
c.setColor(Color.GREEN);
c.setFont(customFont);
c.drawLine(5, 20, width-10, 20);
like this you can draw different things on that Bitmap uing graphics. I think this will help you.
Feel free to post as useful , if you find it is useful.

Related

AS2 bitmap resizing external image anti-aliasing (Actionscript 2)

I'm using the dreded AS2 (not by choice) and working with images externally loaded.
I know that
targetClip.forceSmoothing = true;
...exists, but it still doesn't seem to be doing much at all.
The images externally loaded are really big in dimensions and when made smaller in the flash, they pixelate.
Perhaps forceSmoothing is the best method but...
I'm thinking there may be a way to resave the external bitmap resized and use that, instead of resizing a bitmap as a vector.
Any ideas?
Also, I've got an AS3 version of this, so if you know how I can do it in that too, then great. But it seems they do not want to use that yet.
in as2:
add this class to your project BitmapLoader
and use like that:
var loader : BitmapLoader = new BitmapLoader(true);
loader.addListener(this);
loader.loadBitmap("http://foo.tr/example.jpg", this, "doneLoading" );
in as3 :
var loader:Loader = new Loader()
loader.load(new URLRequest("1.jpg"))
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,doneLoad);
function doneLoad(e:Event){
var bitmap:Bitmap = e.target.content as Bitmap
bitmap.smoothing = true
}
How are you loading the image data? If you're doing it with the BitmapData class, you can use a matrix together with the scale() command to shrink it.
http://docs.brajeshwar.com/as2/flash/geom/Matrix.html
http://docs.brajeshwar.com/as2/flash/display/BitmapData.html

How to make an in-game button (with text) in Phaser?

I have made a PNG image which will be my button background. In the preload() of my relevant state I load that image. I want a way to have this image placed in the world and be able to set text onto it (and also be clickable but I guess that's a bit unimportant here because I know how to set up event handlers).
I thought I could manage something with
Text text = new Text(x,y,foo,style);
text.texture = <something>
but trying to, for example, create a new Texture() shows a warning "undefined class Texture" in DartEditor, and anyway (as far as I can tell?) Texture doesn't seem to allow giving a source image key/URL..
So could anyone with Phaser experience tell me how I can get an in-game button as I want?
I currently seem to have achieved more or less what I wanted (may have to tweak some values here and there but generally seems alright) with code like this
class MyState
{
preload() {
//...
game.load.image('key','$assetPath/button.png');
//...
}
create() {
Sprite temp2;
temp2 = new Sprite(this.game, x, y, 'button');
BitmapData bmp = game.add.bitmapData(temp2.width, temp2.height);
bmp.draw(temp2);
//Text positioning x,y in fillText() is just my choice of course
bmp.ctx.fillText('Wait', bmp.width / 2, bmp.height / 2);
game.add.sprite(game, someX, someY, bmp);
}
}
EDIT: For what I'm doing there adding the bitmap to game cache wasn't needed; must've been something I was trying when trying to figure it out and forgot to delete.
So I needed to use the BitmapData class. My only little concern with this (although I'm not sure it really is an issue) is how when I create the Sprite temp2 I am giving it a position but of course it is not used in the game, rather the output of drawing the sprite, and then text on top, to bmp is added as a sprite to the game. Does anyone know if there are any real implications of creating that first Sprite and leaving it like so? I'm just wondering because visually it appears it is not an issue since it is not appearing in the "game world".
Also, while this method seems just fine for me at the moment I'm curious as to whether there other ways, like something else that is somehow better and/or more preferred?

Firemonkey drawing on bitmap without interpolation

I am using the canvas draw functions drawrect and filltext to draw onto a Tbitmap but I don't want the results antialiased. Anyone know how to do that ?
Working with OSX and Delphi XE3 (but have XE4 and XE5 if needed)
Is the problem:
the bitmap you create seems to have anti-aliasing present in the data?
or have you got a good bitmap and want to disable anti-aliasing in the viewer/display?
If it is the former, have you checked that the anti-aliasing is actually present in the bitmap, and not introduced by your viewer?
In the past I've found it useful to draw a black-on-white test pattern, and display the image at 1:1 scale. Irfanview is a nice tool for viewing at 'true' scale. Then use a loupe/peak/lens to get a close-up of the actual pixels.
Black-on-white test patterns are particularly good since you should be able to see (hopefully) that the R,G and B sub-pixels are all equally illuminated when there is no anti-aliassing present. If you draw a black-on white pattern and you get solitary bright sub-pixels then you've definitely got anti-aliassing (or some other form of corruption!).
My experience has been that image viewers often do interpolation for you, and it can be tricky to see what is going on unless you look at the actual bitmap data or have a close-up look at the unscaled image...
Hi in the drawBitmap method you need to set HighSpeed parameter to "True", in the sample below:
NewBitmap.Canvas.DrawBitmap(SmallBmp, RectF(0, 0, SmallBmp.Width, SmallBmp.Height), RectF(0, 0, NewBitmap.Width, NewBitmap.Height), 1,**True**);
rgds
Ivan

Good tutorial on using Quads for custom Text in OpenGL ES 2.0 on iOS

I'm currently new to OpenGL ES and am self teaching myself how to program iOS games. I'm currently playing with a project that I would like to put a HUD over with some custom text. I don't want to do this using a UILabel and currently have no idea how to use Quads to cut up a png or such full of text and attach them to normal text to be used for display. I would like the end result to be providing a simple string to a command/method and the output to be displayed using the textures/bitmap for the quad. Say glPrint("Hello World");. Would anyone be able to guide me in the proper direction? There doesn't seem to be a single good tutorial on how to do this for OpenGL ES 2.0 (just OpenGL). I also want to try to avoid using 3rd party APIs. I really need/want to understand how to tackle this.
When I was getting started with OpenGL ES for my current 2D project I used Ray's tutorial, which helped me get a handle on rendering textured 2D quads. In conjunction with his 3D OpenGL ES tutorial, you might be able to piece together what you want to do. Note that you probably wouldn't render every single quad separately like in the tutorial, as that is very inefficient. Instead, you would gather all of the vertices of the characters into two big arrays/vertex buffers and batch render the characters. The basic flow for rendering each frame would probably look like this: pass a normal perspective projection matrix for 3D rendering, get your vertex information for your 3D scene to your shaders somehow, render the 3D scene. This part you've already done. For the text, immediately after, pass an orthogonal projection matrix in, bind your font texture (generally generated earlier with the GLKTextureLoader class) to the active texture unit, generate two big arrays of texture and geometric vertices for the characters/update VBOs if the text has changed, pass that in, and then batch render all of the letters at once using either glDrawArrays or glDrawElements (which requires indices).
Also, as I'm also new at using OpenGL, some of this may be wrong/inefficient. I've yet to use OpenGL ES to render anything 3D, so I'm not sure what other state changes (enabling, disabling, etc) besides a different projection matrix might be needed between rendering your 3D scene and the 2D scene (text).
It seems that drawing text using only OpenGL is a relatively difficult and tedious task, so if you just want to render a HUD overlay displaying frame rates and other things you are much better off using UILabels and saving yourself the trouble, especially if your project is not very complex. This also prevents you from having to deal with wrapping, kerning, font sizes, colors, different languages and a load of other stuff that greatly complicates text rendering if you need anything more complex.
Rather than tracking the location of each letter, why not use Core Graphics to draw your entire string into a bitmap, then upload that as a texture? You'd just need to get the dimensions from your bitmap to know what size quad to draw for that text string.
Within my open source GPUImage framework, I have an input class called a GPUImageUIElement that does something similar. The relevant code from that input is as follows:
CGSize layerPixelSize = [self layerSizeInPixels];
GLubyte *imageData = (GLubyte *) calloc(1, (int)layerPixelSize.width * (int)layerPixelSize.height * 4);
CGColorSpaceRef genericRGBColorspace = CGColorSpaceCreateDeviceRGB();
CGContextRef imageContext = CGBitmapContextCreate(imageData, (int)layerPixelSize.width, (int)layerPixelSize.height, 8, (int)layerPixelSize.width * 4, genericRGBColorspace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
CGContextTranslateCTM(imageContext, 0.0f, layerPixelSize.height);
CGContextScaleCTM(imageContext, layer.contentsScale, -layer.contentsScale);
[layer renderInContext:imageContext];
CGContextRelease(imageContext);
CGColorSpaceRelease(genericRGBColorspace);
glBindTexture(GL_TEXTURE_2D, outputTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (int)layerPixelSize.width, (int)layerPixelSize.height, 0, GL_BGRA, GL_UNSIGNED_BYTE, imageData);
free(imageData);
This code takes a CALayer (either directly or from the backing layer of a UIView) and renders its contents to a texture. I've already initialized the texture before this, so the code sets up a bitmap context, renders the layer into that context using -renderInContext:, and then uploads that bitmap to the texture for use in OpenGL ES.
The helper method -layerSizeInPixels just accounts for the current Retina scale factor as follows:
- (CGSize)layerSizeInPixels;
{
CGSize pointSize = layer.bounds.size;
return CGSizeMake(layer.contentsScale * pointSize.width, layer.contentsScale * pointSize.height);
}
If you used a UILabel for your view and had it autosize to fit its text, you could set the text on it, use the above to render and upload your texture, and then take the pixel size of the element to determine your quad size. However, it would probably be more efficient to just draw the text yourself using -drawAtPoint:withFont:fontForSize: or the like with an NSString.
Using Core Graphics to render your text makes it easy to manipulate the text as an NSString and use all of Core Graphics' typesetting capabilities instead of rolling your own.

How to scale a texture and save the result in another in XNA

I'm new to XNA. What I want is just to scale a texture (double its size for example) and save the bigger one in another texture object of type Texture2D..
Any Ideas?
thanks..
Note::
I know how to view a texture in a different scale,, take this piece of code:
CountryTexturData = new Color[CountryTextur.Width * CountryTextur.Height];
CountryTextur.GetData(CountryTexturData);
I want to make a process on the pixels of the country, but not the original one (CountryTextur), I want the scaled one, to save its pixels data in an array, like CountryTextureData, then make a simple process..
SpriteBatch.Draw only can view it scaled,, hopefully I could explain the problem..
You can use RenderTargets to achieve what you want to do:
graphicsDevice.SetRenderTarget(scaledCountryTextur);
spriteBatch.Begin();
//Draw your scaled CountryTextur
spriteBatch.End();
graphicsDevice.SetRenderTarget(null);
//You can now use scaledCountryTextur as an enlarged Texture2D of CountryTextur
What this will do is it will 'draw' your ContryTexture in a RenderTarget, which can be used like a regular Texture2D.
Hope this helps!

Resources