android


whole viewgroup to bitmap


Is it possible to get a full bitmap from a viewgroup-object?
This code takes a 'screenshot' off the view group that's currently on the screen, but I want the whole view, also what's not currently on the screen.
public void export(ViewGroup view){
view.setDrawingCacheEnabled(true);
view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
Bitmap bitmap = view.getDrawingCache(true);
}
Here I used ScrollView to get the whole view to bitmap
so Here u can use instead of scrollview anyother view group like linerlayout etc..
Bitmap map = loadBitmapFromView(getApplicationContext(),scrollView);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
map.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
//you can create a new file name "test.jpg" in sdcard folder.
File f = new File("/sdcard" +"/" + "mainemailpdf.jpg");
f.createNewFile();
//write the bytes in file
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
bArray = bytes.toByteArray();
// remember close de FileOutput
fo.close();
and for loadBitmapFromView method is:
public static Bitmap loadBitmapFromView(Context context, View v) {
Toast.makeText(context,
v.getMeasuredHeight() + "::::::::::::" + v.getMeasuredWidth(),
Toast.LENGTH_LONG).show();
if (v.getMeasuredHeight() > 0) {
v.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(),
Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
v.layout(0, 0, v.getWidth(), v.getWidth());
v.draw(c);
return b;
}
return null;
}
I hope it helps :)
Any query let me know.
It is not possible since Android system scales down the bitmap.
For ex - if your bitmap size is 480*800 then its size is 480*800*4 = 1536000.
The multiplication with 4 is because each pixel is 4 bytes - RGBA.
Meaning more than a mega and a half for every unscaled image. If the Android won't scale down image you will probably get
OutOfMemoryException after a few image loadings.
as
you have 3 options:
1) view.draw(canvas) you'll get the visible portion of the image(only what is actually being drawn to the screen)
2) getDrawingCache() - will give you the scaled down image.
3) Create custom view which saves the bitmap to the disk and loads it from there when requested

Related Links

APK file was built successfully with no errors but app isn't working
Android Studio - reading and writing files
Dinamically change style of application. Android
Receiving empty push message after sending GCM Upstream Message
Gradle message in Android Studio
Android - json cannot parse from url
How to store firebase token on my server if user have more than one device
Cannot resolve method “checkSelfPermission”
Populate a spinner based on the selection of another spinner
Updated Android Studio, keystore path lost
decode windows 1256 to utf-8 in android
Is there any way to represent PDF as a flipbook in android?
How to call the MongoLabs (mongoDB) RESTFULL APIS for adding documents in Native Android Application?
How to authenticate firebase database from android jobscheduler
Locale not working properly
Ionic Cordova App Not Installing on Android

Categories

HOME
xml
codenvy
merge
c99
forms
github-for-windows
nunit
owl-carousel
replace
pattern-matching
arangodb
github-enterprise
watson-conversation
mxgraph
aws-sdk
forgot-password
solrcloud
google-maps-autocomplete
angular-routing
parcelable
joptionpane
object-storage
tosca
flask-sqlalchemy
interpreter
froala
mql
autodesk-designautomation
anki
testbed
jbutton
laravel-eloquent
code-snippets
card.io
biztalk-rule-engine
keras-layer
slacktextviewcontroller
mnist
watchman
cd
amazon-ses
loading
metawidget
numberpicker
plaintext
datacachefactory
branching-and-merging
movilizer
snapchat
jide
openrasta
dotnet-httpclient
convex-optimization
posixct
carrot2
oracleclient
check-mk
seq
mach-o
google-photos
objectscript
javafx-css
restore
docpad
meteor-packages
tinkerpop3
mongodb-php
pushbots
nio2
design-principles
concurrentmodification
tfs-workitem
intel-c++
android-launcher
airbrake
entity-framework-4.3
mass-assignment
jbake
pseudo-class
teaspoon
paw
rmysql
insight.database
named-parameters
jquery-slider
ora-06550
http-patch
cmmi
swfobject
wimax
patricia-trie
adobe-media-server
paginator
event-receiver
django-paypal
presentation-layer
aspmenu
message-passing
purepdf

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App