Using Picture.FormatJPEG and Picture.QualityMax

Hi all. This is my first post to the forum. I am struggling to find good examples of Picture.FormatJPEG and Picture.QualityMax that fit in my code. I have an extensive Application that uses a number of JPEGS. I am losing resolution when I scale my pictures down, so I am hoping that proper use of QualityMax or QualityHigh would fix this. Note I am not resaving the pictures, so I am not concerned with the “lossy” nature of jpegs.

This is the area of code in question:
pic = New Picture(ButtonPic(i).Width * factor, ButtonPic(i).Height * factor, 32)
pic.graphics.DrawPicture ButtonPic(i), 0, 0, pic.width, pic.height, 0, 0, ButtonPic(i).width, ButtonPic(i).height
Button(i).Icon = pic

And I originally read my jpeg file off of disk here:
picFile = GetFolderItem(…)
ButtonPic(i) = Picture.Open(picFile)

So, talking about jpg is useless / meaningless.

I am struggling to find good examples of Picture.FormatJPEG
This happens only at image file open time (as you wrote later in your post.
Xonsider JPEG (and others like PNG, etc.) as a user file format. In memory, the things are different (Picture).

I am losing resolution when I scale my pictures down
I think this is (more or less) included in the process.

What you do not disclose is the code to create the lower sized Picture to hold your smaller image.

I notice that you do not specify a Resolution at pic Picture creation.

Do you know about:
http://documentation.xojo.com/api/graphics/picture.html#picture-horizontalresolution
http://documentation.xojo.com/api/graphics/picture.html#picture-verticalresolution

Look at Picture in the LR:
http://documentation.xojo.com/api/graphics/picture.html

If you are still having troubles, come back here and ask more questions. :slight_smile:

set pic.graphics.AntiAliasMode before you draw picture into a picture to Global.Graphics.AntiAliasModes.HighQuality

QualityMaximum or QualityHigh is used if you save a picture to file as jpeg.
usually 80% is ok for jpeg. if you not like this lossy format use png.

This line of code creates the smaller picture:
pic.graphics.DrawPicture ButtonPic(i), 0, 0, pic.width, pic.height, 0, 0, ButtonPic(i).width, ButtonPic(i).height

Brilliant. That did it! Thanks so much.
James

1 Like