|
|
06-04-2008, 12:04 PM
|
#1
|
Knows Where the Search Button Is
Join Date: Apr 2008
Model: 8800
PIN: N/A
Carrier: IT
Posts: 21
|
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
|
|
06-04-2008, 03:25 PM
|
#2
|
Talking BlackBerry Encyclopedia
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
|
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.
Last edited by richard.puckett; 06-04-2008 at 03:27 PM..
|
Offline
|
|
06-05-2008, 02:00 AM
|
#3
|
Knows Where the Search Button Is
Join Date: Apr 2008
Model: 8800
PIN: N/A
Carrier: IT
Posts: 21
|
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
|
|
06-05-2008, 02:28 AM
|
#4
|
Talking BlackBerry Encyclopedia
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
|
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);
|
Offline
|
|
06-05-2008, 03:19 AM
|
#5
|
Knows Where the Search Button Is
Join Date: Apr 2008
Model: 8800
PIN: N/A
Carrier: IT
Posts: 21
|
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
|
|
06-05-2008, 11:27 AM
|
#6
|
Talking BlackBerry Encyclopedia
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
|
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.
|
Offline
|
|
06-06-2008, 01:38 AM
|
#7
|
Knows Where the Search Button Is
Join Date: Apr 2008
Model: 8800
PIN: N/A
Carrier: IT
Posts: 21
|
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
|
|
08-18-2008, 08:17 PM
|
#8
|
New Member
Join Date: Aug 2008
Model: 8800
PIN: N/A
Carrier: AT&T
Posts: 1
|
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
|
|
01-17-2009, 10:14 PM
|
#9
|
Thumbs Must Hurt
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
|
or this:
Code:
g.drawTexturedPath( xPts, yPts, null, null, 0, 0, Fixed32.ONE, 0, 0, Fixed32.ONE, bmp );
|
Offline
|
|
02-17-2009, 01:05 PM
|
#10
|
New Member
Join Date: Feb 2009
Model: 9530
PIN: N/A
Carrier: Verizon
Posts: 2
|
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
|
|
|
|