Resizing of bitmaps with Graphics.drawTexturedPath - bad ratio

Hello

I used to resize bitmap images (to have the similar physical size on different phones) in my project with the following code - found in this thread:

Without creating an encoded image bitmap image resizing

    public static Bitmap resizeBitmap(Bitmap image, int width, int height)
    {
        int imageWidth = image.getWidth();
        int imageHeight = image.getHeight();

        // Need an array (for RGB, with the size of original image)
        int rgb[] = new int[imageWidth * imageHeight];

        // Get the RGB array of image into "rgb"
        image.getARGB(rgb, 0, imageWidth, 0, 0, imageWidth, imageHeight);

        // Call to our function and obtain rgb2
        int rgb2[] = rescaleArray(rgb, imageWidth, imageHeight, width, height);

        // Create an image with that RGB array
        Bitmap temp2 = new Bitmap(width, height);

        temp2.setARGB(rgb2, 0, width, 0, 0, width, height);

        return temp2;
    }

    private static int[] rescaleArray(int[] ini, int x, int y, int x2, int y2)
    {
        int out[] = new int[x2*y2];
        for (int yy = 0; yy < y2; yy++)
        {
            int dy = yy * y / y2;
            for (int xx = 0; xx < x2; xx++)
            {
                int dx = xx * x / x2;
                out[(x2 * yy) + xx] = ini[(x * dy) + dx];
            }
        }
        return out;
    }

My problem with the code was that it was quite slow - larger images would take almost a second (!) on the older phones (8830) scale.  It did not prevent UI - I have the code running in a separate Thread - but it has considerably delayed showing the image on the screen.

Recently, I started to experiment with Graphics.drawTexturedPath and I really like this method.  However, I found a weird problem while reducing images.  For example, I need to put a picture of 48 x 48 up to 42 x 42.  The most important parameters for the scale are dux and dvy (of the four walk coordinates vector only these two are zero).  So now my code object looks like this:

XYRect area = getExtent();
// ourBgImage is the unscaled Bitmap - our background image
int imageWidth = ourBgImage.getWidth();
int imageHeight = ourBgImage.getHeight();
int[] xPts = {0, 0, area.width - 1, area.width - 1};
int[] yPts = {0, area.height - 1, area.height - 1, 0};
int dux = (int) ((((long) imageWidth) << 16) / area.width);
int dvy = (int) ((((long) imageHeight) << 16) / area.height);
// Keep aspect ratio and make image fit fully
dux = dvy = Math.max(dux, dvy);
g.drawTexturedPath(xPts, yPts, null, null, 0, 0, dux, 0, 0, dvy, ourBgImage);

which is a little shorter and much more fast-work (especially on older phones as 8830).

However, the image is truncated on the right and down - looks like two pixels are missing on one of these two parties.  This was not the case with the old algorithm. I am specifying all the wrong settings?

Final nail in the coffin of drawTexturedPath:

I decided to check how drawTexturedPath resizes checkerboard (mainly the scale down).  And the results are pretty ugly - it seems to use the algorithm "nearest neighbour" without any means.  The project with which I tested it is attached.  Once you have it running, use Alt + move to shrink and Alt + down to stretch.  Observe the results.

The decision is, of course, to remove this method and resize Bitmaps the old way

Tags: BlackBerry Developers

