BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 06-04-2008, 12:04 PM   #1
Happe79
Knows Where the Search Button Is
 
Join Date: Apr 2008
Model: 8800
PIN: N/A
Carrier: IT
Posts: 21
Default Graphics.drawTexturedPath

Please Login to Remove!

Has anyone every used the Graphics.drawTexturedPath(...) - method. If my understanding is right, I can use this method in order to draw rotated images.
Therefore I defined four corner points, for the first time defined like a non-rotated rectangle.

But it currently draws nothing.

Does anyone know how to set the dux,dvx,duy,dvy parameters. What I am doing wrong?
Maybe sample code available?

Thx a lot in advance.

Happe
Offline  
Old 06-04-2008, 03:25 PM   #2
richard.puckett
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Default

It can be a little tricky - there's a couple moving pieces.

dux/dvx mean: For each pixel that gets drawn to the screen, what offset (from the screen coords) into the bitmap should be used to grab a source pixel? Same with duy/dvy.

For dux/dvx we're performing this query for each 'x' value on the screen; for duy/dvy we're doing this for each 'y' value on the screen.

'u' and 'v' are just different names for 'x' and 'y' in the bitmap.

To draw an "identity" bitmap (no transform) you'd specify:
dux: 1
dvx: 0
duy: 0
dvy: 1

(For each screen x, walk 1 x and 0 y into the bitmap; for each screen y, walk 0 x and 1 y into the bitmap. This just walks the bitmap in exactly the same pattern as the screen.)

Make sure these are specified in fixed-point, as according to the docs! For example, Fixed32.toInt(1). Fixed32 is 16.16 but the sign bit is ignored.

If you want to make an image half as big you'd increase the magnitudes from 1 to 2. What that'll do is grab every second pixel in the source bitmap for each pixel on the screen, thereby reducing the size by 50%.

Skewing is accomplished by specifying something like (1, 1, 0, 1). As the screen is drawn, the y values will map to the identity, but the x values will "walk" up the source bitmap at a 45 degree angle. If you want a certain angle then just use trig to determine the lengths of your vectors (eg: dvx=1.7 for a 60 degree angle).

This is all assuming you've got your paths set up correctly as well. Also note that the source bitmap will be tiled so it might not be the best option for certain kinds image manipulation.
__________________
Do your homework and know how to ask a good question.

Last edited by richard.puckett; 06-04-2008 at 03:27 PM..
Offline  
Old 06-05-2008, 02:00 AM   #3
Happe79
Knows Where the Search Button Is
 
Join Date: Apr 2008
Model: 8800
PIN: N/A
Carrier: IT
Posts: 21
Default

Thx a lot for your anwser, richard.puckett.

I think this is the way I used to draw an image using the Graphics.drawTexturedPath(...) - method. However without success yet.

My code (for the first trial) is the following:

Code:
Bitmap logo  = Bitmap.getBitmapResource( "logo.png" );

.
.
.

// just drawing the image like Graphics.DrawImage(...);

public void drawBitmap(final Bitmap bmp)
{	
		int width = bmp.getWidth();
		int height = bmp.getHeight();
		
		xPts[0] = 0;
		xPts[1] = 0;
		xPts[2] = width;
		xPts[3] = width;
		
		yPts[0] = 0;
		yPts[1] = height;
		yPts[2] = height;
		yPts[3] = 0;
		
		this.graphics.drawTexturedPath(xPts, yPts, null, null,  0, 0, Fixed32.toInt(1), Fixed32.toInt(0), Fixed32.toInt(0), Fixed32.toInt(1), bmp);
}
But it still draws a white area.

What could be wrong, do you maybe see a mistake I made?
What exactly is an "non-null Bitmap", does it mean the bitmap pointer must not null (bmp != null). I could not find information about that.

The image I used is usual png-image (145x99 pixel).

Happe
Offline  
Old 06-05-2008, 02:28 AM   #4
richard.puckett
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Default

At first glance (assuming your bitmap is being loaded successfully), you're providing null for the third argument (control point types). Try something like:

Code:
byte[] types = new byte[] { 
    Graphics.CURVEDPATH_END_POINT,
    Graphics.CURVEDPATH_END_POINT,
    Graphics.CURVEDPATH_END_POINT,
    Graphics.CURVEDPATH_END_POINT };
and then

