Android :: Get A Byte Array From Drawable Resource?
May 13, 2010I would like to get a byte array from an jpeg image located in my res/drawable file?
View 3 RepliesI would like to get a byte array from an jpeg image located in my res/drawable file?
View 3 RepliesI have Picture data in byte rgb_565 array, and I want convert it in a productive way into argb array. Right now I have found only one (little slow) way to do this: Bitmap mPhotoPicture = BitmapFactory.decodeByteArray(imageData, 0 , imageData.length);
where imageData is my byte[] array in rgb_565, and then: int pixels[] = new int[CameraView.PICTURE_HEIGHT*CameraView.PICTURE_WIDTH]; mPhotoPicture.getPixels(pixels, 0,PICTURE_WIDTH, 0, 0, PICTURE_WIDTH, PICTURE_HEIGHT);
The point is I believe creating a Bitmap object is exacting and not necessary in this case. Is there any other faster way to convert rgb_565 array into argb array? I need this because making image processing on rgb_565 array seems to be a little annoying. Or maybe it is not so hard?
I am trying to make an application that would be able to send the user's voice over the network using RTP. I am using the ported stack from hsc (JLIBRTP) and I am able to record user's voice in a saperate thread. the problem is that jlibrtp uses has a class named RTPSession that is responsible for the session and has the sendData method that takes a byte [] as argument and the AudioFormat class I am using to record user's voice is in AudioFormat.ENCODING_PCM_16BIT wich is short. I have tried using 8bit audioformat but I get an illigalargument exception in my htc magic and in my emulator. So is there any way I can convert the short [] to byte [] ? would that be acceptable in order of voice quality?, is the above error a known bug for htc magic or the platform doesn't support 8bit audio format?
View 3 Replies View RelatedI want to store image in sqlite database. I tried to store it using BLOB and String, in both cases it store the image and can retrieve it but when i convert it to Bitmap using BitmapFactory.decodeByteArray(...) it return null. Below is my code please have a look and suggest me where i m making mistake.
View 3 Replies View RelatedDoes anyone know how to convert a bitmap to a byte array?
View 2 Replies View RelatedCan please anyone let me know how to display a raw RGB 565 byte array on the screen.
View 2 Replies View RelatedIs it possible to create a byte array from bitmap?How can I do so?
View 3 Replies View RelatedI want to store pictures from the internet in my data base as byte arrays. I get the pictures as bitmaps, but can't find way to convert it to byte array.
View 4 Replies View RelatedIm trying to convert a byte array which is in Base64 format to String as below. Data was not assigned properly to the String. Do I need to pass the encoding type while creating the new String?
View 3 Replies View RelatedI try to send an image over bluetooth to another device. This works mostly fine, but sometimes, I get a StreamCorruptedException: Wrong format: 0x27 on the receiving device. Anybody knows what this means? And how can I avoid that?
View 1 Replies View RelatedI ask if there is a simple way because there is a google issue report saying that using decodeByteArray isn't possible. But that report originated in 2008 and I was hoping there was a solution not posted on there. The method listed on the issue report was to decode the format yourself, but I'd prefer to not have to put that in and slow down the program.
View 1 Replies View RelatedI have to convert a byte array to string in Android, but my byte array contains negative values. If I convert that string again to byte array, values I am getting are different from original byte array values. What can I do to get proper conversion?
View 7 Replies View RelatedI'm using the following code to encrypt a String (inText) whose output is a byte array named cipherText;
Code:
byte[] cipherText;
cipherText=cipher.doFinal(inText.getBytes());
The cipherText is printed in a textbox as follows:
Code:
encText.setText(new String(cipherText));
Everything works fine until here. However, in the decryption section, I need to get the contents of the textbox as a byte array again. For this purpose, I use the following code:
Code:
byte[] cText;
cText=encText.getText().toString().getBytes();
When I try to do the encryption it gives a 'bad size' error. I found out that the lenghts of the two byte arrays cipherText and cText aren't equal:
Code:
decText.setText(Integer.toString(cText.length));
encText.setText(Integer.toString(cipherText.length));
boolean res=Arrays.equals(cText, cipherText);
result.setText(Boolean.toString(res));
The 'result' textbox always prints 'false' meaning that the two byte arrays cipherText and cText aren't equal. However I convert cipherText to a String to print in a textbox and then read the contents of that textbox, convert to String back and then to Byte Aray again. Obviously some data is lost during these conversions.
Please could anyone suggest an approach for transferring a >2MB video from a ContentResolver into a Bytestream, without running out of memory?
See question: http://stackoverflow.com/questions/2599305/android-outofmemoryerror-w...
Here's the current code, which throws an OutOfMemoryError on the byteBuffer.write(buffer, 0, len) line when transferring large videos:
// get bytestream to upload videoByteArray = getBytesFromFile(cR, fileUriString);
public static byte[] getBytesFromFile(ContentResolver cR, String fileUriString) throws IOException { Uri tempuri = Uri.parse(fileUriString);
InputStream is = cR.openInputStream(tempuri);
byte[] b3 = readBytes(is); is.close(); return b3;
}
How do I store and retrieve a byte array (image data) to and from a SQLite database in Android?
View 1 Replies View RelatedThis is a part of my code...
i want to replace the "" in the title_t.setText("") by a thing that can work.
I just want to take the title from the listview which come from a resource..
I just want to read <string-array> resource elements into a String array. I don't want to make a view or anything and mess with adapters - just want to transfer the elements. Is there a built in class for this? Or do I need to treat the resource file as a regular file?
View 3 Replies View RelatedI need to use some inbuild drawable I found in
http://developer.android.com/reference/android/R.drawable.html
I set drawable @drawable/ic_input_add to a button in my layout xml file. The add icon appears on the button of layout editor. But there is a error of that xml file said that
Description Resource Path Location Type ERROR Error: No resource found that matches the given name (at 'drawableLeft' with value '@drawable/ic_input_add'). spend_list.xml / AccountBook/res/layout line 5 Android AAPT Problem. How to use a inbuild drawable?
I have some image names stored in a database, but the images themselves are in the /res/drawable folder of the application. I need to assign these images to some views at runtime, and I'm currently doing it this way:
// public static final String DRAWABLES_PATH = ":drawable/";
int resId = getResources().getIdentifier(packageName+DRAWABLES_PATH +imageName,null,null); mButtonX.setBackgroundResource(resId); //
Is there a more efficient way to do it? Or should I be storing the images directly in the database (they are many)?
I need to create a tiled drawable using BitmapDrawable but I need to create it from xml resource rather than code.
View 3 Replies View RelatedI have:
String uri = "@drawable/myresource.png";
How can I load that in ImageView? this.setImageDrawable?
Does all resource (all in res folder if on eclipse IDE), specially drawable image, is loaded to memory during runtime? Or it is just like a file which is available when the application need it?
View 1 Replies View RelatedI have a String Array Resource that has about 1000 drug names
<string-array name="index">
<item>Aspirin</item>
<item>Levitra</item>
....
</string-array>
I tried to load this string array into a String[] inside an activity. Using the same syntax provided by Google's java documentation found here.
Resources res = getResources();
String[] drugs = res.getStringArray(R.array.index);
It appears my string-array has too many records and its causing my App to crash (stack-overflow?) When I reduce the string-array resource to about 506 records, the app works again, but adding even 1 more element in the string-array would crash the app. What should I do? I want to code logic to filter and do other things to the list. I do not have a SQL db in the app so I can't do the processing in the DB. Is there a way to iterate through the string-array resource without loading it into a String []? I notice the resource is a pointer. Or is there an alternative data structure or approach that would work?
I am trying to create a drawable in code and change the color based on some criteria. When I try and set the Drawable as the background of the ImageView it displays but won't let me set any padding. I realized I need to set the ImageView image via the setImageDrawable() function in order to be able to set the padding. The problem I am running into is that when I set it via the setImageDrawable() function nothing is displayed.
Here is what I have written:
<?xml version="1.0" encoding="utf-8"?>
ImageView icon = (ImageView) row.findViewById(R.id.icon);
ShapeDrawable mDrawable; int x = 0; int y = 0;
int width = 50; int height = 50;
float[] outerR = new float[] { 12, 12, 12, 12, 12, 12, 12, 12 };
mDrawable = new ShapeDrawable(new RoundRectShape(outerR, null, null));
mDrawable.setBounds(x, y+height, x + width, y);
switch(position){ case 0: mDrawable.getPaint().setColor(0xffff0000); //Red break;
case 1: mDrawable.getPaint().setColor(0xffff0000); //Red break;
case 2: mDrawable.getPaint().setColor(0xff00c000); //Green break;
case 3: mDrawable.getPaint().setColor(0xff00c000); //Green break;
case 4: mDrawable.getPaint().setColor(0xff0000ff); //Blue break;
case 5: mDrawable.getPaint().setColor(0xff0000ff); //Blue break;
case 6: mDrawable.getPaint().setColor(0xff696969); //Gray break;
case 7: mDrawable.getPaint().setColor(0xff696969); //Gray break;
case 8: mDrawable.getPaint().setColor(0xffffff00); //Yellow break;
case 9: mDrawable.getPaint().setColor(0xff8b4513); //Brown break;
case 10: mDrawable.getPaint().setColor(0xff8b4513); //Brown break;
case 11: mDrawable.getPaint().setColor(0xff8b4513); //Brown break;
case 12: mDrawable.getPaint().setColor(0xffa020f0); //Purple break;
case 13: mDrawable.getPaint().setColor(0xffff0000); //Red break;
case 14: mDrawable.getPaint().setColor(0xffffd700); //Gold break;
case 15: mDrawable.getPaint().setColor(0xffff6600); //Orange break;
} icon.setImageDrawable(mDrawable); icon.setPadding(5, 5, 5, 5);
This results in a space for the ImageView but no image.
I tried doing a ProgressBar and I wanted to change the background and the progress bar using my own drawables from the drawable resource. Is this possible? I just don't want to spend time creating my own custom component if can be done relatively easy.
View 4 Replies View RelatedI'm going to be using
setBackgroundResource(R.drawable.background)
in my onCreate() method.
When I create the XML file with the and its colors, what type of resource am I creating? "values", "layout"?
Is is possible to specify data in xml resource file and initialize ArrayList from it? I am looking for a way to use the ArrayList with a SimpleAdapter to bind to a ListView. I am wondering if there is a way to specify my data in xml resource file and init ArrayList from it.
View 6 Replies View RelatedI have an xml resource in res/values/integers.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer-array name="UserBases">
<item>2</item>
<item>8</item>
<item>10</item>
<item>16</item>
</integer-array>
</resources>
and ive tried several things to access it:
int[] bases = R.array.UserBases;
this just returns and int reference to UserBases not the array itself
int[] bases = Resources.getSystem().getIntArray(R.array.UserBases);
and this throws an exception back at me telling me the int reference R.array.UserBases points to nothing
what is the best way to access this array, push it into a nice base-type int[] and then possibly push any modifications back into the xml resource.
I've checked the android documentation but I haven't found anything terribly fruitful.
Can I have sub-folders to hold my drawable resources. For example can I store an image in, say, 'res/drawable/content/images/myimage.jpg' and then find that resource via a call to:
id = context.getResources().getIdentifier("com.mycompany.myprog:drawable/ content/images/myimage", null, null);
I have tried this and it doesn't seem to be working (but I may have something wrong). Is it supposed to work or do all the resources need to be in the root drawable folder? Also, are jpeg files supported and drawable resources?
Is it possible to have subfolders in the /res/drawable directory. I would like my resources to be organized in a tree view and not in a flat dir. If it is possible so how do I reference the resource from the code?