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

Android ProgressBar not update when file downloading
Android Button with Left and Right Margin
View fliper not resizing if content is listview
Import OpenIntents to use the OI File Manager in an Android application
Trouble showing an Image Button on HorizontalScroll View
TransactionTooLargeException
Allow Application to Open a Custom Zip File From Gmail
AlarmManager, Service, onStartCommand called but unable to start
How to disable click style in android GridView
How should I make my mobile website support video playing in iphone, android?
Trouble installing Android 4.2 APIs
read user defined data fields android contacts
Using an Android tablet as “input device”
android forcing localized resource selection by own decision not by device configurations
Differentiate title from description
I want to keep an actionbar for all activities

Categories

HOME
design-patterns
prism
deep-learning
fuelux
time-complexity
pclxl
rendering
appcelerator
big-o
babeljs
webix
barcode
accessibility
fosrestbundle
openstreetmap
project-intu
rtf
flash-player
internationalization
fileserver
bourbon
enterprise-miner
jasmine-node
rpgle
bioinformatics
browser-sync
event-flow
utorrent
turfjs
processwire
searchkit
jpad
odroid
loading
mcustomscrollbar
visa
posixct
grails-plugin
latin
lrs
uicolor
greatest-n-per-group
macaulay2
udpclient
shopping
omniauth-facebook
jparsec
rubaxa-sortable
liquid-layout
shopizer
adehabitathr
at-job
uncaught-typeerror
cocos3d
ora-00904
parallel-testing
grails-domain-class
functional-java
winginx
gnumeric
draw2d-js
buffering
dsym
square-bracket
kendo-dataviz
ebay-lms
inappsettingskit
kogrid
android-sdk-2.3
pdfviewer
fragmenttransaction
inkcanvas
oracle-enterprise-linux
stress
ikimagebrowserview
umra
event-receiver
uideviceorientation
updatesourcetrigger
dot-emacs
aspmenu
zen
echo3
feasibility
wcf-proxy

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App