this.graphics.drawTexturedPath(xPts, yPts, types, null, 0, 0, Fixed32.toInt(1), Fixed32.toInt(0), Fixed32.toInt(0), Fixed32.toInt(1), bmp);
__________________
Do your homework and know how to ask a good question.
Offline  
Old 06-05-2008, 03:19 AM   #5
Happe79
Knows Where the Search Button Is
 
Join Date: Apr 2008
Model: 8800
PIN: N/A
Carrier: IT
Posts: 21
Default

I tried your code, without success.

But I did some tests with the image, so I changed the color of the image to e.g. red than it draws the rectangle complete in red. I think there is still a mistake with texture vectors.

Happe
Offline  
Old 06-05-2008, 11:27 AM   #6
richard.puckett
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Default

Hm, so did you end up getting it to work? There *are* easier ways to draw a bitmap, BTW, if that's all you want to do.

I don't see anything wrong with your code right now (well, you're using straight "width" and "height" for your x/y coords - you should subtract one from those values since your coords are zero-based). If you're still having problems I'll post a complete example. Told ya it was tricky.
__________________
Do your homework and know how to ask a good question.
Offline  
Old 06-06-2008, 01:38 AM   #7
Happe79
Knows Where the Search Button Is
 
Join Date: Apr 2008
Model: 8800
PIN: N/A
Carrier: IT
Posts: 21
Default

I did not get it to work yet.

The background of this work is, that I want to extend/use the Graphics object to allow tranformations of simple drawing objects (rotation, translation and scaling of rectangle, circle etc. and images) like it works for openGL or DirectX.

It is currently just a testing phase, but I hope I can use it later for improving the desgin of the screen or maybe to make transitions when the screen changes (depends on the cpu power of the handheld).

THX for your help.

Happe

Last edited by Happe79; 06-06-2008 at 02:21 AM..
Offline  
Old 08-18-2008, 08:17 PM   #8
Akranar
New Member
 
Join Date: Aug 2008
Model: 8800
PIN: N/A
Carrier: AT&T
Posts: 1
Default

The problem is that you're converting to the wrong type for the d-values:

graphics.drawTexturedPath(xPts, yPts, null, null, 0, 0, Fixed32.toInt(1), Fixed32.toInt(0), Fixed32.toInt(0), Fixed32.toInt(1), bmp);

You're converting the values to normal ints even though they're already normal ints. However drawTexturedPath wants Fixed32 ints. Use this instead and it should work:

graphics.drawTexturedPath(xPts, yPts, null, null, 0, 0, Fixed32.toFP(1), Fixed32.toFP(0), Fixed32.toFP(0), Fixed32.toFP(1), bmp);
Offline  
Old 01-17-2009, 10:14 PM   #9
CELITE
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Default

or this:

Code:
g.drawTexturedPath( xPts, yPts, null, null, 0, 0, Fixed32.ONE, 0, 0, Fixed32.ONE, bmp );
Offline  
Old 02-17-2009, 01:05 PM   #10
Zeeshan0581
New Member
 
Join Date: Feb 2009
Model: 9530
PIN: N/A
Carrier: Verizon
Posts: 2
Default

Is it possible to use this method to get different angle, lets say 15' or 120' angle rotation?? I tried but not having much luck.
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


New In Box JOHNSON CONTROLS F61KB-11C Water Flow Switch picture

New In Box JOHNSON CONTROLS F61KB-11C Water Flow Switch

$49.50



JOHNSON CONTROLS MODP20GA-26 PRESSURE SWITCH 400psi High Limit Sealed New picture

JOHNSON CONTROLS MODP20GA-26 PRESSURE SWITCH 400psi High Limit Sealed New

$44.10



Johnson Controls MS-FEC1621-0 Programmable Controller - FEC 1621 - Metasys 1611 picture

Johnson Controls MS-FEC1621-0 Programmable Controller - FEC 1621 - Metasys 1611

$79.99



digital controller Johnson Controls A419 Digital Controller picture

digital controller Johnson Controls A419 Digital Controller

$29.00



Johnson controls Map-1810 picture

Johnson controls Map-1810

$525.00



JOHNSON CONTROLS 2951J PHOTOELECTRIC SMOKE DETECTOR USA STOCK picture

JOHNSON CONTROLS 2951J PHOTOELECTRIC SMOKE DETECTOR USA STOCK

$34.97







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.