Re: [android-developers] Drawing text on a Bitmap (rather than Canvas)

2010-12-28 Thread zeinab odat
hi, I am new member and I am very happy to be.
zeinab

On Sat, Dec 25, 2010 at 5:51 PM, Kostya Vasilyev kmans...@gmail.com wrote:

 I just tried drawing text to an off-screen bitmap, and it's absolutely
 perfect:

 http://xmages.net/storage/10/1/0/d/0/upload/6fe914a9.png

 In this screenshot, each WiFi router's SSID is drawn twice, top to bottom -
 first directly to the canvas given to onDraw(), then with an off-screen
 bitmap. This on a Motorola Milestone 2.1u1, not that it should make any
 difference.

 The code is like this:


 // * this is direct
 canvas.drawText(i.ssid, si.xPos, si.yPos - netNameDiff / 2.0f, paintNet);

 // * this is with an off-screen bitmap
 int offWidth = 200;
 int offHeight = 30;
 Bitmap.Config offConfig = Bitmap.Config.ARGB_;
 Bitmap offBitmap = Bitmap.createBitmap(offWidth, offHeight, offConfig);
 Canvas offCanvas = new Canvas(offBitmap);

 offCanvas.drawText(i.ssid, 5, 25, paintNet);

 canvas.drawBitmap(offBitmap, si.xPos, si.yPos + 20, null);


 Did you set:

 paint.setFlags(Paint.ANTI_ALIAS_FLAG);

 in the font paint?

 -- Kostya

 25.12.2010 18:17, MichaelF пишет:

 Thanks for your response, Kostya. No, the roughness is not only due to
 magnification, as the text appears rough even when drawn, unmodified, to the
 bitmap. Any idea on how to remedy that?
 Best,
 Michael
 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en



 --
 Kostya Vasilyev -- WiFi Manager + pretty widget --
 http://kmansoft.wordpress.com

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Drawing text on a Bitmap (rather than Canvas)

2010-12-26 Thread Kostya Vasilyev

Michael,

I just tied changing my code so it's exactly like what you posted, 
including the color scheme and how the Paint (font) object is 
constructed. Perfect again.


Is your application perhaps running in 320x480 compatibility mode? That 
would explain what you're seeing.


Make sure that you build with at least Android 1.6, and that in the 
manifest, you have either:


uses-sdk android:minSdkVersion=4 /

or

supports-screens
android:smallScreens=true
android:normalScreens=true
android:largeScreens=true
android:anyDensity=true /

These go inside the top-level manifest tag, *not* inside application

-- Kostya

26.12.2010 5:40, MichaelF пишет:
Kostya, thanks for your time. This is strange... I've literally pasted 
your code into my view, and the problem persists (same results for 
ARGB_ and ARGB_ configs). Here is a full working code: 
http://pastebin.com/damgWgXF, and here is the result: 
http://i.imgur.com/C2wdk.png. Am I missing something in my Paint? 
Could you check what this code gives you, or send me the full working 
code from your example?

Best, Michael
--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en 



--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Drawing text on a Bitmap (rather than Canvas)

2010-12-26 Thread MichaelF
Kostya, that's very well spotted: the uses-sdk android:minSdkVersion=4 
/ tag does the thing (for some reason I neglected it). The alternative 
supports-screens 
... / does it as well.

Cheers, and thanks again,

Michael

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Drawing text on a Bitmap (rather than Canvas)

2010-12-26 Thread Kostya Vasilyev

26.12.2010 14:32, MichaelF ?:
Kostya, that's very well spotted: the uses-sdk 
android:minSdkVersion=4 / tag does the thing (for some reason I 
neglected it). The alternative supports-screens ... / does it as well.




Ok, cool. I should have thought of this sooner.


Cheers, and thanks again,


You are welcome.

-- Kostya


Michael
--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en 



--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Drawing text on a Bitmap (rather than Canvas)

2010-12-25 Thread MichaelF


Hi,

I am drawing some text on a Canvas, and on a Bitmap, respectively:

protected void onDraw(Canvas canvas) {
canvas.drawText(Canvas text, 10, 10, mPaint);
Canvas singleUseCanvas = new Canvas();
singleUseCanvas.setBitmap(mBitmap);
singleUseCanvas.drawText(Bitmap text, 10, 30, mPaint);
}

In the former case, the text renders as you would expect, while in the 
latter, it appears very rough and ugly. This becomes even more problematic 
when using e.g.

canvas.drawBitmapMesh(...);

to apply transformations to the bitmap. Am I doing something wrong, or is 
the quality simply deteriorated when you pass from Canvas to Bitmap?

On a side note, the reason why I'm drawing text on a Bitmap is to obtain a 
magnifier effect on the text in question (like Apple OSX's dock), since I 
can then apply arbitrary transformations to it using a bitmap mesh. Is there 
another, perhaps better, way to do this?

Best,

Michael

(Also posted 
here: 
http://stackoverflow.com/questions/4485587/drawing-text-on-a-bitmap-rather-than-canvas,
 
but with no answer)

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Drawing text on a Bitmap (rather than Canvas)

2010-12-25 Thread Kostya Vasilyev


Since you mention magnification, and it looks like you are using the 
same mPaint object for both drawText calls, I guess you scale up the 
contents of singleUseCanvas to achive that. That's the reason for the 
roughness of text.


Make sure you render text into singleUseCanvas at magnified size, so no 
further scaling is necessary (when drawing mBitmap to the screen).


Also try setting mPaint.setAntiAlias(true)

-- Kostya

25.12.2010 15:37, MichaelF ?:


Hi,

I am drawing some text on a Canvas, and on a Bitmap, respectively:

|protected  void  onDraw(Canvas  canvas)  {
 canvas.drawText(Canvas text,  10,  10,  mPaint);
 Canvas  singleUseCanvas=  new  Canvas();
 singleUseCanvas.setBitmap(mBitmap);
 singleUseCanvas.drawText(Bitmap text,  10,  30,  mPaint);
}
|

In the former case, the text renders as you would expect, while in the 
latter, it appears very rough and ugly. This becomes even more 
problematic when using e.g.


|canvas.drawBitmapMesh(...);
|

to apply transformations to the bitmap. Am I doing something wrong, or 
is the quality simply deteriorated when you pass from Canvas to Bitmap?


On a side note, the reason why I'm drawing text on a Bitmap is to 
obtain a magnifier effect on the text in question (like Apple OSX's 
dock), since I can then apply arbitrary transformations to it using a 
bitmap mesh. Is there another, perhaps better, way to do this?


Best,

Michael

(Also posted 
here: http://stackoverflow.com/questions/4485587/drawing-text-on-a-bitmap-rather-than-canvas, 
but with no answer)


--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en 



--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Drawing text on a Bitmap (rather than Canvas)

2010-12-25 Thread MichaelF
Thanks for your response, Kostya. No, the roughness is not only due to 
magnification, as the text appears rough even when drawn, unmodified, to the 
bitmap. Any idea on how to remedy that?
Best,
Michael

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Drawing text on a Bitmap (rather than Canvas)

2010-12-25 Thread Kostya Vasilyev
I just tried drawing text to an off-screen bitmap, and it's absolutely 
perfect:


http://xmages.net/storage/10/1/0/d/0/upload/6fe914a9.png

In this screenshot, each WiFi router's SSID is drawn twice, top to 
bottom - first directly to the canvas given to onDraw(), then with an 
off-screen bitmap. This on a Motorola Milestone 2.1u1, not that it 
should make any difference.


The code is like this:


// * this is direct
canvas.drawText(i.ssid, si.xPos, si.yPos - netNameDiff / 2.0f, paintNet);

// * this is with an off-screen bitmap
int offWidth = 200;
int offHeight = 30;
Bitmap.Config offConfig = Bitmap.Config.ARGB_;
Bitmap offBitmap = Bitmap.createBitmap(offWidth, offHeight, offConfig);
Canvas offCanvas = new Canvas(offBitmap);

offCanvas.drawText(i.ssid, 5, 25, paintNet);

canvas.drawBitmap(offBitmap, si.xPos, si.yPos + 20, null);


Did you set:

paint.setFlags(Paint.ANTI_ALIAS_FLAG);

in the font paint?

-- Kostya

25.12.2010 18:17, MichaelF пишет:
Thanks for your response, Kostya. No, the roughness is not only due to 
magnification, as the text appears rough even when drawn, unmodified, 
to the bitmap. Any idea on how to remedy that?

Best,
Michael
--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en 



--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Drawing text on a Bitmap (rather than Canvas)

2010-12-25 Thread MichaelF
Hi again,
I see. Indeed, drawBitmap produces very good results (although I can see a 
slight difference on my N1). The mess seems to be caused by drawBitmapMesh 
(even with the mesh vertices unchanged from the original ones). The result 
is as follows: http://i.imgur.com/pCqGT.png. And yes I am using the 
anti-alias flag.
Michael

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Drawing text on a Bitmap (rather than Canvas)

2010-12-25 Thread MichaelF
Hi again,
I see. Indeed, drawBitmap produces very good results (although I can see a 
difference on my N1 when using a very large font size). The mess seems to be 
caused by drawBitmapMesh (even with the mesh vertices unchanged from the 
original ones). The result is as follows: http://i.imgur.com/pCqGT.png. And 
yes I am using the anti-alias flag.
Michael

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Drawing text on a Bitmap (rather than Canvas)

2010-12-25 Thread Kostya Vasilyev

Michael,

Interesting. I actually got curious about this.

I added a call to drawBitmapMesh, stretching the first column (out of 
4), and mapping the rest one to one.


As you can see in this link, the bitmap is still perfect where it's not 
stretched.


http://xmages.net/storage/10/1/0/a/1/upload/fe1ce910.png

Stretching is another matter, and it would be a good idea to pick a font 
size for the off-screen bitmap so that drawBitmapMesh only shrinks, 
never enlarges, any bitmap area.


The small difference you are seeing (I am seeing it too in the link 
above) is due to my using ARGB_ for the offscreen bitmap. I just 
verified that ARGB_ gives exact match (as it should).


However, you're seeing distortion even when there is no mapping.

So, for your reference, I pasted my code here (really simple, really):

http://pastebin.com/5e1C5irq

Hope you can spot a difference somewhere.

-- Kostya

25.12.2010 22:52, MichaelF ?:

Hi again,
I see. Indeed, drawBitmap produces very good results (although I can 
see a difference on my N1 when using a very large font size). The mess 
seems to be caused by drawBitmapMesh (even with the mesh vertices 
unchanged from the original ones). The result is as follows: 
http://i.imgur.com/pCqGT.png http://i.imgur.com/pCqGT.png. And yes I 
am using the anti-alias flag.

Michael
--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en 



--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Drawing text on a Bitmap (rather than Canvas)

2010-12-25 Thread MichaelF
Kostya, thanks for your time. This is strange... I've literally pasted your 
code into my view, and the problem persists (same results for ARGB_ and 
ARGB_ configs). Here is a full working code: 
http://pastebin.com/damgWgXF, and here is the result: 
http://i.imgur.com/C2wdk.png. Am I missing something in my Paint? Could you 
check what this code gives you, or send me the full working code from your 
example?
Best, Michael

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Drawing text on a Bitmap (rather than Canvas)

2010-12-23 Thread MichaelF
(Cross-posted from StackOverflow:
http://stackoverflow.com/questions/4485587/drawing-text-on-a-bitmap-rather-than-canvas)

Hi,

I am drawing some text on a Canvas, and on a Bitmap, respectively:

protected void onDraw(Canvas canvas) {
canvas.drawText(Canvas text, 10, 10, mPaint);
Canvas singleUseCanvas = new Canvas();
singleUseCanvas.setBitmap(mBitmap);
singleUseCanvas.drawText(Bitmap text, 10, 30, mPaint);
}

In the former case, the text renders as you would expect, while in the
latter, it appears very rough and ugly. This becomes even more
problematic when using e.g.

canvas.drawBitmapMesh(...);

to apply transformations to the bitmap. Am I doing something wrong, or
is the quality simply deteriorated when you pass from Canvas to
Bitmap?

On a side note, the reason why I'm drawing text on a Bitmap is to
obtain a magnifier effect on the text in question (like Apple OSX's
dock), since I can then apply arbitrary transformations to it using a
bitmap mesh. Is there another, perhaps better, way to do this?

Best,

Michael

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en