Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Convert a view (layout) to a Bitmap
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  16 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jose Cortes  
View profile  
 More options Nov 17 2008, 5:34 am
From: Jose Cortes <jbeerb...@gmail.com>
Date: Mon, 17 Nov 2008 02:34:07 -0800 (PST)
Local: Mon, Nov 17 2008 5:34 am
Subject: Convert a view (layout) to a Bitmap
Hello everybody.

I am working with OpenGL and Android, and I was wondering if there is
any way to create a Bitmap or a Drawable using a view (layout). The
purpose is to use this Bitmap as Texture for an OpenGL figure.

All I have untill now is:

** I create a new view from the context and the Id.

View l = new View(context);

l.findViewById(R.layout.main);

** I used DrawingCache...but dont know if it is well used:

l.setDrawingCacheEnabled(true);

Bitmap bmp = l.getDrawingCache();

this bmp is null...

Any idea?

Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Romain Guy  
View profile  
 More options Nov 17 2008, 11:20 am
From: Romain Guy <romain...@google.com>
Date: Mon, 17 Nov 2008 08:20:41 -0800
Local: Mon, Nov 17 2008 11:20 am
Subject: Re: [android-developers] Convert a view (layout) to a Bitmap
Hi,

If you do this in onCreate(), then the View didn't go through a layout
pass yet, so its size is null (0 by 0 pixels.) You need to either wait
for the first layout, or force the layout by calling layout() on the
View.

--
Romain Guy
www.curious-creature.org

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Justin Buser  
View profile  
 More options Nov 17 2012, 3:18 pm
From: Justin Buser <justin.bu...@gmail.com>
Date: Sat, 17 Nov 2012 12:18:27 -0800 (PST)
Local: Sat, Nov 17 2012 3:18 pm
Subject: Re: [android-developers] Convert a view (layout) to a Bitmap

I don't understand why I keep finding different posts by you
about forcing  layout passes.  The View instance this person is referring
would never go through a layout pass, regardless of the point at which his
code was executed for several reasons, most notably because it's never even
added to the display list. Additionally, even if it *was* added to the
Window correctly, calling layout() would not "force the layout", you would
call forceLayout() for that but even that would be pointless because the
View doesn't have a layout assigned to it or even have anything to layout
in the first place.

The truly aggravating thing however is the fact that neither the question
itself, nor the *actual* answer ever have anything to do with "forcing
layouts". Do you understand that when other people come across
invalid/irrelevant information like this and believe it (if not because you
claim to be a developer then simply because they don't know any better)
then it's no longer a forgivable case of simply being wrong about
something. At that point you are responsible for every adverse reaction
your bad information results in. Every application crash/exception
thrown/hour lost/dead kitten/etc... that occurs when someone tries your
solution and it doesn't work is on your head.

As a human being you should feel morally obligated to not present anything
as fact unless you are 100% confident that it is indeed so. At the very
least you should have first hand experience as it pertains to the
information you are providing and if not then test / verify it before hand.
Although each individual  failure in this may seem relatively
insignificant, the aggregate result will ultimately have a negative impact
on our evolutionary progress as a species. As far fetched as you may find
this to be the vast multitude of problems that threaten our very existence
are at some level caused by ignorance, as such it should not be taken
lightly at *any* level.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Piren  
View profile  
 More options Nov 18 2012, 3:13 am
From: Piren <gpi...@gmail.com>
Date: Sun, 18 Nov 2012 00:13:33 -0800 (PST)
Local: Sun, Nov 18 2012 3:13 am
Subject: Re: [android-developers] Convert a view (layout) to a Bitmap

Holy fuck dude... you should really google his name...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Streets Of Boston  
View profile  
 More options Nov 19 2012, 10:43 am
From: Streets Of Boston <flyingdutc...@gmail.com>
Date: Mon, 19 Nov 2012 07:43:04 -0800 (PST)
Local: Mon, Nov 19 2012 10:43 am
Subject: Re: Convert a view (layout) to a Bitmap

I'm not sure if this will work in your situation, but try
calling setWillNotCacheDrawing this on the View 'l' as well:

boolean drawsCache = l.willNotCacheDrawing();
l.setWillNotCacheDrawing(false);
Bitmap dragPicture = Bitmap.createBitmap(l.getDrawingCache());
l.setWillNotCacheDrawing(drawsCache);


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Streets Of Boston  
View profile  
 More options Nov 19 2012, 10:46 am
From: Streets Of Boston <flyingdutc...@gmail.com>
Date: Mon, 19 Nov 2012 07:46:00 -0800 (PST)
Subject: Re: [android-developers] Convert a view (layout) to a Bitmap

Hi Justin,

While I do agree that people should not post/answer just anything that they
have no clue about, you may want to put your foot into your mouth when you
realize who Romain is.... :-)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Black  
View profile  
 More options Nov 18 2012, 7:19 am
