I've wrote an app that encrypt/decrypt pictures. When the encrypted image is stored, in the image gallery we can see the "picture no available" icon for this encrypted image. I would like to change this to default icon, but I don't know where is this default stored...
thanks!
EDIT
What I am trying to do now, is with BitMapFactory convert the encripted file to a bitmap. The icon it's not possible to change and EXIF algorithm is not exactly what I want.
With this code I obtain a black bitmap, what I would like to do is to obtain a bitmap from the encripted file that shows colour pixels. Any idea?
Bittmap bitmap=BitmapFactory.decodeFile("/sdcard/abc.jpg");
Bitmap bm = bitmap.createBitmap(30, 30, Bitmap.Config.ARGB_8888);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bm.compress(CompressFormat.JPEG, 30, bos);
bos.toByteArray();
FileOutputStream ft = new FileOutputStream(new File("/sdcard/ab.jpg"));
bos.writeTo(ft);
bos.flush();
ft.flush();
bos.close();
ft.close();
Since your app encrypts images I guess that you want them all to be viewable only by your app. So why don't you just change the file extension to something other so that the Android Image gallery won't recognize the file as image and try to display it.
This is outside of your control. Default Gallery appliaction (and probably 1000 others on Google Play) display their own image when parsing fails the way they want.
Related
I am trying to use the Azure Face API on android. I am capturing an image from the device camera and then converting it to an InputStream to be sent to the detect method. I keep getting the error "com.microsoft.projectoxford.face.rest.ClientException: Image size is too small"
I checked the documentation and the image size is 1.4Mb which is within the 1Kb-4Mb range. I don't understand why it isn't working.
Bitmap bitmap = cameraKitImage.getBitmap();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, bos);
bitmapdata = bos.toByteArray();
new FaceTask().execute(new ByteArrayInputStream(bitmapdata));
Face[] faces = faceServiceClient.detect(inputStreams[0], true, false, null);
Somehow your file is being compressed more than 1Kb or if it is small in actual size already. Try to save it somewhere in the drawable or assets folder and open it in the input stream.
I use the following code to obtain a bitmap from an ImageView. This image is not saved anywhere else on my device. I want to upload this image into an online mysqli database. However, to do so I need to decrease the size of the file first. I found a lot of links about this, however they all require the file to be saved on the device and then use FileOutputStream. I am looking for a way to reduce the file size so that it can be comfortably transferred using the Volley API ( i am currently receiving either run out of memory exceptions or broken pipe errors). Hence I am looking for a way to modify this code to be able to significantly decrease the file size, whilst still maintaining a quality which can be comfortably shown on a mobile device. The original image is taken straight from the camera hence the size is quite large. Here is my code:
ImageView pic_holder = (ImageView) findViewById(R.id.picturedisplay);
Bitmap bitmap = ((BitmapDrawable)pic_holder.getDrawable()).getBitmap();
ByteArrayOutputStream stream=new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream);
byte[] image=stream.toByteArray();
String img_str = Base64.encodeToString(image, 0);
I would like to decrease the size of the img_str which is passed to my Volley method.
I have a byte array. I then create a Bitmap object from it like this and display it in an ImageView:
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
ByteBuffer buffer = ByteBuffer.wrap(bytes);
image.copyPixelsFromBuffer(buffer);
...
ImageView imgView = (ImageView) findViewById(R.id.image);
imgView.setImageBitmap(image);
I then create a file and store this byte array as an image
FileOutputStream fOut = new FileOutputStream(file);
image.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();
When I open this file in Gallery, it looks different than the one in the ImageView. I tried to write the bytes directly to file, as opposed to the Bitmap, but then I was not able to open the image at all.
ImageView:
Gallery:
I thought that Bitmap.CompressFormat.PNG, endured no compression. What am I missing here?
EDIT:
I don't know if it matters, but the original bytes array comes from encrypting another byte array that came from an original picture. I loaded an image from disk, created a byte array, modified it, and then tried the above with it.
It's probably because you view your image with different background colors in your app and in Gallery. Since you use Bitmap.Config.ARGB_8888 and effectively feed it random data, some pixels will be transparent in the resulting image, and the color of the background will "shine through" when you view the image. If you make the background color of your app black, the image will probably look like it does in Gallery.
I am trying to compress the photo took by the camera in Android. But the color of the image changed when it compressed by Bitmap.CompressFormat.JPEG. How can I solve this problem? Thanks
I have put some sample images which generated from my code. You can see the color of the paper on the top of the images is different.
Here is the code snippet:
Bitmap bitmap = BitmapFactory.decodeFile(Common.FOLDER_PATH + "pic.jpg");
FileOutputStream stream2 = new FileOutputStream(Common.FOLDER_PATH + "pic100.jpg");
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream2);
FileOutputStream stream3 = new FileOutputStream(Common.FOLDER_PATH + "pic100.png");
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream3);
This is original image:
This is JPEG:
This is PNG:
JPEG is a lossy compression format and there may be loss of image information during the compression. The sacrifice of original image information is made for a better compression ratio (resulting in smaller file).
However, if this is not acceptable for you, you should use one of the lossless compression methods which includes the PNG.
Simply put I need to capture image using camera and upload it to facebook via my android application. And I successfully did that. The problem is when the photo posted in facebook, it's just too small and in low resolution while the image I took is in high resolution.
I understand that: in order to upload to facebook, i need to convert the captured image which is in bitmap format into byte array. So i have method for that:
public static byte[] convertBitmapToByteArray(Bitmap bm){
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bm.compress(CompressFormat.PNG, 100, bos);
byte[] bitmapdata = bos.toByteArray();
return bitmapdata;
}
Then to upload the image to facebook, i have code below where byteData is byte array I converted from bitmap image using the method above.
parameters.putString("message", "Test");
parameters.putByteArray("source", byteData);
String facebookResponse = facebookInstance.request(albumId+"/photos",parameters,"POST");
return facebookResponse;
I am pretty sure the problem is my convertBitmapToByteArray method since the method is to compress the bitmap image and turn it into byte array, and this made my image into low resolution image. However I can't seem to find the way to upload the image without converting it into byte array first. Any solution for me?
Alright even this thread is old, i found out the answer. It's not the problem of CompressFormant.JPEG or CompressFormat.JPG. Simply put, intent in android isn't designed to carry big data like image from activity through activity. I need to save the image from intent to sd card first before able to pull it out from there. It's my solution.