I want to render an image to a canvas but without the smoothing taking place.
According to the JavaFX API's the image class has a 'isSmooth' option.
Can this be implemented?
isSmooth
public final boolean isSmooth()
Indicates whether to use a better quality filtering algorithm or a faster one when scaling this image to fit within the bounding box provided by width and height.
If not initialized or set to true a better quality filtering will be used, otherwise a faster but lesser quality filtering will be used.
Thanks Steve. Yes, I am using the Image type, and the "setSmooth" option is not available.
What I am doing is rendering an image to a canvas, but it always appears smooth. I want a pixel-sharp unfiltered look.
The problem is, when I later save the canvas the image is blurred.
OK, the good news is that the B4j image object is not wrapped, so we can create out own using JavaObject, and use it just the same.
This will do it:
B4X:
Dim I As JavaObject
I.InitializeNewInstance("javafx.scene.image.Image",Array As Object(File.GetUri(File.DirAssets,"color.jpg"),Width,Height,True,False))
Cnv.DrawImage(I,10Dip,10Dip,200Dip,200Dip)
Width and Height need to be Variables of type Double to be recognized.
If you check the XML definition of Image class (ImageWrapper) you can see that there is an ObjectWrapper element. This means that ImageWrapper is a thin wrapper over javafx.scene.image.Image. The compiler will automatically convert between the two.
Thanks for your efforts Steve. Donation on its way!
There seems to be a fundamental problem though. Images now look a sharper when rendered at their normal size but if I zoom in (basically rendering the image to the canvas at a larger scaled size) the image still renders blurred.
Here is an example. My B4J app on the left. Windows photo viewer on the right.
My image load routine is now:
B4X:
' Loads images with PreserveRatio=FALSE and Smooth=FALSE
Sub Image_Load(dir As String,name As String) As JavaObject
Dim tmpImg As Image = fx.LoadImage(dir,name)
Dim i As JavaObject
i.InitializeNewInstance("javafx.scene.image.Image",Array As Object(File.GetUri(dir,name),tmpImg.Width,tmpImg.Height,False,False))
Return i
End Sub
The draw routine is a simple myCanvas.DrawImage(img,x,y,img.Width*zoom,img.Height*zoom)
It's looking like Canvas is not a viable option for pure image manipulation. I found a related issue here too.