From: James Black <planiturth...@gmail.com>
Date: Sun, 18 Nov 2012 07:19:37 -0500
Local: Sun, Nov 18 2012 7:19 am
Subject: Re: [android-developers] Convert a view (layout) to a Bitmap

People deserve respect when not being nice, but if you want to attack Guy I
would suggest you watch him on YouTube and as mentioned, Google him.

He helps answer questions to share from his depth of knowledge, so if you
factually disagree be to the point and show where he erred, without the
attacks.
On Nov 17, 2012 3:19 PM, "Justin Buser" <justin.bu...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Justin Buser  
View profile  
 More options Jan 6, 7:21 am
From: "Justin Buser" <justin.bu...@gmail.com>
Date: Sun, 6 Jan 2013 07:21:11 -0500
Local: Sun, Jan 6 2013 7:21 am
Subject: RE: [android-developers] Convert a view (layout) to a Bitmap

I agree that people deserve respect, however I don't feel that my response
was disrespectful. If I was curt it was only because I felt that the
situation warranted it. Furthermore, I clearly and succinctly explained
exactly why his response was incorrect and misleading as well as why I found
his answer so frustrating so I'm not really sure how to respond to this.
Scolding me for scolding someone seems kind of hypocritical, especially when
you have no point.

From: android-developers@googlegroups.com
[mailto:android-developers@googlegroups.com] On Behalf Of James Black
Sent: Sunday, November 18, 2012 7:20 AM
To: android-developers@googlegroups.com
Subject: Re: [android-developers] Convert a view (layout) to a Bitmap

People deserve respect when not being nice, but if you want to attack Guy I
would suggest you watch him on YouTube and as mentioned, Google him.

He helps answer questions to share from his depth of knowledge, so if you
factually disagree be to the point and show where he erred, without the
attacks.

On Nov 17, 2012 3:19 PM, "Justin Buser" <justin.bu...@gmail.com> wrote:

I don't understand why I keep finding different posts by you about forcing
layout passes.  The View instance this person is referring would never go
through a layout pass, regardless of the point at which his code was
executed for several reasons, most notably because it's never even added to
the display list. Additionally, even if it was added to the Window
correctly, calling layout() would not "force the layout", you would call
forceLayout() for that but even that would be pointless because the View
doesn't have a layout assigned to it or even have anything to layout in the
first place.

The truly aggravating thing however is the fact that neither the question
itself, nor the actual answer ever have anything to do with "forcing
layouts". Do you understand that when other people come across
invalid/irrelevant information like this and believe it (if not because you
claim to be a developer then simply because they don't know any better) then
it's no longer a forgivable case of simply being wrong about something. At
that point you are responsible for every adverse reaction your bad
information results in. Every application crash/exception thrown/hour
lost/dead kitten/etc... that occurs when someone tries your solution and it
doesn't work is on your head.

As a human being you should feel morally obligated to not present anything
as fact unless you are 100% confident that it is indeed so. At the very
least you should have first hand experience as it pertains to the
information you are providing and if not then test / verify it before hand.
Although each individual  failure in this may seem relatively insignificant,
the aggregate result will ultimately have a negative impact on our
evolutionary progress as a species. As far fetched as you may find this to
be the vast multitude of problems that threaten our very existence are at
some level caused by ignorance, as such it should not be taken lightly at
any level.

On Monday, November 17, 2008 11:20:41 AM UTC-5, Romain Guy wrote:

Hi,

If you do this in onCreate(), then the View didn't go through a layout
pass yet, so its size is null (0 by 0 pixels.) You need to either wait
for the first layout, or force the layout by calling layout() on the
View.

--
Romain Guy
www.curious-creature.org

--
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+unsubscribe@googlegroups.com
<mailto:android-developers%2Bunsubscribe@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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bob  
View profile  
 More options Jan 7, 10:00 am
From: bob <b...@coolfone.comze.com>
Date: Mon, 7 Jan 2013 07:00:37 -0800 (PST)
Local: Mon, Jan 7 2013 10:00 am
Subject: Re: [android-developers] Convert a view (layout) to a Bitmap

Maybe you could explicitly call the drawing method of the View passing in
your own Canvas?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
genericforumuser2...@gmail.com  
View profile  
 More options Jan 7, 1:46 pm
From: genericforumuser2...@gmail.com
Date: Mon, 7 Jan 2013 10:46:54 -0800 (PST)
Local: Mon, Jan 7 2013 1:46 pm
Subject: Re: [android-developers] Convert a view (layout) to a Bitmap

You're aware that Romain Guy is the Android engineer that wrote most of the
code involved, right? As such it would seem that he would be infinitely
more familiar with how the code actually works than you are.
Perhaps instead of "correcting" Romain, you could go over to a linux kernel
mailing list and correct Linus Torvalds in his observations on the linux
kernel.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Justin Buser  
View profile  
 More options Jan 26, 9:31 pm
From: Justin Buser <justin.bu...@gmail.com>
Date: Sat, 26 Jan 2013 21:31:21 -0500
Local: Sat, Jan 26 2013 9:31 pm
Subject: Re: [android-developers] Convert a view (layout) to a Bitmap

Who should Google who's name?

--

-- NOT Sent from an iPhone --


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
RichardC  
View profile  
 More options Jan 26, 9:42 pm
From: RichardC <richard.crit...@googlemail.com>
Date: Sat, 26 Jan 2013 18:42:00 -0800 (PST)
Subject: Re: [android-developers] Convert a view (layout) to a Bitmap

You :)

