Android :: Loading A Resource To A Mutable Bitmap

Sep 11, 2010

I am loading a bitmap from a resource like so:

Bitmap mBackground = BitmapFactory.decodeResource(res,R.drawable.image);

What I want to do is make some changes to the bitmap before It gets drawn to the main canvas in my draw method (As it would seem wasteful to repeat lots of drawing in my main loop when it isn't going to change). I am making the changes to the bitmap with the following:

Canvas c = new Canvas(mBackground);
c.drawARGB(...); // etc

So naturally I get an exception

java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor

So to avoid that I made a copy of the bitmap so that it is mutable

Bitmap mBackground = BitmapFactory.decodeResource(res,R.drawable.image).copy(Bitmap.Config.ARGB_8888, true);

Which avoid the problem however it sometimes causes OutOfMemoryExceptions, do know any better ways of achieving what I want?

Android :: Loading a resource to a mutable bitmap


Android :: Create Mutable Bitmap From Camera - Draw Another Bitmap On Top - And Save It

Apr 2, 2009

I am 1) taking a picture and 2) then draw another Bitmap on top of it 3) then I store it

I am doing it as follows and it works on the emulator.

On the device I get a OutOfMemoryError: bitmap size exceeds VM budget android.graphics.Bitmap.nativeCopy(Native Method) android.graphics.Bitmap.copy(Bitmap.java:199) in the line copy the Bitmap to get a mutable Bitmap.

CODE:...........

What I am asking:

a) Is there a better way to do what I am doing? 1) take a picture 2) draw another Bitmap on top of it 3) then I store it

b) What is the best way to create a mutable Bitmap from the picture I just took with the camera?

In my app, resolution is not an issue. If it works better for small photos that would be fine.

View 3 Replies View Related

Android :: Bitmap Resource Not Found On 1.5 Platform AVD

Nov 2, 2010

I have a bitmap that I want to display in my Android app.This works fine for platforms with version number greater than 1.5 but not for 1.5. When executing the line below an exception is thrown stating that the resource couldn't be found.

Bitmap bmp = BitmapFactory.decodeResource(mApplicationContext.getResources(), R.drawable.arrow);

I have put the bitmap in all density-folders (hdpi, mdpi, ldpi) and scaled them according to the documentation (the mdpi-bitmap is 25x25 pixels and the ldpi-bitmap size 75% of the mdpi-bitmap size and the hdpi-bitmap size 150% of the mdpi-bitmap size).
Any idea what is wrong here?

View 2 Replies View Related

Android :: Determining What Bitmap Resource Was Loaded

Nov 14, 2010

I have created multiple bitmaps - one for each folder (mdpi, hdpi, ldpi). Can someone show me some code or point me to the appropriate method that will allow me to detect which resource Android decided to load.

View 4 Replies View Related

Android :: SDK - Convert Bitmap To Resource For Layout Params?

Nov 3, 2010

For some reason, when I create a bitmap from an image in asset, it does not display fullscreen. When I take an image from drawable, resId, the image shows fullscreen. Why is this?

CODE:..........................

View 1 Replies View Related

Android :: Dynamic Resource Loading

Sep 5, 2010

I'm trying to find a way to open resources which name is determined at runtime only. Let me explain in more details. I want to have a XML that references a bunch of other XML files in the application apk. for the purpose of explaining lets say the main XML is main.xml and the other XML are file1.xml file2.xml...fileX.xml...

what i want is to read main.xml, extract the name of the xml I want (fileX.xml) for example. and then read fileX.XML. the problem I face is that what I extract form main.xml is a string and I can't find a way to change that to R.raw.nameOfTheFile

View 2 Replies View Related

Android :: Loading & Displaying Image From A Resource

Apr 29, 2010

Currently I'm successfully loading and displaying an image from a webserver using the code below.

URL imgURL = new URL("http://www.xxx.com/myimage.png"); URLConnection conn = aURL.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); bm= BitmapFactory.decodeStream(bis); bis.close(); is.close();

canvas.drawBitmap(bm, 0, 0, null);

What I want to do is load it from a resource. I've put myimage.png into res/drawable and referenced the bitmap as follows :-

Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.myimage);

However when I try to display it with canvas.drawBitmap(bm, 0, 0, null); I get a Force Close. What am I missing?

View 2 Replies View Related

