How to display an image saved as "/storage/emulated/0/Download/IMG_1582623402006.jpg" in emulator - android-studio

I capture a image by camera in emulator and it was saved as:
"/storage/emulated/0/Download/IMG_1582623402006.jpg"
I am trying to display this image in < ImageView > as the following:
Bitmap finalBitmap = BitmapFactory.decodeFile("/storage/emulated/0/Download/IMG_1582623402006.jpg");
holder.image.setImageBitmap(scaledBitmap);
but it shows that "finalBitmap" is empty. What have I missed?
Thanks in advance!

You posted this over a year ago, so it may be too old at this point.
It appears that you are using two variables for your bitmaps: finalBitmap and scaledBitmap and not referencing the proper one in the setImageBitmap command.
Instead, have you tried this?
holder.image.setImageBitmap(finalBitmap);

Not totally sure, but adding some attributes in "options" seems make it work in emulator:
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = true;
options.inSampleSize = 5;
Bitmap scaledBitmap = BitmapFactory.decodeFile(/storage/emulated/0/Download/IMG_1582623402006.jpg, options);
holder.image.setImageBitmap(scaledBitmap);

Related

How can I rezise an image in Haxeflixel?

I'm trying to set up a background in my game, and I want it to support multiple resolutions. I've tried using the scale trigger, but I'm pretty sure it multiplies the dimensions by the value. I need to resize the background by the resolution, so that won't work. Here's my code right now:
bgImage = new FlxSprite();
bgImage.loadGraphic(AssetPaths.SP_LevelBG__png, false, FlxG.width, FlxG.height);
bgImage.width = FlxG.width;
bgImage.height = FlxG.height;
add(bgImage);
Thanks in advance.
Use scale: https://snippets.haxeflixel.com/sprites/scale/
bgImage.scale.x = 10;
bgImage.scale.y = 10;

EaselJS StageGL: text not working (but does using Stage canvas)

I re-programmed a HTML5 game (using createJS) to match StageGL, but it turned out all text fields disappear. Switching back to Stage solved this specific problem (see code example below).
Does anyone know a workaround to this?
Example code:
canvas.width = stageWidth;
canvas.height = stageHeight;
stage = new createjs.StageGL(canvas); // <= text does not work with GL???
stage = new createjs.Stage(canvas); // <= text works fine
var textTest = new createjs.Text("Hello World");
textTest.x = 10;
textTest.y = 20;
stage.addChild(textTest);
Thanks in advance for your comments!
Text will not work without being cached, as the Text/Vector canvas APIs are not supported by StageGL.
Caching is pretty easy:
var bounds = text.getBounds();
text.cache(bounds.x, bounds.y, bounds.width, bounds.height);
When the text changes, you will need to recache the text.
Cheers,

Chrome capture visible tab gives messy result

I have a Chrome extension, where I'm using the captureVisibleTab method of the chrome.tabs API to capture screenshots. I have tested the extension on 3 devices (Chromebooks) and I'm getting mixed results. Two of them work perfectly, but one always returns a completely malformed screenshot.
My code:
chrome.tabs.onUpdated.addListener(function(tabId,changeInfo,tab){
chrome.tabs.get(tabId, function (_tab) {
if (_tab.status == "complete" && _tab.active ) {
chrome.tabs.captureVisibleTab( function(dataUrl){
});
}
});
});
Any ideas what could be the issue on that one device?
EDIT
Example of a bad screenshot:
I suspect that the device pixel ratio is higher on your 3rd device. This was an issue I was having with Retina displays when building a screenshot app. Basically, certain high-resolution displays have a higher ratio pixels per square inch. You're going to want to find window.devicePixelRatio and divide the context scale by that amount.
Assuming that you are using Canvas to draw the screenshot and capture it into an image, this little snippet should help show what you're going to want to do:
var canvas = document.createElement("canvas");
canvas.width = image.width;
canvas.height = image.height;
var context = canvas.getContext("2d");
if(window.devicePixelRatio > 1){
context.scale(1/window.devicePixelRatio, 1/window.devicePixelRatio);
}
context.drawImage(image, 0, 0);
Let me know if that works for you.

Gridview in C++ windows form app cant edit

I am not sure if I am missing something, but for the life of me I cannot get the grid to be editable.
All I am doing is loading a file to a Dictionary, then binding that Dictionary to the grid.
The grid displays the data in the Dictionary, but I cant edit any data in the grid.
I tried changing the modes also:
EditOnEnter
EditOnKeyStroke
And Nada.
Any ideas? PS: I have not done much GUI work in C++, so maybe I am overlooking something.
Here is how I load the grid.
Dictionary<String^, String^>^ data = gcnew Dictionary<String^, String^>();
BindingSource^ bindingSource1 = gcnew BindingSource();
// Read and display lines from the file until the end of the file is reached.
while ( line = sr->ReadLine() )
{
array<String^>^split = line->Split( chars );
data->Add(split[0], split[1]);
}
dataGridView1->DataSource = bindingSource1;
bindingSource1->DataSource = data;
dataGridView1->AutoResizeColumns( DataGridViewAutoSizeColumnsMode::AllCells);
Thank in advance.
I found the problem. You have to use an update-able source and a Dictionary is not update-able.
Once I changed to a DataTablew, problem solved.

setIcon in j2me to set icons for buttons

I am trying to put in an icon (a scaled image) as part of a button that also contains some text. I am programming in J2ME for the Nokia SDK (S60 device) and using Eclipse.
The code is as follows:
but = new Button("Some text");
Image img = null;
try {
img = Image.createImage("/flower.png");
} catch(IOException e) {
e1.printStackTrace();
}
but.setIcon(img);
The above lines are the code that works properly. I am facing problems in scaling the image to the size of the button. Whenever I try to do that, I get a divide by zero error. The function I am using to scale the image and the way it is being scaled is:
Image img2 = null;
img2 = img.scaled(but.getWidth()/2, but.getHeight());
but.setIcon(img2);
I am unable to figure out why I get a divide by zero error every time I try to run the above code. Is there some other function that I should use? Or is there something I am missing ?
which UI Framework are using, is it LWUIT? if yes, you can't get the width/height of any component before showing the form, you should use getPreferredWidth instead

Resources