I have created a bitmap that forms a linear gradient background. I am trying to save it into the device's storage but the saved image has very low quality.
Code to save the bitmap image:
public void saveImage(Bitmap bitmap) {
String filename = "dy/dx_wallpaper-" + System.currentTimeMillis();
String url = MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, filename, "Gradient Wallpaper");
Toast.makeText(MainActivity.this, "Saved as " + url, Toast.LENGTH_SHORT).show();
}
Image should be like this
But it's like this
Am I doing something wrong?
Thanks in advance folks! :)
It seems the insertImage method only stores a thumbnail of the original bitmap. Here is a possible solution which may help:
How to insert high quality Bitmap image in android into Gallery
Related
I am a newbie to MFC.
I am trying to copy a CScrollView dialog (which has drawn contents) into a image and then save that to a image as bmp or jpg or tiff.
I know how to save the CImage into a file, but i am unable to copy the draw area into a new CImage object. I know the procedure to copy. but i am unable to get in the code.
I need to get the CDC of the drawn area.
Create a new DC and copy that to new DC or an image.
Save the image.
Any pointers please?
You can create CImage based on Window size, and just draw on that image with BitBlt. Use CImage::GetDC() to obtain HDC, don't forget to call CImage::ReleaseDC() later.
CDC *pDC; //or use CClientDC, CPaintDC etc.
//do all drawings on pDC first
//pDC->TextOut(0,0,L"hello world")...
CRect rc;
GetClientRect(&rc);
CImage image;
image.Create(rc.Width(), rc.Height(), 32);
HDC imageHDC = image.GetDC();
::BitBlt(imageHDC, 0, 0, rc.Width(), rc.Height(), pDC->GetSafeHdc(), 0, 0, SRCCOPY);
image.Save(L"fileName.jpg", GUID_NULL);
image.ReleaseDC();
I have a HashMap in which I stored images with Bitmap format. Now the problem is how do I get those images again?
In details,
Here in this hasmap, I stored my Bitmap image as an object.
ArrayList<HashMap<String,Object>> mImgList = new ArrayList<HashMap<String,Object>>();
Bitmap img = imgLoader.decodeSampledBitmapFactoryFromUrl(x,x,x,x);
HashMap<String, Object> map = new HashMap<String, Object>();
map.put(TAG_IMG, img);
map.put(TAG_NAME, name);
map.put(TAG_ID, cont_id);
mImgList.add(map);
I use this hashmap in the listview to diplay img and text, everything's fine.
But now I need to display some of those images in a ImageView, but I don't know how to get the image as those Bitmap in the HashMap is becoming an object.
I tried to use:
Bitmap bmp = mImgList.get(x).get(TAG_IMG);
but what i got is actualy an object not a bitmap. so how should i get my bitmap? or are there any other way I can display this picture on the alertdialog? thanks!
Turns out no one answered my question...But I end up converting bitmap into drawable so that I can save them into hashmap and get them when i want.
Bitmap bitmap = (Bitmap) mMap.get("bitmap_key_001");
Problem:
I have used following code for scaling image and make it fit to bounds of UITableviewCell in monotouch.This code is scaling image but it is making image color faint means it is not maintaining color combination.So please provide any better solution.
Code:
public static UIImage Scale (UIImage source, SizeF newSize)
{
UIGraphics.BeginImageContext (newSize);
var context = UIGraphics.GetCurrentContext ();
context.TranslateCTM (0, newSize.Height);
context.ScaleCTM (1f, -1f);
context.DrawImage (new RectangleF (0, 0, newSize.Width, newSize.Height), source.CGImage);
var scaledImage = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
return scaledImage;
}
If you want scale UIImage, then see this method. It works fine. You should cache method's result in file system to avoid image scaling on every GetCell.
If you source images are the same or almost the same size like UIImageViews in UITableViewCell Mohib Sheth solution with setting ContentMode property is best. It source image have much greater size than UIImageViews in UITableViewCell, scrolling speed will be lower.
Read all about ContentMode for UIView in iOS here
For your requirement you would need to set the ContentMode property to UIViewContentModeScaleAspectFit
I cant help you with a sample code, since you haven't provided any code on how you are creating & populating the TableView.
In my j2me App I have tried canvas which works great on Nokia phone but doesn't run on samsung. For that I have to switch to some FORM which in both cases works but only issue is of size, if I create smaller image to fit for both phone screens, one (samsung) shows that ok but other (nokia) leaves a lot more space and vice versa.
I need to have code that could stretch my image and just fix if to the screen size which I basically get by form.getHeight() and form.getWidth() property. I wonder if there is property of Image.createImage(width, height) then why doesn't it stretch it to the value I provide?
my code for that is below
try {
System.out.println("Height: " + displayForm.getHeight());
System.out.println("Width: " + displayForm.getWidth());
Image img1 = Image.createImage("/bur/splashScreen1.PNG");
img1.createImage(displayForm.getHeight(), displayForm.getWidth());
displayForm.append(new ImageItem(null, img1, Item.LAYOUT_CENTER, null));
} catch (Exception ex) {
}
Image
A single image will not fit all screens. But more will do.
The smaller logo image should be less than 96x54, as this is the smallest screen resolution. This image can be used up to the resolution of 128x128 without problems. With bigger resolutions it will look tiny, though.
The bigger logo image should be a bit bigger than 128x128 and can be used up to 240x320.
The code bellow gives as example of how to implement this.
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Graphics;
class Splash extends javax.microedition.lcdui.Canvas {
Image logo;
Splash () {
if (getWidth() <= 128) {
// sl stands for Small Logo and does not need to have a file extension
// this will use less space on the jar file
logo = Image.createImage("/sl");
} else {
// bl stands for Big Logo
logo = Image.createImage("/bl");
}
}
protected void paint (Graphics g) {
// With these anchors your logo image will be drawn on the center of the screen.
g.drawImage(logo, getWidth()/2, getHeight()/2, Graphics.HCENTER | Graphics.VCENTER);
}
}
As seen in http://smallandadaptive.blogspot.com.br/2008/10/showing-splash.html
wonder if there is property of Image.createImage(width, height) then why doesn't it stretch it to the value I provide?
Parameters in this method have nothing to do with stretching, see API javadocs:
public static Image createImage(int width, int height)
Creates a new, mutable image for off-screen drawing.
Every pixel within the newly created image is white.
The width and height of the image must both be greater than zero.
Parameters:
width - the width of the new image, in pixels
height - the height of the new image, in pixels
Image class (API javadocs) has two more createImage methods that use parameters called "width" and "height" - one with six, another with four arguments but none of these has anything to do with stretching.
In createImage with six arguments, width and height specify size of the region to be copied (without stretching) from source image.
In method with four arguments, width and height specify how to interpret source ARGB array, without these it would be impossible to find out if, say, array of 12 values represents 3x4 image or 4x3. Again, this has nothing to do with stretching.
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