Check out "Romain Guy" he is a Google Engineer


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Justin Buser  
View profile  
 More options Jan 26, 9:55 pm
From: Justin Buser <justin.bu...@gmail.com>
Date: Sat, 26 Jan 2013 21:55:00 -0500
Subject: Re: [android-developers] Convert a view (layout) to a Bitmap

I don't know where you get your information from, but "You're aware that
Romain Guy is the Android engineer that wrote most of the code involved,
right?" is such an absurd thing to say that I'm not even going to begin
getting into it with you.

The fact of the matter is that regardless of who HE is, you have absolutely
no idea who I AM, neither of which is even relevant. Since when does being
in the public eye automatically make someone infallible?

All I can say to all of this is let's see it. Let's see the code that
contradicts or in any way invalidates anything that I have said. It
shouldn't be difficult, it's publicly available source.

Show me one single line of code that suggests I am wrong, or even one
single line of code written by Romain Guy, just ONE LINE from ANYWHERE in
the AOSP or ANY Google product and I will be publicly retract the entirety
of my statements thus far.

It boggles my mind when so many people jump on the trash talking
band-wagon, all tripping over each other to publicly debase me and my point
of view when all I was trying to do is stand up for something that I
personally am very passionate about. I just don't understand why, when this
happens(and it does happen with some regularity), every single person that
starts freaking out and blathering on about how wrong I am fails to produce
a single shred of code or make even a cursory attempt to cite any thing
that would in any way support their contentions. I mean seriously, it's not
like we're talking about where the best coffee comes from...

--

-- NOT Sent from an iPhone --


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Justin Buser  
View profile  
 More options Jan 26, 10:04 pm
From: Justin Buser <justin.bu...@gmail.com>
Date: Sat, 26 Jan 2013 22:04:22 -0500
Local: Sat, Jan 26 2013 10:04 pm
Subject: Re: [android-developers] Convert a view (layout) to a Bitmap

I did actually, not that it's really relevant. I also looked back through
the aosp commit logs and found a grand total of 1 commit that he made, but
that's not really relevant either as it doesn't really PROVE anything... My
frustration was based on the fact that I was looking for a solution to a
problem, and found almost exactly the same couple of paragraphs that he
posted here in several other places as well, all of which were pertaining
to different problems, and none of those problems were related to the
information he was providing.  Now I'm not saying that it was malicious,
and he may in fact have just been trying to help, but the fact still
remains that the information was inaccurate, regardless of any good
intentions.

On Sat, Jan 26, 2013 at 9:42 PM, RichardC <richard.crit...@googlemail.com>wrote:

--

-- NOT Sent from an iPhone --


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
a1  
View profile  
 More options Jan 27, 4:07 am
From: a1 <arco...@gmail.com>
Date: Sun, 27 Jan 2013 01:07:00 -0800 (PST)
Subject: Re: [android-developers] Convert a view (layout) to a Bitmap

W dniu niedziela, 27 stycznia 2013 04:04:22 UTC+1 użytkownik Justin Buser
napisał:

> I did actually, not that it's really relevant. I also looked back through
> the aosp commit logs and found a grand total of 1 commit that he made, but
> that's not really relevant either as it doesn't really PROVE anything... My
> frustration was based on the fact that I was looking for a solution to a
> problem, and found almost exactly the same couple of paragraphs that he
> posted here in several other places as well, all of which were pertaining
> to different problems, and none of those problems were related to the
> information he was providing.

You probably wouldn't sound like total (frustrated) douchebag if you know
what you are saying. Romain advice was of course correct, and your comment
about forceLayout() just proves you have no idea what you are talking about.

