Question:
Question:
When you set an image as the background of an item, if the image is smaller it is scaled with aliasing.
Is it possible (by script I assume) to remove that aliasing but without changing the size of the image (this is: the internal bitmap from item.getBoxBackground(“n”).getBitmap() need to have a small size, smaller than the item)
I know I can create an image with the size of the item and draw the previous image with an anti alias paint, then set that new image. The problem is that the image has now a different size, I want to keep the original size.
(Note: I know some workarounds, but I’m interested in that way in particular)
]]>
< ![CDATA[
In fact bitmap filtering is always on. I can add an API to temporarily disable it but I am not sure of what you need. Do you want to:
– remove filtering when upscaling a small image in the case it needs to be scaled to fit the item’s boundaries
– display the image without any scaling (1:1 pixel) and in that case it doesn’t need filtering at all
I think this is the second option. Yes I think it can be done. By coincidence I am preparing a new beta with an option to scale or not the item’s icon (already fully implemented). This way the icon can display any image size, this is easier to display graphics. Would you be interested in using the icon this way , or do you specifically need the background ?
]]>
< ![CDATA[
The first option, that’s what I want.
Think about pixel art: the ability to show a 16×16 image in a 500×500 item without aliasing. (And I need to keep the image unscaled because from script I’m editing its pixels)
It is for a test I’m doing and I don’t think I’ll do anything more than a simple test, if it is difficult to implement don’t spend too much on it. I asked because this is the second time I need this ‘feature’ and I decided to ask in case I missed something. (I can make a custom view)
]]>
< ![CDATA[
TrianguloY I think you got it wrong. An aliased upscaled image is a jagged image. The anti-aliasing filter is blurring the image. The blurring also occurs when you use bilinear filtering.
You want to show a 16×16 image in a 500×500 space with alias (jagged edges) and point sampled.
See https://en.m.wikipedia.org/wiki/Texture_filtering
]]>
< ![CDATA[
Bogdan Tautu you are totally right, I mixed the definitions.
Let me check…yes, I need the bitmap without anti-aliasing
(The pixel art is the best example)
]]>
< ![CDATA[
As far as I can see, images drawn upscaled will always be filtered on Android 3+ because the graphics subsystem uploads the image to an opengl texture, which is itself drawn with filtering by the GPU. Filtering cannot be disabled here by applications. I just tested on a 2.3 device and the difference is clearly visible. So the only way to avoid filtering on 3+ is to use an image with the same size as its display target, and draw the image using the canvas API, which will not suffer from this limitation since it is software rasterization only.
]]>
< ![CDATA[
And what about:
BitmapDrawable draw = new BitmapDrawable(R.drawable.image);
draw.setAntiAlias(false);
view.setImageDrawable(draw);
]]>
< ![CDATA[
Anti aliasing is for edges, filtering is for image content, so this won’t work. Also Lightning doesn’t use a BitmapDrawable but a custom Drawable so this doesn’t apply. The exact code to draw a bitmap is
canvas.drawBitmap(bitmap, null, bounds, paint);
Where bounds is the destination rectangle, and paint is either null, or a paint created this way when filtering is on:
paint = new Paint()
paint.setFilterBitmap(true);
Unfotunately using a null paint, or a paint with setFilterBitmap(false) always results in a filtered upscaled image (but not on 2.3…). I assume this is enforced somewhere behind
]]>
< ![CDATA[
Ok, understood.
Thanks for the explanation 🙂
]]>
< ![CDATA[
By the way, I know that the APIs to manipulate images have important limitations, and are not always easy to use. I am currently restructuring this part (I dove into this because I wanted some sort of scripted support for animated GIF) and I think it will be ready soon, if you need something (not related to filtering 🙁 ) please let me know.
]]>
< ![CDATA[
Hmm, what about a public script function to call the lightning image cropper?
I mean net.pierrox.lightning_launcher.activities.ImageCropper.
]]>
< ![CDATA[
I can do something like:
boolean LL.cropImage(input, output)
where arguments would be path to image files
]]>
< ![CDATA[
And
Image LL.cropImage(Image input)
where they are Lightning Images and returns null if cancelled?
If this is worst I’m ok with your solution. Is only because if you want to crop the background of an item you need to save the image as file, run that function, set the image, delete the files. Just to avoid more complications.
(If the image is a 9-patch I’m ok if the function throws an exception)
]]>
< ![CDATA[
Indeed this is boring, but persistence is needed because Android may stop and restart activities, hence keeping things in memory is difficult. The issue is that it often happens when using an image picker and/or the camera or other gallery apps.
]]>
< ![CDATA[
Pierre Hébert oh, right.
Hmm, and
void LL.cropImage(Image input, Script handler)
Where the handler script will have the output image as variable?
]]>
< ![CDATA[
Then the return value can be an Image, or null, as with pickImage.
But wait… I wonder how this pickImage method is working at the moment, it should fail from time to time because of activity restarts(?)
]]>
< ![CDATA[
Hum… regarding filtering there must be something else in the equation because now I am able to manually disable it, and I don’t know why it works now :-S
]]>
< ![CDATA[
Finally I was able to implement a crop image function that takes images as parameters, not file. Images are persisted / “unpersisted” by the function itself et voila. (sorry for the interleaved discussion!)
]]>
< ![CDATA[
Nice!
Talking about the image cropper. Currently it is only shown when selecting a desktop background. But what about show it when selecting any image in the image picker? (The default ‘cropping rectangle’ will need to be the image dimensions)
This makes selecting an image one click longer…But it allows to crop any image without other apps…
]]>
< ![CDATA[
I’m already working on it 😉
]]>