Similar Questions

  • Rotation of bitmap with drawTexturedPath

    I'm trying to find the fastest way to draw a bitmap to an arbitrary angle.  Here's what I have so far:

    private void drawRotatedBitmap(Graphics graphics, Bitmap bm, int angle, int x, int y) {
      int w = bm.getWidth(); int h = bm.getHeight();
      double a = Math.toRadians(angle);
      int x1 = (int) (x - h * Math.sin(a));
      int y1 = (int) (y + h * Math.cos(a));
      int x2 = (int) (x1 + w * Math.cos(a));
      int y2 = (int) (y1 + w * Math.sin(a));
      int x3 = (int) (x + w * Math.cos(a));
      int y3 = (int) (y + w * Math.sin(a));
      int xPts[] = {x, x1, x2, x3};
      int yPts[] = {y, y1, y2, y3};
      int fAngle = Fixed32.toFP(angle);
      int dvx = Fixed32.cosd(fAngle);
      int dux = -Fixed32.sind(fAngle);
      int dvy = Fixed32.sind(fAngle);
      int duy = Fixed32.cosd(fAngle);
      graphics.drawTexturedPath(xPts, yPts, null, null, x, y, dvx, dux, dvy, duy, bm);
    }
    

    The problem is that drawTexturedPath does exactly what it was designed for: he draws a path.  Could someone please suggest a way to hide the part of path, so the rotated image would not have a line around it?  Are there other ways to draw a rotated quickly image and with a quality comparable to that drawTexturedPath produced?

    I found the source of the problem.  Apparently the path comes only when you enable the anti-aliasing polygon by calling

    graphics.setDrawingStyle (Graphics.DRAWSTYLE_AAPOLYGONS, true);

    Deleting this line solves the problem.

  • Satellite A300-146 - cannot play games with graphics

    I have Toshiba Satellite A300-146, model No.: PSAJ0E, 1 GB of RAM, Intel Dual core 1.87 processor, chipset Mobile Intel (r) 965 family.

    I can play some games like hitman silent of assasin on fullscreen and with graphics.

    But the problem is that a game could not open correctly IE after you open the game, he becomes 16-bit or not graphicsless. I tried these games = need for speed - pursuit and need for speed - undercover, the same problem occurs. I tried in windows XP and Vista.

    We all know Roadrash. I played this game in computer III pentium no value correctly... but I can not play in my laptop...

    Please help me to recover from this problem with the graphics.

    Sul

    Hello!

    Check the system requirements for the game. Satellite A300 is not a high-end gaming laptop and maybe some new games couldn't work on this laptop.

    Maybe you need to reinstall your laptop with the Toshiba recovery disc. I put t have another idea so try and post your result.

    Good bye

  • HP pavilion f002sm 17: hp pavilion 17 f002sm problem with graphics card

    OK Hi again, you help me with my problem with graphics card yesterday I install the driver for my laptop and I can play games, but I I look for tools of diagnosis and is in writing which is r5 graphics card which is built on my laptop and I have A7 graphical please help amd a8 6410 win 7 32-bit

    Hi @zumzo ,

    I understand that you have installed the driver and it works fine.  When you checked the diagnostics you became confused because it says graphic R5 but you R7.

    According to the specifications of your laptop you have AMD Quad - Core A8 - 6410 APU with graphics Radeon R5 (2 GHz, 2 MB cache).

    Here is a link to the 17-f002sm HP Pavilion Notebook product specifications to confirm this information. I hope that this eliminates any confusion.

  • When you try to connect to my email it says he was the block because someone tried to open a session with too many bad passwords.

    Blocked e-mail?

    I have not tried to connect to my email for a week, but when I tried to log on it (I only tried once), it tells me that my email is blocked because someone tried to open a session with too to bad passwords. What is someone trying to hack into my email?

    Hello handset,

    What e-mail account are referring? If it's Hotmail or Live email, then click on the links below and re - ask your question. Thank you.

    Windows Live Mail

    Windows Live Hotmail

  • ordered a pavilion with graphics card upgrade, upgrade used only 16-bit location

    ordered a pavilion with graphics card upgrade, upgrade used only 16-bit location. I want to connect a second monitor, can I use the parent connections card currently have coverage through them that say "do not remove"?

    Hello

    If you use an adapter, then you have the choice on the end to use the adapter based on the adapter that you use. Buy cable HDMI to DVI and save frustration adapter problems and possible.

  • Resize the Bitmap and get changed background = /...

    Hi I have a simple code for mounira a bitmap, but, when I get the new resized Bitmap of it have a black background? and I don't want to. Here's the code.

    public class ImageUtils {
    
        public static Bitmap resizeImage(Bitmap originalImage, int newWidth, int newHeight) {
            Bitmap newImage = new Bitmap(newWidth, newHeight);
            originalImage.scaleInto(newImage, Bitmap.FILTER_BILINEAR, Bitmap.SCALE_TO_FILL);
            return newImage;
        }
    }
    

    Try this:

    http://supportforums.BlackBerry.com/T5/Java-development/resizing-transparent-bitmaps/Ta-p/703239

  • How to resize the Bitmap

    I have a bitmap with lets say the size 200 x 100 and I want to create a bitmap with size 200 x 200 and the first bitmap to be drawn in the news and have offset of 50px from the top and bottom of the new bitmap?

    How can I do this and be compatible with OS > = 4.6. I see in the OS 5.0, we have a method scaleInto in the class Bitmap - http://www.blackberry.com/developers/docs/5.0.0api/

    Yes, in this way, the obstacle is buffer of the Blackberry chart which is available only twice the size of the screen.

    Another option is to obtain Bitmap of RGB and that put the RGB right in the right place int this new Bitmap.

  • Need help with graphics

    Hi all

    I'm experimenting with graphics api.

    Although I used it until I'm still not very confident on this subject. So, I want to build a strong foundation in this area. I looked online but couldn't find something really useful and what explains the basics.

    For my first mission I want to draw a rectangle in the middle of the screen. Now, for this I used a verticalfieldmanager and I replaced its sublayout method.

    In the sublayout method, I use the getgraphics() method to create the instance of the graphics class. Now, type the following lines:

    g.drawRect (width/2, height/2, 70, 30);

    g.fillRect (width/2, height/2, 70, 30);

    Super.paint (g);

    setExtent (width, height);

    but all I get is a white screen... can't use a graphical object directly in a fieldmanager? do I have to draw the rectangle in a separate field (perhaps a labelfield), then add it to the fieldmanager?

    as you can see my bases regarding the user interface graphics and custom api are not very good and that's why I need all the help I can get here.

    Thank you!!

    For one you super.paint () to call after you did you paint that will erase everything you have done. There is no need to call super.paint () If you make your own custom paint job.

  • having problems with graphics acceleration in lightroom with card amd 2015 running drivers latest

    having problems with graphics acceleration in lightroom with card amd 2015 running latest drivers. It crashes every time that you do something to make anything with acceleration for example. develop module or turn it off

    Version of Lightroom: CC 2015.1 [1025654]

    License: Creative Cloud

    Operating system: Windows 7 Ultimate Edition

    Version: 6.1 [7601]

    Application architecture: x 64

    System architecture: x 64

    Number of logical processors: 6

    Processor speed: 2.8 GHz

    Built-in memory: 16383,3 MB

    Real memory for Lightroom: 16383,3 MB

    Real memory used by Lightroom: 841,5 MB (5.1%)

    Virtual memory used by Lightroom: 853,0 MB

    Memory cache size: 261,4 MB

    Maximum thread count used by Camera Raw: 6

    Camera Raw SIMD optimization: SSE2

    System DPI setting: 96 DPI

    Composition of the Bureau enabled: Yes

    Exhibition: 1) 1600 x 900, 2) 1600 x 900

    Entry types: Multitouch: no, built-in touch: No, built-in pen: no, touch external: No, external pen: no keyboard: No.

    Graphic processor News:

    AMD Radeon HD 6800 Series

    Check the supported OpenGL: past

    Vendor: ATI Technologies Inc.

    Version: 3.3.13397 context 15.200.1046.0 the base profile

    Renderer: AMD Radeon HD 6800 Series

    LanguageVersion: 4.40

    The application folder: C:\Program Files\Adobe\Adobe Lightroom

    Library path: K:\hdd\photos\Lightroom\Lightroom Catalog.lrcat

    Settings folder: C:\Users\nathan\AppData\Roaming\Adobe\Lightroom

    Plugins installed:

    (1) Behance

    (2) substantive canon Plugin

    (3) Facebook

    (4) Flickr

    (5) irista

    Config.LUA flags: None

    Map #1: Seller: 1002

    Feature: 6738

    Subsystem: e178174b

    Revision: 0

    Video memory: 1011

    AudioDeviceIOBlockSize: 1024

    AudioDeviceName: Speakers (Corsair Gaming H1500 helmet)

    AudioDeviceNumberOfChannels: 2

    AudioDeviceSampleRate: 44100

    Build: not initialized

    Direct2DEnabled: false

    GPUDevice: not available

    OGLEnabled: true

    You can disable the GPU manually by changing the preferences file to LR with a text editor such as notepad and change the line useAutoBahn = true to useAutoBahn = false.  You do not want to do with LR does not.

    On Windows, the LR file is located here:

    C:\Users\- yourusername -\AppData\Roaming\Adobe\Lightroom\Preferences\Lightroom 6 Preferences.agprefs

    You could make a backup copy of a file agprefs on your desktop, firstly, in the case where mess you something.

  • Publish reports migration with graphic functions.

    Hi guys,.
    I'm working on the relationship between 10g and 11g migration and I have a problem with the reports that contains a chart. They give the following error when I run them against the report of 11g Server (they work very well against the server 10g with on all issues)

    The report stopped with the error:
    REP-56048: engine rwEng-1 crushed., job Id: 24.

    I searched on Google for a solution to fix them, the closer, I found was install Oracle Graphics 6i engine in a House separate from the Oracle, but this has been said for 9i and 10g, you can find that in the oracle document below:

    http://www.Oracle.com/technetwork/middleware/reports/graph-FAQ-with-style-094084.html#Q101

    Do anyone knows if I can 6i engine install Oracle Graphics in a separate Oracle 11 g House too?, so that they work at least, if not to change those that exist?

    Thank you
    Sona.

    Hello Sona,
    Unfortunately installation chart 6i to one OH for 11g will not work. This option is possible as long as 10g as a temporary option during migration to the BI beans new chart features in gr 10, 2 and 11 g.

    Reference
    http://www.Oracle.com/technetwork/middleware/reports/graph-FAQ-with-style-094084.html

    Migration Oracle Graphics graphics 6i

    How can I migrate my Oracle graphics cards to the new chart format in reports of Oracle9i or Oracle10g reports?

    Oracle9i Release 1 go, graphical reports from Oracle was desupported. Reports of Oracle9i and Oracle10g use BI beans to generate graphs. Because of the underlying technology, there is no way to direct migration of Oracle Graphics to the bean BI graphing functionality. Therefore, the user will need to rewrite all their new graphics with the graphic Wizard in Report Builder.

    Top of Page

    Can I still use my Oracle Reports Developer 6i existing reports with graphical charts Oracle Oracle reports?

    As stated in the declaration of the Oracle reports, Oracle Graphics is no longer ships with Oracle Reports. However, as part of the migration route, you can still run Oracle Oracle reports graphic graphics if you install Oracle 6i graphics engine in a separate Oracle home. You must only maintain graph Oracle 6i as a temporary measure while redesign you your new charts using the chart wizard. For more details on configuring Oracle to use Oracle Graphics 6i, see Migration of graphics in the Oracle9i Application of Oracle9iAS version 1 (1.0.2.2.x) Server Migration manual version 2 (9.0.2).

    Top of Page

    Can I change or add diagrams of 6i, Oracle Graphics to my reports with Oracle9i reports or reports from Oracle 10 g?

    N ° you must have a separate installation of Oracle 6i graph generator to change your existing graphic Oracle 6i graphics since Oracle Graphics is not delivered with Oracle Reports. We strongly recommend that you migrate your cards to the new standard in the Oracle reports.

    Thank you, RZ

  • Resize the layer with smart filter without affecting the Smart Filter layer appearance

    I made a wax seals on photoshop with lots of embossing, bevelment and a dynamic filter. It's done and I just need to make it smaller so it fits well on my certificate. When I resize (Ctr + T) it appears a messgae which reads:

    ______________________________________________

    Adobe Photoshop CS6 extended

    "The dynamic filters applied to the layers contained in this group will be disabled at the temprarily while conversion is in preview. They will be applied after commit the transformation. »

    Ok

    [] Do not show

    ______________________________________________

    I click OK and I resize the layer with free transform, and then press ENTER. The layer is resized, but my smart filter that cretaes affect a shower around the joint is completely distorted.

    How to resize my layer with smart filter without affecting the appearance of dynamic filter of the layer

    Right-click on the name of the layer to smart object in the layers panel to get the menu below. Choose "Convert to Smart Object" to encapsulate the er and its smart filter and Layer Styles within a new KIND that can be resized without appearance changes.

  • MovieClip sprite vs drawing with graphics

    Hello! I have a program that dynamically draws a polygon anywhere where the user clicks on the screen. (using lineto, moveto) However this polygon is always behind the other symbol of objects on the screen even if his last added in the childlist is. Is there a problem with the depth when you draw symbols vs drawing with lines? How can ensure me that my smart object will display in the face?

    Thank you

    Will be

    OK the problem is that you have the graphics in the main class through the polygon class to draw

    which works great but all the objects in the main class, if they are added before or after the polygon will appear above any line draw

    to work around this problem

    change the DrawPolygon() function do not take a target

    so

    public void DrawPolygon() (x: Number, y: Number, sides: uint, RADIUS: Number, angle: number = 0): void

    adjust the call to this function in hand in the appropriate form

    then in DrawPolygon() instead of references to target just replace them with graphics this will draw on the contrary to the purpose of polygon graphics

    Note You can put calls Graphics.Clear and graphics.lineStlye early DrawPolygon() so

    We can then remove the clear and graphics.lineStyle calls in your main class

    hope that makes sense

  • Creating visible buttons with graphics

    After you have created the button with graphics.

    Button layer... See the CIRCLE, MORE white poster, down the place of show, STRUCK by the black circle.

    Can you tell me it's OK because after I add layer to ActionScript still getting errors.

    I want to assure you that I have up to this point.

    a big thank you to you guys who helps others

    What you are doing inside the both graphic key have no impact on issues relating to the code.    The CLICKED image specifies only the clickable area for the button, it is not an image that is displayed at any time.  It is usually used if the clickable area must be different from that of the top lowest areas.

    If you get any errors, you must copy and paste errors in your ad and view the code associated with them.

  • Can't resize an object with the Selection (black arrow) tool?

    If called on an object, I am suddenly unable to resize it by dragging one of its corners with the selection tool.

    The object is not locked. The layer which is the object is not locked. I can only move the object.

    If I use the transformation tool, I can also resize, but not with the black arrow by dragging its corners.

    What could cause this problem?

    I read in this form of stimulus Illustrator command-Option-shift key. It solve my problem?

    View > Show Bounding Box - or - shift + command + B

Maybe you are looking for