Android :: Loading Resource Represented By R.attr.*

Nov 6, 2010

I want to load resource that is located in android.R.attr class.Next code failed to load resource with Resources$NotFoundException exception:

getResources().getString(android.R.attr.action); //action is a string resource

Also tried to load resource using:

getResources().obtainAttributes(android.R.attr.action)

No exception is thrown, but returned TypedArray array has nothing valuable inside it. At least I couldn't find anything that is connected to actual resource id or resource I'm interested in.So, how to load resources represented by android.R.attr.* ids?

View 1 Replies View Related

Android :: Optimizing Bitmap Loading By Using ASyncTask

Aug 4, 2010

I have been trying to optimize my single thread app which loads a bunch of tiles that makeup a large bitmap.The app was becoming very sluggish when it would load the new tiles into system memory.I'm now looking trying to use Async Tasks for this purpose. The app detects which tile is in the top left in a method called by onDraw, creates a string that contains the path of the bitmap in the Assets folder, and then checks to see if the bitmap is null before drawing. If it is null, it will load it into memory. My idea was to process the bitmap in DoBackground, and in postExecute trigger a view invalidate to display the async loaded bitmap. Few questions:

1.) can i execute my aSync task for each bitmap? (this statement: new myAsyncTaskManager().execute(bitmapPath); if not, what is the best way to go about it since the only thing aSync will do is just load bitmaps into memory?

2.) Is it possible to set the priority aSyncTask if the bitmaps load too slow?

3.) Is there a better way to go about this? im certain it is the bitmap loading, and not the canvas drawing that slows down the app.

My temporary aSync code:

private class myAsyncTaskManager extends AsyncTask<String, Void, String> {

@Override
protected String doInBackground(String... bitmapPath) {
Log.e("sys","i ran using aTask");
try {

bitmapArray[rectBeingDrawn] = BitmapFactory.decodeStream(assetManager.open(imagePathToLoad));

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} return null;
}

@Override
protected void onPostExecute(String result) {
// execution of result of Long time consuming operation
mCampusMap.invalidate()

View 2 Replies View Related

Android :: Loading An Alpha Mask Bitmap

Oct 28, 2010

I have a single-channel PNG file I'd like to use as an alpha mask for Porter-Duff drawing operations.If I load it without any options, the resulting Bitmap has an RGB_565 config, i.e. treated as grayscale.If I set the preferred config to ALPHA_8, it loads it as a grayscale ARGB_8888 instead.How can I convince Android to treat this file as an alpha mask instead of a grayscale image?

mask1 = BitmapFactory.decodeStream(pngStream);
// mask1.getConfig() is now RGB_565

BitmapFactory.Options maskOpts = new BitmapFactory.Options();
maskOpts.inPreferredConfig = Bitmap.Config.ALPHA_8;
mask2 = BitmapFactory.decodeStream(pngStream, null, maskOpts);
// mask2.getConfig() is now ARGB_8888 (the alpha channel is fully opaque)

View 1 Replies View Related

Android :: Loading Raw Resource Text File / Out Of Memory Error

Sep 15, 2010

I use this method couples of occasion to load text file to display as help file. But I don't know why the following code didn't work. It seems to hang and logcat says "OutOfMemoryError"? All I did was break this out as an separate activity.

---xml---
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/helptab"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/helptext"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</ScrollView>

---code---
import java.io.DataInputStream;
import java.io.IOException; import java.io.InputStream;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class Help extends Activity {
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.help);
InputStream iFile = getResources().openRawResource(R.raw.help);
try { TextView helpText = (TextView) findViewById(R.id.helptext);
String strFile = inputStreamToString(iFile);
helpText.setText(strFile);
} catch (Exception e) {
} }
public String inputStreamToString(InputStream is) throws IOException {
StringBuffer sBuffer = new StringBuffer();
DataInputStream dataIO = new DataInputStream(is);
String strLine = "";
while ((strLine = dataIO.readLine()) != "") {
sBuffer.append(strLine + " ");
} dataIO.close();
is.close();
return sBuffer.toString();
}

View 6 Replies View Related

Android :: Will Threaded Resource Loading Improve Throughput - Or Just Responsiveness

Oct 13, 2010

Are there any Android phones that are multi-processor (multi-core/ cpu), where application threads execute concurrently on different processors?

There doesn't seem to be any explicit way of doing asynchronous file I/ O or asynchronous resource loading. So, suppose I put BitmapFactory.decodeResource() or Resources.openRawResource() into a separate thread. Will those methods play nice with the other threads, yielding during blocking I/O operations so those other threads can run?

If those methods rely on the thread scheduler to forcibly suspend them, then the separate resource-loading thread isn't going to help me get my application started any faster (although it will help it to be more responsive to user input).

View 5 Replies View Related

Android :: OutOfMemory Exception When Loading Bitmap From External Storage

Nov 5, 2010

In my application I load a couple of images from JPEG and PNG files. When I place all those files into assets directory and load it in this way, everything is ok:

CODE:..................

But when I try to load the exact same images from sd card, I get an OutOfMemory exception!

CODE:..............

This is what I get in the log:

CODE:...........

UPDATE: Tried both of these on real device - it seems that I can't load more than 12MB of bitmaps into whatever is called "external memory" (this is not an sd card).

View 7 Replies View Related

Android :: Loading Only Part Of Bitmap File In Android

Mar 30, 2010

I would like to load a cropped version of a bitmap image into a Bitmap object, without loading the original bitmap as well. Is this at all possible without writing custom loading routines to handle the raw data?

View 1 Replies View Related

Android : Crop Bitmap Without Reading Entire Bitmap / Cannot Read Image Into Memory

Jul 21, 2010

I have a very large image and I only want to display a section the size of the display (no scaling), and the section should just be the center of the image. Because the image is very large I cannot read the entire image into memory and then crop it. This is what I have so far but it will give OutOfMemory for large images. Also I don't think inSampleSize applies because I want to crop the image, not lower the resolution.

Uri data = getIntent().getData();
Input Stream is = getContentResolver().openInputStream(data);
Bitmap bitmap = BitmapFactory.decodeStream(is, null, null);

Any help would be great?

View 3 Replies View Related

Android :: How To Use Resource Within A Custom Xml Resource File?

Aug 3, 2010

I have an XML resource file:
<resources> <section>
<category value="1" resourceId="@xml/categoryData1" />
<category value="2" resourceId="@xml/categoryData2" />
<category value="3" resourceId="@xml/categoryData3" />
</section> </resources>
Using XmlPullParser, on the START_TAG, I can use:
int value = parser.getAttributeIntValue(null, "value", 0);
to get values 1, 2, 3...however:
int resourceId = parser.getAttributeIntValue(null, "resourceId", 0);
doesn't work...it just yields the default value 0, or whatever I change the default value (3rd parameter) to be. Does anyone know what I am doing wrong or if this is possible?

View 1 Replies View Related

Android :: Overlay Bitmap - Draw Over A Bitmap

Oct 8, 2009

I have two questions actually:

Is it better to draw an image on a bitmap or create a bitmap as resource and then draw it over a bitmap? Performance wise... which one is better?

If I want to draw something transparent over a bitmap, how would I go about doing it?

If I want to overlay one transparent bitmap over another, how would I do it?

View 1 Replies View Related

Android :: Draw A Bitmap Rotated Onto Another Bitmap

Mar 22, 2009

My goal is the draw a bitmap onto another bitmap but rotated 90 degress. whats the most efficient way to do that. My current method is as follows which is horribly bad because it creates a new bitmap every time.

CODE:.....................

View 4 Replies View Related

Android :: Displaying A Now Loading Image While Applic - Loading

May 4, 2009

I want to display a fancy 'loading' image at my app's startup time.

The problem: my startup code is mostly GUI related, hence needs to run on UI thread.

Is there a way to do both - that is run UI-related code on UI thread while an image is displayed to the user?

View 8 Replies View Related

Android :: Draw Shape Or Bitmap Into Another Bitmap - Java - Android

Jun 22, 2010

I want to draw a shape(many circles particularly) into a Specific Bitmap. I have never used canvas / 2D graphs etc. As i see it i create a Drawable put the bitmap in it then "canvas-it" to the shapes i want etc.

View 1 Replies View Related

Android :: Loading Activity Darkens Screen - Loading Screen

Nov 2, 2009

I've looked through the documentation and I can't seem to figure out how to have the screen blured/greyed when I select an activity that may take a while to load.

This seems to be an Android standard (both the Camera app and the Camcorder app do it when first selected), but I don't see any documentation on it. I even tried looking through the source of these apps on git, but couldn't seem to find it.

View 3 Replies View Related

Android :: Resource ID

Sep 6, 2010

I am using the function decodeResource(Resources res, int id, BitmapFactory.Options opt).I am using it in the following way:

BitmapFactory.decodeResource(getResources(), R.drawable.image,opt);

My question is instead of using R.drawable.image which is an image in resdrawable folder, I want to use a image from sdcard.Is it possible? How to get the resource id of an image in the sdcard?

View 3 Replies View Related

Android :: Get Resource ID From Value

Oct 11, 2010

I do have a lot of language specific resources. There's one point in my Android apps where I do get a resource value and need to translate this value into the matching id. The value is not neccessarily in the language specific file for the current language (en/de/...). It's somewhere in there ... and it's unique.

After reading the docs and this thread "http://stackoverflow.com/questions/3476430/get-resource-id-by-passing-name-as-a-parameter-in-android" I thought that "getIdentifier(String name, String defType, String defPackage)" is the correct way to go but I can't get it to work. The result is always "0".

This code is part of an activity and I'm on Android 2.2.

Is it possible that Android doesn't take all resource files into account and searches just in the current language specific one?

For an example

CODE:....

To make things clear. I don't want to mis-use string resources as a database. It's only one part that occurs on very rare situations.

View 1 Replies View Related

Android :: Resource For Very New Beginner?

Jul 25, 2010

I will admit - I've never had a smart phone. Never. I was going to get one last year, but waited b/c I heard 2010 was 'the year of the smart phone' - and I'm glad I waited.Though I'd have to see it in person to know for sure, but I'm almost positive that DroidX will be my first smartphone. I'm VERY excited, but I want to make sure that I'm educated enough to use it for all it's worth (ie: my mom has had every iphone, but just leared to text message last month).Is there some place/book/thread/site that I can study which would tell me about smartphones from the very most basic all the way to the more advanced? I'm a smart girl, but I have to start somewhere!

View 1 Replies View Related

Android :: Can I Parse Uri From Resource?

Mar 18, 2010

When I use the first,app will crash in emulator but the second run well, how can I fix the first. Code...

View 1 Replies View Related

Android :: Resource IDs And SharedUserID

Jul 20, 2010

If I am not wrong with the way android:sharedUserId is intended to work, then my question is how to avoid overlapping resource IDs? appt seems to aways start IDs at the same initial value (i.e. drawables at 0x7f020000), so there will be sort of conflict or ambiguation. As for now I failed to get that cleared w/o digging in OS sources. Or I miss anything, like magic "undocumented" appt option (not that aapt is documented at all)?

View 5 Replies View Related

Android :: Resource In Conflict

Sep 4, 2010

My application has resource conflict problem. Did some investigation, seems like all the resources within the apk file are cached after they are loaded on demand. The cache is stored in Resources.java mDrawableCache. The key to retrieve the drawable from this cache is combining the data and assertCookie fields of TypedValue class. In my application, there are 2 resources, ex. a color background and image drawable, evaluated to the SAME key value.. So just wondering, how can it happen?BTW, I am using eclair SDK.

View 2 Replies View Related

Android :: Negative Resource Id Value

Sep 15, 2010

Is it possible that a resource id (such as a generated id for a string resource) can be a negative int?Often, when defining a method that accepts a resource id, I want the caller to be able to specify a "null" value.For primitives this is not possible, but I'm wondering whether "any negative value" may be a good approach? Alternatively I suppose it would be OK to specify the argument as an Integer and take advantage of auto-boxing.Thoughts?

View 3 Replies View Related

Android :: Skin Resource

Jul 19, 2010

Can this kind of files (buttons) be used to create android applications, or you must use predefined buttons?

http://graphicriver.net/item/tabletphone-user-interface-professional-.

View 2 Replies View Related

Android :: Resource With Name From Numbers

Oct 13, 2009

I had imported several .png files with names like 1.png, 2.png untill 59.png in my Android Project.But it gives this error:

Description Resource Path Location Type Syntax error on token "48", invalid VariableDeclaratorId R.java / TVGidsBelgie/gen/com/woutergo/tvgids line 14 Java Problem

How can i solve this?

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved