{"id":15200,"date":"2021-09-13T12:01:23","date_gmt":"2021-09-13T12:01:23","guid":{"rendered":"https:\/\/flobiz.in\/blog\/?p=15200"},"modified":"2021-09-21T05:26:20","modified_gmt":"2021-09-21T05:26:20","slug":"create-resizable-bitmaps-9-patch-files","status":"publish","type":"post","link":"http:\/\/35.200.248.73\/blog\/create-resizable-bitmaps-9-patch-files\/","title":{"rendered":"How to create resizable bitmaps (9-Patch files) in Android Studio"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/1280\/1*yAF2ldNXrmH7BQXkJhDe5w.jpeg\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"1600\"><strong>What is 9-patch image<\/strong><\/h2>\n\n\n\n<p id=\"43d0\">A&nbsp;<code><a href=\"https:\/\/developer.android.com\/reference\/android\/graphics\/drawable\/NinePatchDrawable\">NinePatchDrawable<\/a><\/code>&nbsp;graphic is a stretchable bitmap image that you can use as the background of a view. A NinePatch graphic is a standard PNG image that includes an extra 1-pixel border. It must be saved with the&nbsp;<code>9.png<\/code>&nbsp;extension in the&nbsp;<code>res\/drawable\/<\/code>&nbsp;directory of your project.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/1400\/1*WHyMA30aNQD5Q1PxCVlIkw.png\" alt=\"\" width=\"439\" height=\"357\"\/><figcaption>Example of a NinePatch graphic that defines a button<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"63a8\"><strong>9-Patch Theory<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/376\/1*zuenDjgdkTEmtLClvRe4fg.png\" alt=\"\"\/><\/figure>\n\n\n\n<p id=\"dc3f\"><strong>9-Patch<\/strong>&nbsp;gets its name from the fact that the overlay created breaks the image up into nine defined regions. Each region has specific stretch properties:<\/p>\n\n\n\n<p id=\"b262\"><strong>Corner Regions (1, 3, 7, 9)<\/strong>&nbsp;These regions are fixed and nothing inside them will stretch.<\/p>\n\n\n\n<p id=\"e766\"><strong>Horizontal Sides (4, 6)<\/strong>&nbsp;The pixels in these regions will stretch vertically when necessary.<\/p>\n\n\n\n<p id=\"7e39\"><strong>Vertical Sides (2, 8)<\/strong>&nbsp;The pixels in these regions will stretch horizontally when necessary.<\/p>\n\n\n\n<p id=\"22db\"><strong>Center (5)<\/strong>&nbsp;The pixels in this region will stretch in both horizontal and vertical directions equally.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"8776\">Why 9-patch image<\/h2>\n\n\n\n<p id=\"9fa6\">A 9 patch image is a regular png (.PNG) image which is needful for android app developers where they require to wrap any content within a background image without pixelating the background image. Usually, background images have a fixed height and width, but sometimes we may require background images that do not pixelate though stretched, this now becomes a challenge with regular PNG images.<\/p>\n\n\n\n<p id=\"e70f\">In the below image you can clearly observe that the background image height and width varies. Then how do you handle such a situation? Do you need to create thousands of images with different heights and widths? The answer is \u201cNO\u201d. This situation gave way to a new kind of image which is now called a (9 PATCH) image. It is an extension of a simple png image that can be modified using a tool and append it with a different extension.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/875\/1*qvIaNVu7dYn853SilBV3BA.jpeg\" alt=\"\" width=\"438\" height=\"438\"\/><figcaption>WhatsApp Conversation Screen<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"9661\">How to create a 9 patch image in Android Studio<\/h2>\n\n\n\n<p id=\"c6cc\">Here\u2019s a quick guide to creating a NinePatch graphic using the Draw 9-patch tool in Android Studio. You\u2019ll need the PNG image with which you\u2019d like to create a NinePatch image.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/1400\/1*ZIM836lN41YN4i-yu2hnTA.png\" alt=\"\"\/><figcaption>9-Patch Image Creator<\/figcaption><\/figure>\n\n\n\n<ol class=\"wp-block-list\"><li>In Android Studio, right-click the PNG image you\u2019d like to create a NinePatch image from, then click&nbsp;<strong>Create 9-patch file<\/strong>.<\/li><li>Type a file name for your NinePatch image, and click&nbsp;<strong>OK<\/strong>. Your image will be created with the&nbsp;<code>.9.png<\/code>&nbsp;file extension.<\/li><li>Double-click your new NinePatch file to open it in Android Studio. Your workspace will now open. The left pane is your drawing area, in which you can edit the lines for the stretchable patches and content area. The right pane is the preview area, where you can preview your graphic when stretched.<\/li><li>Click within the 1-pixel perimeter to draw the lines that define the stretchable patches and (optional) content area. Right-click (or hold Shift and click, on Mac) to erase previously drawn lines.<\/li><li>When done, click&nbsp;<strong>File<\/strong>&nbsp;&gt;&nbsp;<strong>Save<\/strong>&nbsp;to save your changes.<\/li><\/ol>\n\n\n\n<p id=\"1fce\">You can open an existing NinePatch file in Android Studio by double-clicking the file.<\/p>\n\n\n\n<p id=\"f93e\">To make sure that your NinePatch graphics scale down properly, verify that any stretchable regions are at least 2&#215;2 pixels in size. Otherwise, they may disappear when scaled down. Also, provide one pixel of extra safe space in the graphics before and after stretchable regions to avoid interpolation during scaling that may cause the colour at the boundaries to change.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/875\/1*9Wb39uJ2qdNcTNxg0bC-VQ.png\" alt=\"\"\/><\/figure>\n\n\n\n<p id=\"da67\">Optional controls include:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Zoom<\/strong>: Adjust the zoom level of the graphic in the drawing area.<\/li><li><strong>Patch scale<\/strong>: Adjust the scale of the images in the preview area.<\/li><li><strong>Show lock<\/strong>: Visualize the non-drawable area of the graphic on mouse-over.<\/li><li><strong>Show patches<\/strong>: Preview the stretchable patches in the drawing area (pink is a stretchable patch), as shown in figure 2, above.<\/li><li><strong>Show content<\/strong>: Highlight the content area in the preview images (purple is the area in which content is allowed), as shown in figure 2.<\/li><li><strong>Show bad patches<\/strong>: Adds a red border around patch areas that may produce artifacts in the graphic when stretched, as shown in figure 2. Visual coherence of your stretched image will be maintained if you eliminate all bad patches.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"33d4\">9-Patch vs Vector<\/h2>\n\n\n\n<p id=\"fc7a\">In vector graphics, all sides are scale or stretch when we set it to any background whereas in 9-patch we can define which sides can scale or stretch so at runtime only those side scale which we set it to scale in the 9-patch tool.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"c85d\">Advantage<\/h2>\n\n\n\n<p id=\"5315\">The advantage of using 9-patch images is that when using it as a background, for instance, the image won\u2019t stretch and lose proportions in different screen sizes. The centre &#8216;patch\u2019 will remain as is and the \u2018borders\u2019 patches will be stretched to fit the screen\/view size.<a href=\"https:\/\/drjansari.medium.com\/?source=post_page-----48c774db4526--------------------------------\"><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here\u2019s a quick guide to creating a NinePatch graphic in Android Studio. You\u2019ll need the PNG image with which you\u2019d like to create a 9-Patch image.<\/p>\n","protected":false},"author":8,"featured_media":15286,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[149],"tags":[],"class_list":["post-15200","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-engineering-product"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.1.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Create resizable bitmaps (9-Patch files) - Flobiz<\/title>\n<meta name=\"description\" content=\"Guide to creating resizable bitmaps - 9-Patch files. Read what is 9-patch image, 9-Patch Theory, how to create 9 patch image in Android Studio, 9-Patch vs Vector\" \/>\n<link rel=\"canonical\" href=\"https:\/\/73.248.200.35.bc.googleusercontent.com\/blog\/create-resizable-bitmaps-9-patch-files\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create resizable bitmaps (9-Patch files) - Flobiz\" \/>\n<meta property=\"og:description\" content=\"Guide to creating resizable bitmaps - 9-Patch files. Read what is 9-patch image, 9-Patch Theory, how to create 9 patch image in Android Studio, 9-Patch vs Vector\" \/>\n<meta property=\"og:url\" content=\"https:\/\/73.248.200.35.bc.googleusercontent.com\/blog\/create-resizable-bitmaps-9-patch-files\/\" \/>\n<meta property=\"og:site_name\" content=\"FloBiz\" \/>\n<meta property=\"article:published_time\" content=\"2021-09-13T12:01:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-09-21T05:26:20+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/35.200.248.73\/blog\/wp-content\/uploads\/2021\/09\/Untitled-design-6.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data1\" content=\"5 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"http:\/\/35.200.248.73:80\/blog\/#website\",\"url\":\"http:\/\/35.200.248.73:80\/blog\/\",\"name\":\"FloBiz\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"http:\/\/35.200.248.73:80\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/73.248.200.35.bc.googleusercontent.com\/blog\/create-resizable-bitmaps-9-patch-files\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/35.200.248.73\/blog\/wp-content\/uploads\/2021\/09\/Untitled-design-6.png\",\"contentUrl\":\"http:\/\/35.200.248.73\/blog\/wp-content\/uploads\/2021\/09\/Untitled-design-6.png\",\"width\":1200,\"height\":675,\"caption\":\"Bitmaps\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/73.248.200.35.bc.googleusercontent.com\/blog\/create-resizable-bitmaps-9-patch-files\/#webpage\",\"url\":\"https:\/\/73.248.200.35.bc.googleusercontent.com\/blog\/create-resizable-bitmaps-9-patch-files\/\",\"name\":\"Create resizable bitmaps (9-Patch files) - Flobiz\",\"isPartOf\":{\"@id\":\"http:\/\/35.200.248.73:80\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/73.248.200.35.bc.googleusercontent.com\/blog\/create-resizable-bitmaps-9-patch-files\/#primaryimage\"},\"datePublished\":\"2021-09-13T12:01:23+00:00\",\"dateModified\":\"2021-09-21T05:26:20+00:00\",\"author\":{\"@id\":\"http:\/\/35.200.248.73:80\/blog\/#\/schema\/person\/acf0255a56a8dacf88e9a27998430248\"},\"description\":\"Guide to creating resizable bitmaps - 9-Patch files. Read what is 9-patch image, 9-Patch Theory, how to create 9 patch image in Android Studio, 9-Patch vs Vector\",\"breadcrumb\":{\"@id\":\"https:\/\/73.248.200.35.bc.googleusercontent.com\/blog\/create-resizable-bitmaps-9-patch-files\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/73.248.200.35.bc.googleusercontent.com\/blog\/create-resizable-bitmaps-9-patch-files\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/73.248.200.35.bc.googleusercontent.com\/blog\/create-resizable-bitmaps-9-patch-files\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"http:\/\/35.200.248.73:80\/blog\/\",\"url\":\"http:\/\/35.200.248.73:80\/blog\/\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/73.248.200.35.bc.googleusercontent.com\/blog\/create-resizable-bitmaps-9-patch-files\/\",\"url\":\"https:\/\/73.248.200.35.bc.googleusercontent.com\/blog\/create-resizable-bitmaps-9-patch-files\/\",\"name\":\"How to create resizable bitmaps (9-Patch files) in Android Studio\"}}]},{\"@type\":\"Person\",\"@id\":\"http:\/\/35.200.248.73:80\/blog\/#\/schema\/person\/acf0255a56a8dacf88e9a27998430248\",\"name\":\"Dipen Jansari\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"http:\/\/35.200.248.73:80\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d92393e3a8f1d1045848cb246f4a770d7e44bdcc74f38ac6e0e3bb67d4d10d13?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d92393e3a8f1d1045848cb246f4a770d7e44bdcc74f38ac6e0e3bb67d4d10d13?s=96&d=mm&r=g\",\"caption\":\"Dipen Jansari\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"http:\/\/35.200.248.73\/blog\/wp-json\/wp\/v2\/posts\/15200","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/35.200.248.73\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/35.200.248.73\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/35.200.248.73\/blog\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/35.200.248.73\/blog\/wp-json\/wp\/v2\/comments?post=15200"}],"version-history":[{"count":7,"href":"http:\/\/35.200.248.73\/blog\/wp-json\/wp\/v2\/posts\/15200\/revisions"}],"predecessor-version":[{"id":15419,"href":"http:\/\/35.200.248.73\/blog\/wp-json\/wp\/v2\/posts\/15200\/revisions\/15419"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/35.200.248.73\/blog\/wp-json\/wp\/v2\/media\/15286"}],"wp:attachment":[{"href":"http:\/\/35.200.248.73\/blog\/wp-json\/wp\/v2\/media?parent=15200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/35.200.248.73\/blog\/wp-json\/wp\/v2\/categories?post=15200"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/35.200.248.73\/blog\/wp-json\/wp\/v2\/tags?post=15200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}