Layout is normally done in layout pass, before drawing, and (because layout
is time consuming) it only perform when needed (that is when view is marked
as being eligible for layout). So requestLayout and forceLayout just marks
view to execute layout pass (and indeed will never be executed if view is
not inside view hierarchy) but Romain never suggested to call forceLayout.
His advice was to call layout directly and  doing that will execute layout
- that is will calculate position and size of view and will setup drawing
cache bitmap if enabled.
Everything I just wrote you could easily find in sources, but you are not
up to that task (Android sources could be sometimes hard to read), you
could make a simple test:

package com.test.layout;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ImageView v1 = new ImageView(this);

v1.setImageDrawable(getResources().getDrawable(R.drawable.ic_launcher));
        v1.setDrawingCacheEnabled(true);
        Bitmap b1 = v1.getDrawingCache();

        ImageView v2 = new ImageView(this);

v2.setImageDrawable(getResources().getDrawable(R.drawable.ic_launcher));
        v2.setDrawingCacheEnabled(true);
        v2.layout(0, 0, 200, 200);
        Bitmap b2 = v2.getDrawingCache();

        if (null != b1) {
            ((ImageView) findViewById(R.id.imageView1)).setImageBitmap(b1);
        } else {
            Log.d("TEST", "Cannot get bitmap1");
        }
        if (null != b2) {
            ((ImageView) findViewById(R.id.imageView2)).setImageBitmap(b2);
            Log.d("TEST", "Wow it works, it's probably a miracle");        

        } else {
            Log.d("TEST", "Cannot get bitmap2");
        }
    }

}

which would take like 15 minutes and prove that you assertion were
baseless, but instead you choose to spend 20 minutes on writing stupid
and arrogant accusations, that's also an option I guess.

--
Bart


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Justin Buser  
View profile  
 More options Mar 9, 6:53 am
From: Justin Buser <justin.bu...@gmail.com>
Date: Sat, 9 Mar 2013 06:53:31 -0500
Local: Sat, Mar 9 2013 6:53 am
Subject: Re: [android-developers] Convert a view (layout) to a Bitmap

Thank you for proving my point, even the information *you* posted would be
moderately useful to the person who had originally asked the question, v.s.
the answer provided by Guy which had absolutely no bearing on the problem
they were having.

Perhaps you should work on your spelling and grammar before accusing *me* of
sounding like a douche (hypocrisy instance 1).

Perhaps you should *actually read* the original post I wrote before
replying with something that you imply refutes my point when in fact it
actually affirms it(hypocrisy instance 2).

Perhaps you should *actually read* the android source before accusing me of
not doing the same (hypocrisy instance 3).
https://android.googlesource.com/platform/frameworks/base/+/master/co...
layout
and forceLayout would do absolutely nothing. If you can handle tracing back
through the relevant methods you'll eventually discover the fact that
proves my point, even if the original poster had actually assigned a layout
to his view that layout would have no effect on a View with no parent.

*"His advice was to call layout directly and  doing that will execute
layout"*
-- REALLY?

*"Everything I just wrote you could easily find in sources, but you are not
up to that task"*
-- I am in fact, and have done so. Although  to be honest I don't recall
seeing any rambling gibberish or broken english in them so I'd have to
disagree on this one (hypocrisy instance 4).

*"which would take like 15 minutes and prove that you assertion were
baseless, but instead you choose to spend 20 minutes on writing stupid
and arrogant accusations, that's also an option I guess." *
*-- You* should probably look up the definitions of arrogant and accusation
before writing stupid and arrogant accusations. I simply pointed out that
his answer did not apply to the question, that's not an accusation, merely
a verifiable fact.

FYI:

A.) Calling layout on a view created in the manner indicated would do
absolutely nothing because it has no layout defined, and is not even a
child view of the window yet. It certainly *wouldn't* *force* the layout,
there is a separate function for that purpose, which in this instance would
also do absolutely nothing.

B.) That is irrelevant anyway, because the answer to this question would
have more appropriately been something along the lines of explaining how to
properly create an OpenGL texture using a bitmap, which most certainly is
NOT to instantiate it from the drawing cache of an empty View instance that
hasn't even been added to the display list yet.

The only response that will disprove *anything* that I've said would be to
take the code that the user originally posted and show me how in the hell
you could apply Guys answer (with no added conjecture) and end up with an
even remotely viable solution to the problem as stated, i.e. a Bitmap
applied to an OpenGL texture.

To suggest that his answer of:

*"If you do this in onCreate(), then the View didn't go through a layout **pass
yet, so its size is null (0 by 0 pixels.) You need to either wait **for the
first layout, or force the layout by calling layout() on the **View. "*

would apply to the original question included below would be simply
idiotic. Furthermore I firmly believe that if Guy swallowed his pride and
actually gave it some thought he would eventually agree with me.

--

-- NOT Sent from an iPhone --


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »